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

feat: add chatlog to chatbot #391

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions src/lambda/post-chat/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@


@resp_handler
def post_chat(prompt, timetable):
def post_chat(prompt, timetable, chatlog):
recommender = CourseRecommender(s3_client, bucket, school_code_map)


prompt = recommender.generate_gpt_prompt(prompt, timetable)
prompt = recommender.generate_gpt_prompt(prompt, timetable, chatlog)

response = ai_client.chat.completions.create(
model= "gpt-4-1106-preview",
Expand All @@ -29,7 +29,8 @@ def handler(event, context):
req = json.loads(event['body'])
params = {
"timetable": req["data"]["timetable"],
"prompt": req['data']['prompt']
"prompt": req['data']['prompt'],
"chatlog": req['data']['chatlog'],
}

return post_chat(**params)
5 changes: 3 additions & 2 deletions src/lambda/post-chat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,14 @@ def filter_courses(self, desired_terms=['2q', '3q', '2s']):
return filtered_courses


def generate_gpt_prompt(self, user_query, timetable):
def generate_gpt_prompt(self, user_query, timetable, chatlog):
self.set_timetable(timetable)
self.fetch_syllabus()
self.filter_courses()
timetable_str = "My timetable:\n" + json.dumps(self.simplified_timetable)
filtered_courses_str = "Filtered courses:\n" + json.dumps(self.filter_courses(['2q', '3q', '2s']))
combined_str = timetable_str + "\n" + filtered_courses_str
chatlog_str = "Previous chats:\n" + json.dumps(chatlog)
combined_str = timetable_str + "\n" + filtered_courses_str + "\n" + chatlog_str

# Format the prompt for GPT
prompt = [
Expand Down
Loading