Skip to content

Commit

Permalink
feat: add chatlog to chatbot (#391)
Browse files Browse the repository at this point in the history
* feat: add chatlog to chatbot

* feat: add chatlog to chatbot2
  • Loading branch information
LIEN-YUHSIANG authored Dec 1, 2023
1 parent 5cbce30 commit 8ed131a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit 8ed131a

Please sign in to comment.