From aaf6a38d4763b4eb3db655de685fb57cd011e2d1 Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Thu, 26 Sep 2024 07:42:38 +0800 Subject: [PATCH] fix: prompt input formatting --- backend/src/lm/generate_response.py | 11 ++++++----- backend/src/lm/prompts.py | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/backend/src/lm/generate_response.py b/backend/src/lm/generate_response.py index 05f596dc..b7215e38 100644 --- a/backend/src/lm/generate_response.py +++ b/backend/src/lm/generate_response.py @@ -27,9 +27,9 @@ def format_analyses(relevant_analyses: dict, question: str): "point": point["point"], "examples": [ { - "event_title": get_event_by_id(point["event_id"]).title, + "event_title": get_event_by_id(analysis["event_id"]).title, "event_description": get_event_by_id( - point["event_id"] + analysis["event_id"] ).description, "analysis": analysis["content"], } @@ -43,9 +43,9 @@ def format_analyses(relevant_analyses: dict, question: str): "point": point["point"], "examples": [ { - "event": get_event_by_id(point["event_id"]).title, + "event": get_event_by_id(analysis["event_id"]).title, "event_description": get_event_by_id( - point["event_id"] + analysis["event_id"] ).description, "analysis": analysis["content"], } @@ -65,9 +65,10 @@ def get_event_by_id(event_id: int) -> Event: def generate_response(question: str) -> dict: relevant_analyses = get_relevant_analyses(question) + formatted_analyses = format_analyses(relevant_analyses, question) messages = [ SystemMessage(content=SYSPROMPT), - HumanMessage(content=json.dumps(relevant_analyses)), + HumanMessage(content=json.dumps(formatted_analyses)), ] result = lm_model.invoke(messages) diff --git a/backend/src/lm/prompts.py b/backend/src/lm/prompts.py index f6b302c0..6d54e723 100644 --- a/backend/src/lm/prompts.py +++ b/backend/src/lm/prompts.py @@ -122,6 +122,9 @@ Important Note: Do not provide any new points or examples. You should only elaborate on the examples given in the input or skip them if they are not relevant to the question or the points given. Important Note: The "event", "event_description", and "analysis" fields MUST BE RETURNED AS IS. You should not rephrase or change the content of these fields. Important Note: You must NOT rephrase the question or the points given. You must only provide elaborations for the examples given in the input. + + Final Check: Before generating an elaboration, verify whether the example *directly* reinforces or counters the argument made in the point. If the connection is weak, DO NOT elaborate. + Final Check: Ensure that "question", "event", "event_description", and "analysis" fields are returned as is. Do not rephrase or change the content of these fields. Your response should be in the following json format: { "question": , @@ -152,7 +155,7 @@ } ] } - Final Check: Before generating an elaboration, verify whether the example *directly* reinforces or counters the argument made in the point. If the connection is weak, DO NOT elaborate. + Given inputs: