Skip to content

Commit

Permalink
Merge pull request #64 from langchain-ai/harrison/fix-anthropic
Browse files Browse the repository at this point in the history
fix anthropic models
  • Loading branch information
nfcampos authored Nov 20, 2023
2 parents 83b933d + d2c6696 commit 6e3a860
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 6e3a860

Please sign in to comment.