From df63bd76967ab1501e4aa31a35c7453554c74fba Mon Sep 17 00:00:00 2001 From: Bagatur Date: Tue, 2 Apr 2024 14:53:11 -0700 Subject: [PATCH] fmt --- backend/app/agent.py | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/backend/app/agent.py b/backend/app/agent.py index 6c6b4758..3053329d 100644 --- a/backend/app/agent.py +++ b/backend/app/agent.py @@ -74,26 +74,20 @@ class AgentType(str, Enum): LANGSMITH_CLIENT = LangSmithClient() -def _format_example(example: Example) -> str: - return f""" +def _format_chat_example(example: Example) -> str: + feedback = "" + for i in example.inputs["input"][1:]: + if i["type"] == "human": + feedback += "\n" + i["content"] + "\n\n" + return f""" {example.inputs['input'][0]['content']} - - + +{feedback} {example.outputs['output']['content']} """ -def _get_learnings(examples: List[Example]) -> List[str]: - learnings = [] - for e in examples: - for i in e.inputs["input"][1:]: - print(i) - if i["type"] == "human": - learnings.append(i["content"]) - return learnings - - -def _format_example_agent(example: Example) -> str: +def _format_agent_example(example: Example) -> str: new_messages = [] for o in example.outputs["output"][1:][::-1]: if o["type"] == "human": @@ -112,24 +106,19 @@ def few_shot_examples(assistant_id: str, *, agent: bool = False) -> str: return "" if agent: examples = random.sample(examples, min(len(examples), 10)) - e_str = "\n".join([_format_example_agent(e) for e in examples]) + example_str = "\n".join([_format_agent_example(e) for e in examples]) else: examples = random.sample(examples, min(len(examples), 10)) - e_str = "\n".join([_format_example(e) for e in examples]) - learnings = _get_learnings(examples) - e_str += ( - "\n\nHere are some of the comments that lead to these examples. Keep " - "these comments in mind as you generate a new response!" - + "\n".join(learnings) - ) + example_str = "\n".join([_format_chat_example(e) for e in examples]) return f""" Here are some previous interactions with a user trying to accomplish a similar task. \ -You should assumed that the final result in all scenarios is the desired one, and any \ -previous steps were wrong in some way, and the human then tried to improve upon them \ -in specific ways. Learn from these previous interactions and do not repeat previous \ +You should assume that the final output is the desired one, and any \ +intermediate steps were wrong in some way, and the human then tried to improve upon \ +them in specific ways. Learn from these previous interactions and do not repeat past \ mistakes! -{e_str} + +{example_str} """