Skip to content

Commit

Permalink
Update feedback_openai.py
Browse files Browse the repository at this point in the history
  • Loading branch information
curtis-sun committed Mar 22, 2024
1 parent 239caa0 commit 716380f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions multiagents/llms/feedback_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def __init__(self, max_retry: int = 100, **kwargs):
self.kb = DocKnowledgeBase()

async def feedback(self, messages, instruction, output, feedback):
messages = copy.deepcopy(messages)
instruction_feedback = f'{instruction}\n\n{feedback}'

messages.append({"role": "assistant", "content": output})
Expand Down Expand Up @@ -196,6 +197,7 @@ async def feedback(self, messages, instruction, output, feedback):
return reply

def extract_rules_from_feedback(self, messages, output, preferred_output):
messages = copy.deepcopy(messages)
messages.append({"role": "assistant", "content": output})
messages.append({"role": "user", "content": EXTRACT_RULE_PROMPT.format(preferred_output=preferred_output)})
reply = call_openai(messages)
Expand Down Expand Up @@ -232,7 +234,7 @@ def interact(self, instruction, res, role, task):
add_display_message(cur_task, role, empty_feedback_placeholder, get_time())
return None

refined_reply = pool.submit(asyncio.run, self.feedback(copy.deepcopy(self.conversation_history), instruction, res['content'], feedback)).result()
refined_reply = pool.submit(asyncio.run, self.feedback(self.conversation_history, instruction, res['content'], feedback)).result()

if refined_reply is not None:
print('='*6 + 'REFINED OUPUT' + '='*6, flush=True)
Expand Down Expand Up @@ -343,7 +345,7 @@ def parse(self, role="", task=""):
if refined_reply is None:
return res

rules = self.extract_rules_from_feedback(copy.deepcopy(self.conversation_history), res['content'], refined_reply)
rules = self.extract_rules_from_feedback(self.conversation_history, res['content'], refined_reply)

flag = 0
new_doc = Document(page_content=vars, metadata={'rules': '\n'.join(rules), 'task': task, 'source': task + '|' + vars.replace('|', '\|'), 'messages': str(self.conversation_history), 'response': res['content'], 'refined_response': refined_reply, 'feedback': self.feedbacks[-1]['feedback'], 'auto': self.feedbacks[-1]['auto']})
Expand Down

0 comments on commit 716380f

Please sign in to comment.