Skip to content

Commit

Permalink
updated getting started doc for callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
brainlid committed Jun 18, 2024
1 parent bf5e61f commit 35a57bb
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions guides/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,27 @@ In this example, we'll output the responses as they are streamed back. That happ
```elixir
alias LangChain.MessageDelta

callback = fn
%MessageDelta{} = data ->
handler = %{
on_llm_new_delta: fn _model, %MessageDelta{} = data ->
# we received a piece of data
IO.write(data.content)

%Message{} = data ->
end,
on_llm_new_message: fn _model, %Message{} = data ->
# we received the finshed message once fully complete
IO.puts("")
IO.puts("")
IO.inspect(data.content, label: "COMPLETED MESSAGE")
end
end
}

{:ok, _updated_chain, response} =
%{llm: ChatOpenAI.new!(%{model: "gpt-4", stream: true})}
%{llm: ChatOpenAI.new!(%{model: "gpt-4o", stream: true, callbacks: [handler]})}
|> LLMChain.new!()
|> LLMChain.add_messages([
Message.new_system!("You are a helpful assistant."),
Message.new_user!("Write a haiku about the capital of the United States")
])
|> LLMChain.run(callback_fn: callback)
|> LLMChain.run()

response.content
# streamed
Expand Down

0 comments on commit 35a57bb

Please sign in to comment.