Skip to content

Commit

Permalink
Docs: Updated callbacks/index.mdx (langchain-ai#16404)
Browse files Browse the repository at this point in the history
The callbacks get started demo code was updated , replacing the
chain.run() command ( which is now depricated) ,with the updated
chain.invoke() command.
Solving the following issue : langchain-ai#16379
Twitter/X : @Hazxhx
  • Loading branch information
HazSyl1 authored Jan 22, 2024
1 parent 873de14 commit dd5b810
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions docs/docs/modules/callbacks/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,42 +95,40 @@ prompt = PromptTemplate.from_template("1 + {number} = ")

# Constructor callback: First, let's explicitly set the StdOutCallbackHandler when initializing our chain
chain = LLMChain(llm=llm, prompt=prompt, callbacks=[handler])
chain.run(number=2)
chain.invoke({"number":2})

# Use verbose flag: Then, let's use the `verbose` flag to achieve the same result
chain = LLMChain(llm=llm, prompt=prompt, verbose=True)
chain.run(number=2)
chain.invoke({"number":2})

# Request callbacks: Finally, let's use the request `callbacks` to achieve the same result
chain = LLMChain(llm=llm, prompt=prompt)
chain.run(number=2, callbacks=[handler])
chain.invoke({"number":2}, {"callbacks":[handler]})

```

<CodeOutputBlock lang="python">

```
> Entering new LLMChain chain...
Prompt after formatting:
1 + 2 =
> Finished chain.
> Entering new LLMChain chain...
Prompt after formatting:
1 + 2 =
> Entering new LLMChain chain...
Prompt after formatting:
1 + 2 =
> Finished chain.
> Finished chain.
> Entering new LLMChain chain...
Prompt after formatting:
1 + 2 =
> Entering new LLMChain chain...
Prompt after formatting:
1 + 2 =
> Finished chain.
> Finished chain.
> Entering new LLMChain chain...
Prompt after formatting:
1 + 2 =
'\n\n3'
> Finished chain.
```

</CodeOutputBlock>
Expand Down

0 comments on commit dd5b810

Please sign in to comment.