Skip to content

Commit

Permalink
fix: prompt input formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-ny committed Sep 25, 2024
1 parent 792c47b commit aaf6a38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions backend/src/lm/generate_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}
Expand All @@ -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"],
}
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion backend/src/lm/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": <Given General Paper essay question without rephrasing>,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit aaf6a38

Please sign in to comment.