From 35a57bbf413a51af97d537c0c97dc4753b686277 Mon Sep 17 00:00:00 2001 From: Mark Ericksen Date: Mon, 17 Jun 2024 22:08:55 -0600 Subject: [PATCH] updated getting started doc for callbacks --- guides/getting_started.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/guides/getting_started.md b/guides/getting_started.md index 3c2591a0..ba8b6b49 100644 --- a/guides/getting_started.md +++ b/guides/getting_started.md @@ -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