Maximilian-Winter / llama-cpp-agent

The llama-cpp-agent framework is a tool designed for easy interaction with Large Language Models (LLMs). Allowing users to chat with LLM models, execute structured function calls and get structured output. Works also with models not fine-tuned to JSON output and function calls.
Other
472 stars 42 forks source link

Is it necessary add additional_fields to AgentChainElement ? #50

Closed svjack closed 5 months ago

svjack commented 5 months ago

In the example of https://llama-cpp-agent.readthedocs.io/en/latest/map_chain/ If I want to add a AgentChainElement to it as

summary_chain = AgentChainElement("out_0", 
system_prompt="You are an advanced AI agent for summarizing articles", 
prompt="Summarize this article into bullet points:\n{item}")

translate_chain = AgentChainElement("out_1",
system_prompt="You are an advanced AI agent for translate articles",
 prompt="translate the content into French")

combine_chain = AgentChainElement("out_2",
system_prompt="You are an advanced AI agent that summarizes text",
prompt="You are an advanced AI agent that summarizes text", prompt="Please combine the French bullet points of different summaries below, into one summary as French bullet points:\n{map_output}")

map_chain = MapChain(agent, [summary_chain, translate_chain], [combine_chain])
out = map_chain.run_map_chain(items_to_map=article_list)

the translate_chain seems not take summary_chain's output as its input. Is it necessary add additional_fields (run_map_chain) to AgentChainElement Or I should call run_map_chain In sequence manually ?

Maximilian-Winter commented 5 months ago

@svjack Hi, I think your code should look something like this:

summary_chain = AgentChainElement("out_0",
                                  system_prompt="You are an advanced AI agent for summarizing articles",
                                  prompt="Summarize this article into bullet points:\n{item}")

translate_chain = AgentChainElement("out_1",
                                    system_prompt="You are an advanced AI agent for translate articles",
                                    prompt="translate the content into French:\n{out_0}")

combine_chain = AgentChainElement("out_2",
                                  system_prompt="You are an advanced AI agent that summarizes text",
                                  prompt="Please combine the French bullet points of different summaries below, into one summary as French bullet points:\n{map_output}")

map_chain = MapChain(agent, [summary_chain, translate_chain], [combine_chain])

map_chain.run_map_chain(items_to_map=article_list)

You basically pipe the output from the first element in the second as out_0 and then use the outputs of the first chain in the second with map_output

Maximilian-Winter commented 5 months ago

The elment summary_chain will forward its output to translate_chain. The two elements build the first map chain, which will be invoked on every input element ìtems_to_mapand then the results of all these runs will be put into one prompt for the combine_chain under map_output.

Maximilian-Winter commented 5 months ago

@svjack I added a full example like yours here: https://github.com/Maximilian-Winter/llama-cpp-agent/blob/master/examples/08_Chains/map_chain_summary_translate.py