Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change return of LLMChain.run/2 - breaking change #170

Merged
merged 3 commits into from
Aug 21, 2024

Conversation

brainlid
Copy link
Owner

@brainlid brainlid commented Aug 21, 2024

  • Remove the "last_message" from the return tuple of LLMChain.run/2
  • Data is still available in %LLMChain{last_message: last_message}
  • Adds %LLMChain{exchanged_messages: exchanged_messages}.

This is a breaking change. Let's cover why this is being done and how to adapt to it.

Why the change

Before this change, an LLMChain's run function returned {:ok, updated_chain, last_message}.

When an assistant (ie LLM) issues a ToolCall and when run is in the mode :until_success or :while_need_response, the LLMChain will automatically execute the function and return the result as a new Message back to the LLM. This works great!

The problem comes when an application needs to keep track of all the messages being exchanged during a run operation. That can be done by using callbacks and sending and receiving messages, but that's far from ideal. It makes more sense to have access to that information directly after the run operation completes.

What this change does

This PR changes the returned type to {:ok, updated_chain}.

The last_message is available in updated_chain.last_message. This cleans up the return API.

This change also adds %LLMChain{exchanged_messages: exchanged_messages},or updated_chain.exchanged_messages which is a list of all the messages exchanged between the application and the LLM during the execution of the run function.

This breaks the return contract for the run function.

How to adapt to this change

To adapt to this, if the application isn't using the last_message in {:ok, updated_chain, _last_message}, then delete the third position in the tuple. Ex: {:ok, updated_chain}.

Access to the last_message is available on the updated_chain.

{:ok, updated_chain} =
  %{llm: model}
  |> LLMChain.new!()
  |> LLMChain.run()

last_message = updated_chain.last_message

NOTE: that the updated_chain now includes updated_chain.exchanged_messages which can also be used.

@brainlid brainlid changed the title return list of exchanged messages after LLMChain.run/2 change return of LLMChain.run/2 - breaking change Aug 21, 2024
@brainlid brainlid merged commit 07bd3fb into main Aug 21, 2024
1 check passed
@brainlid brainlid deleted the me-llmchain-track-exchanged-messages branch August 21, 2024 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant