Skip to content

Commit

Permalink
fix anthropic models
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchase17 committed Nov 20, 2023
1 parent 94f7fee commit d2c6696
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@

def _collapse_messages(messages):
log = ""
scratchpad, final_message = messages[:-1], messages[-1]
if isinstance(messages[-1], AIMessage):
scratchpad = messages[:-1]
final = messages[-1]
else:
scratchpad = messages
final = None
if len(scratchpad) % 2 != 0:
raise ValueError("Unexpected")
for i in range(0, len(scratchpad), 2):
action = messages[i]
observation = messages[i + 1]
log += f"{action.content}<observation>{observation.content}</observation>"
log += final_message.content
if final is not None:
log += final.content
return AIMessage(content=log)


def construct_chat_history(messages):
collapsed_messages = []
temp_messages = []

for message in messages:
if isinstance(message, HumanMessage):
if temp_messages:
Expand Down

0 comments on commit d2c6696

Please sign in to comment.