Docs: Updated callbacks/index.mdx (#16404)

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 : #16379
Twitter/X : @Hazxhx
This commit is contained in:
Sarthak Chaure 2024-01-23 02:40:19 +05:30 committed by GitHub
parent 873de14cd8
commit dd5b8107b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -95,42 +95,40 @@ prompt = PromptTemplate.from_template("1 + {number} = ")
# Constructor callback: First, let's explicitly set the StdOutCallbackHandler when initializing our chain # Constructor callback: First, let's explicitly set the StdOutCallbackHandler when initializing our chain
chain = LLMChain(llm=llm, prompt=prompt, callbacks=[handler]) 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 # Use verbose flag: Then, let's use the `verbose` flag to achieve the same result
chain = LLMChain(llm=llm, prompt=prompt, verbose=True) 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 # Request callbacks: Finally, let's use the request `callbacks` to achieve the same result
chain = LLMChain(llm=llm, prompt=prompt) chain = LLMChain(llm=llm, prompt=prompt)
chain.run(number=2, callbacks=[handler]) chain.invoke({"number":2}, {"callbacks":[handler]})
``` ```
<CodeOutputBlock lang="python"> <CodeOutputBlock lang="python">
``` ```
> Entering new LLMChain chain... > Entering new LLMChain chain...
Prompt after formatting: Prompt after formatting:
1 + 2 = 1 + 2 =
> Finished chain. > Finished chain.
> Entering new LLMChain chain... > Entering new LLMChain chain...
Prompt after formatting: Prompt after formatting:
1 + 2 = 1 + 2 =
> Finished chain. > Finished chain.
> Entering new LLMChain chain... > Entering new LLMChain chain...
Prompt after formatting: Prompt after formatting:
1 + 2 = 1 + 2 =
> Finished chain. > Finished chain.
'\n\n3'
``` ```
</CodeOutputBlock> </CodeOutputBlock>