Skip to content

Commit

Permalink
Fix cohere bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanleomk committed Oct 12, 2024
1 parent d2c2f06 commit d8d521f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions instructor/reask.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ def reask_cohere_tools(
attempt_number: int = 1,
):
if attempt_number == 1:
kwargs["chat_history"].extend(
[{"role": "user", "message": kwargs.get("message")}]
)
chat_history = kwargs.get("chat_history", [])
chat_history.append({"role": "user", "message": kwargs.get("message")})
kwargs["chat_history"] = chat_history

kwargs["message"] = (
f"Correct the following JSON response, based on the errors given below:\n\n"
f"JSON:\n{response.text}\n\nExceptions:\n{exception}"
Expand Down
6 changes: 3 additions & 3 deletions instructor/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def handle_templating(
# Handle Cohere's message field
if "message" in new_kwargs:
new_kwargs["message"] = apply_template(new_kwargs["message"], context)
new_kwargs["chat_history"] = handle_templating(
new_kwargs["chat_history"], context
)
for message in new_kwargs["chat_history"]:
process_message(message, context)

return new_kwargs

if isinstance(new_kwargs, list):
Expand Down

0 comments on commit d8d521f

Please sign in to comment.