Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt changes #75

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
06da51f
Creating file structure for syllabus generator
vedanth-aggarwal Jul 18, 2024
0c555be
Test init.py
vedanth-aggarwal Jul 18, 2024
8af9a33
Prompts
vedanth-aggarwal Jul 18, 2024
c34e64b
Repurpose quizzify
vedanth-aggarwal Jul 18, 2024
bcf9900
Update README.md
AngelicSage Jul 19, 2024
98523fb
Update README.md
AngelicSage Jul 19, 2024
991e40e
syllabus change
RayMoham Jul 19, 2024
92b5701
Merge branch 'main' of https://github.com/RayMoham/kai-ai-backend
RayMoham Jul 19, 2024
1f3015b
Update core.py
AngelicSage Jul 19, 2024
a83d982
Update core.py
AngelicSage Jul 19, 2024
efff97d
Update core.py
AngelicSage Jul 19, 2024
4a60adf
Update core.py
AngelicSage Jul 19, 2024
0923fd5
created test files, they are incomple
AngelicSage Jul 19, 2024
c2d5670
Changes new
vedanth-aggarwal Jul 20, 2024
e06169a
Merge branch 'main' of https://github.com/RayMoham/kai-ai-backend
vedanth-aggarwal Jul 20, 2024
b9f9dd4
core.py
vedanth-aggarwal Jul 20, 2024
d488472
TOOLS.PY framework
vedanth-aggarwal Jul 20, 2024
0e27247
Draft final code
vedanth-aggarwal Jul 20, 2024
5fa1ee9
added my idea to test_tools.py
AngelicSage Jul 20, 2024
5f94e6b
space chnages
RayMoham Jul 20, 2024
b312ae2
str error
RayMoham Jul 20, 2024
0f817d7
changed grade level expected data type to be strings
AngelicSage Jul 20, 2024
3c9618f
changed grade level data type to str
AngelicSage Jul 20, 2024
6761637
Prompts
vedanth-aggarwal Jul 21, 2024
5d594fd
Merge branch 'main' of https://github.com/RayMoham/kai-ai-backend
vedanth-aggarwal Jul 21, 2024
aa5bf85
modification of the prompts to return a structured response
AmineRaouane Jul 21, 2024
e996e12
Resolved merge conflicts
AmineRaouane Jul 22, 2024
e91b96d
Resolved merge conflicts
AmineRaouane Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ pip install -r requirements.txt
### Step 4: Create a new .env and store the API Key

1. Create a new file called `.env` in the root of the project.
2. Copy the contents of the `.env.example` file into the `.env` file.
2. Copy the contents of the `.env.sample` file into the `.env` file.
3. Replace the placeholder values with your API key and project ID.
4. Set the `ENV_TYPE` variable to `dev`.

### Step 4: Run the Application with Local Shell Script
### Step 5: Run the Application with Local Shell Script

1. Run the following command to start the application:

Expand Down
Empty file.
50 changes: 50 additions & 0 deletions app/features/syllabus_generator/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This is code from quizbuilder - repurpose for syllabus generator
from services.logger import setup_logger
from gemini_api_client import generate_response
from tools import course_objectives,course_description,course_outline,grading_policy,rules_policies,study_materials,final_output
logger = setup_logger()

def executor(grade_level: str, topic: str, context: str) -> str:
"""
Executes the tool's functionality.

Args:
grade_level (int): The grade level for the content.
topic (str): The topic of interest.
context (str): Additional context or information.

Returns:
str: The result or output of the tool's functionality.
"""
try:
description = course_description(grade_level,topic,custom_info=context)

objectives = course_objectives(grade_level,topic,description,custom_info=context)

outline = course_outline(grade_level,topic,description,objectives,custom_info=context)

grading = grading_policy(grade_level,topic,outline,custom_info=context)

class_rules = rules_policies(grade_level,topic,outline,custom_info=context)

materials = study_materials(grade_level,topic,outline,custom_info=context)

response = final_output(description,objectives,outline,grading,class_rules,materials)
# Example of tool's logic (this should be detailed and explicit before abstraction)
#logger.error(f"Executing with grade_level={grade_level}, topic={topic}, context={context}")

# Here you would define the core functionality
#Prompt
#prompt_template = f"Create content for grade {grade_level} on {topic}. Context: {context}"
# Call the Gemini API to generate a response
#response = generate_response(prompt_template)

#logger.error(f"Execution successful: {response}")


except Exception as e:
error_message = f"Error in executor: {e}"
logger.error(error_message)
raise ValueError(error_message)

return response
19 changes: 19 additions & 0 deletions app/features/syllabus_generator/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"inputs": [
{
"label": "Grade",
"name": "grade_level",
"type": "text"
},
{
"label": "Subject",
"name": "topic",
"type": "text"
},
{
"label": "Custom Info",
"name": "context",
"type": "text"
}
]
}
7 changes: 7 additions & 0 deletions app/features/syllabus_generator/prompt/course_description.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
You are an expert syllabus generator. Your have to create a concise and hollistic course descriptionfor:
Grade : {grade}
Subject : {subject}
Customized information : {custom_info}

*Respond only with The descripion that should be a brief summary convering key aspects of the course
Answer:
18 changes: 18 additions & 0 deletions app/features/syllabus_generator/prompt/course_objectives.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
You are an expert syllabus generator. Your have to create a concise and hollistic course objectives for:
Grade : {grade}
Subject : {subject}
Customized information : {custom_info}
------------
Course Description ( Use as reference ):
{course_description}

*The response should be structured as a list. Ensure that the response can be loaded using json.loads in Python.
Answer:

Example structure of the response:
[
"<Objective 1 here ...>",
"<Objective 2 here ...>",
"<Objective 3 here ...>",
...
]
29 changes: 29 additions & 0 deletions app/features/syllabus_generator/prompt/course_outline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
You are an expert syllabus generator. Your have to create a detailed course outline or:
Grade : {grade}
Subject : {subject}
Customized information : {custom_info}
-----------------
Course Description ( use as reference ):
{course_description}
------------------
Course Objectives ( use as reference ):
{course_objectives}
*The outline should be well structured and detail all the syllabus in a form of a list of dictionnaries . Ensure that the response can be loaded using json.loads in Python.
Answer:

Example structure of the response:
[
{{
"week": 1,
"topic": "<The topic for week 1 ...>"
}},
{{
"week": 2,
"topic": "<The topic for week 2 ...>"
}},
{{
"week": 3,
"topic": "<The topic for week 3 ...>"
}},
...
]
9 changes: 9 additions & 0 deletions app/features/syllabus_generator/prompt/grading_policy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
You are an expert syllabus generator. Your have to create a grading policy for:
Grade : {grade}
Subject : {subject}
Customized information : {custom_info}
------------------
Course Outline ( use as reference ):
{course_outline}
*The grading policy should be suitable and relevant , the response should be only the grading policy
Answer:
17 changes: 17 additions & 0 deletions app/features/syllabus_generator/prompt/rules_policies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
You are an expert syllabus generator. Your have to create class rules and instructions for:
Grade : {grade}
Subject : {subject}
Customized information : {custom_info}
------------------
Course Outline ( use as reference ):
{course_outline}
*The rules and policies should be numerically listed in order of importance in a form of a python list.Ensure that the response can be loaded using json.loads in Python.
Answer:

Example structure of the response:
[
"<Rule 1 here ...>",
"<Rule 2 here ...>",
"<Rule 3 here ...>",
...
]
28 changes: 28 additions & 0 deletions app/features/syllabus_generator/prompt/study_materials.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
You are an expert syllabus generator. Your have to create the study material listfor:
Grade : {grade}
Subject : {subject}
Customized information : {custom_info}
------------------
Course Outline ( use as reference ):
{course_outline}

*Explain which study material is used for which purpose
The response should be structured as a list of dictionaries with the study material and it's purpose. Ensure that the response can be loaded using json.loads in Python.
Answer:

Example structure of the response:
[
{{
"material": "<Material 1 here>",
"purpose" : "<The purpose for material 1 ...>"
}},
{{
"material": "<Material 2 here>",
"purpose" : "<The purpose for material 2 ...>"
}},
{{
"material": "<Material 3 here>",
"purpose" : "<The purpose for material 3 ...>"
}},
...
]
Empty file.
5 changes: 5 additions & 0 deletions app/features/syllabus_generator/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

from core import executor

def test_executor():
assert executor
175 changes: 175 additions & 0 deletions app/features/syllabus_generator/tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import unittest
import os
from unittest.mock import patch, MagicMock
from tools import (
read_text_file,
build_prompt,
course_description,
course_objectives,
course_outline,
grading_policy,
rules_policies,
study_materials,
final_output
)
class TestFunctions(unittest.TestCase):

def setUp(self):
# Setup a test file
self.test_file_name = 'test_file.txt'
self.test_content = 'Hello, world!'
script_dir = os.path.dirname(os.path.abspath(__file__))
self.test_file_path = os.path.join(script_dir, self.test_file_name)
with open(self.test_file_path, 'w') as f:
f.write(self.test_content)


def tearDown(self):
# Clean up the test file after each test

os.remove(self.test_file_path)

def test_read_text_file(self):
result = read_text_file(self.test_file_name)
self.assertEqual(result, self.test_content)

@patch('your_module.read_text_file')
@patch('your_module.PromptTemplate')
def test_build_prompt(self, MockPromptTemplate, mock_read_text_file):
mock_read_text_file.return_value = self.test_content
mock_prompt_template_instance = MockPromptTemplate.from_template.return_value
mock_prompt_template_instance.return_value = self.test_content

result = build_prompt(self.test_file_name)
MockPromptTemplate.from_template.assert_called_once_with(self.test_content)
self.assertEqual(result, mock_prompt_template_instance)

@patch('your_module.build_prompt')
@patch('your_module.GoogleGenerativeAI')
def test_course_description(self, MockGoogleGenerativeAI, mock_build_prompt):
mock_build_prompt.return_value = MagicMock()
mock_model = MockGoogleGenerativeAI.return_value
mock_chain = MagicMock()
mock_model.__or__.return_value = mock_chain
mock_chain.invoke.return_value = "Generated course description"

result = course_description(10, "Math")
mock_chain.invoke.assert_called_once_with({"grade": 10, "subject": "Math", "custom_info": 'None'})
self.assertEqual(result, "Generated course description")

@patch('your_module.build_prompt')
@patch('your_module.GoogleGenerativeAI')
def test_course_objectives(self, MockGoogleGenerativeAI, mock_build_prompt):
mock_build_prompt.return_value = MagicMock()
mock_model = MockGoogleGenerativeAI.return_value
mock_chain = MagicMock()
mock_model.__or__.return_value = mock_chain
mock_chain.invoke.return_value = "Generated course objectives"

result = course_objectives(10, "Math", "Course description")
mock_chain.invoke.assert_called_once_with({
"grade": 10,
"subject": "Math",
"custom_info": 'None',
'course_description': 'Course description'
})
self.assertEqual(result, "Generated course objectives")

@patch('your_module.build_prompt')
@patch('your_module.GoogleGenerativeAI')
def test_course_outline(self, MockGoogleGenerativeAI, mock_build_prompt):
mock_build_prompt.return_value = MagicMock()
mock_model = MockGoogleGenerativeAI.return_value
mock_chain = MagicMock()
mock_model.__or__.return_value = mock_chain
mock_chain.invoke.return_value = "Generated course outline"

result = course_outline(10, "Math", "Course description", "Course objectives")
mock_chain.invoke.assert_called_once_with({
"grade": 10,
"subject": "Math",
"custom_info": 'None',
'course_description': 'Course description',
'course_objectives': 'Course objectives'
})
self.assertEqual(result, "Generated course outline")

@patch('your_module.build_prompt')
@patch('your_module.GoogleGenerativeAI')
def test_grading_policy(self, MockGoogleGenerativeAI, mock_build_prompt):
mock_build_prompt.return_value = MagicMock()
mock_model = MockGoogleGenerativeAI.return_value
mock_chain = MagicMock()
mock_model.__or__.return_value = mock_chain
mock_chain.invoke.return_value = "Generated grading policy"

result = grading_policy(10, "Math", "Course outline")
mock_chain.invoke.assert_called_once_with({
"grade": 10,
"subject": "Math",
"custom_info": 'None',
'course_outline': 'Course outline'
})
self.assertEqual(result, "Generated grading policy")

@patch('your_module.build_prompt')
@patch('your_module.GoogleGenerativeAI')
def test_rules_policies(self, MockGoogleGenerativeAI, mock_build_prompt):
mock_build_prompt.return_value = MagicMock()
mock_model = MockGoogleGenerativeAI.return_value
mock_chain = MagicMock()
mock_model.__or__.return_value = mock_chain
mock_chain.invoke.return_value = "Generated rules and policies"

result = rules_policies(10, "Math", "Course outline")
mock_chain.invoke.assert_called_once_with({
"grade": 10,
"subject": "Math",
"custom_info": 'None',
'course_outline': 'Course outline'
})
self.assertEqual(result, "Generated rules and policies")

@patch('your_module.build_prompt')
@patch('your_module.GoogleGenerativeAI')
def test_study_materials(self, MockGoogleGenerativeAI, mock_build_prompt):
mock_build_prompt.return_value = MagicMock()
mock_model = MockGoogleGenerativeAI.return_value
mock_chain = MagicMock()
mock_model.__or__.return_value = mock_chain
mock_chain.invoke.return_value = "Generated study materials"

result = study_materials(10, "Math", "Course outline")
mock_chain.invoke.assert_called_once_with({
"grade": 10,
"subject": "Math",
"custom_info": 'None',
'course_outline': 'Course outline'
})
self.assertEqual(result, "Generated study materials")

def test_final_output(self):

course_desc = "Course description"
course_obj = "Course objectives"
course_out = "Course outline"
grading_pol = "Grading policy"
rules_pol = "Rules and policies"
study_mat = "Study materials"

result = final_output(course_desc, course_obj, course_out, grading_pol, rules_pol, study_mat)

expected_output = (

f"#Course Description\n{course_desc}\n\n"
f"#Course Objectives\n{course_obj}\n\n"
f"#Course Outline\n{course_out}\n\n"
f"#Grading Policy\n{grading_pol}\n\n"
f"#Class Rules\n{rules_pol}\n\n"
f"#Study Materials\n{study_mat}\n\n"
)

self.assertEqual(result, expected_output)

if __name__ == '__main__':
unittest.main()
Loading