Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming comes with extra data. #591

Open
hizbul-inument opened this issue Oct 10, 2024 · 0 comments
Open

Streaming comes with extra data. #591

hizbul-inument opened this issue Oct 10, 2024 · 0 comments

Comments

@hizbul-inument
Copy link

I am using langchain and cohere. It works fine whenever i used invoke with agent executor, but whenever i moved for streaming and using astream_events i got extra data along with the response. Following is my sample code and response.

 agent = create_cohere_react_agent(
        llm=llm,
        tools=tools,
        prompt=prompt
    )
agent_executor = AgentExecutor(agent=agent, tools=[search_1, search_2], verbose=True)
            
# Get Response
async for event in agent_executor.astream_events({
            "preamble": session_data["initial_prompt"],
    }, version="v2", exclude_names=["Plan", "Action", "Relevant Documents", "Cited Documents"]):
    if event["event"] == "on_chat_model_stream":
        chunk_content = serialize_aimessagechunk(event["data"]["chunk"])
        chunk_content_html = chunk_content.replace("\n", "<br>")
        yield f"data: {json.dumps({'event': 'stream', 'data': chunk_content_html})}\n\n"

I am getting following response:

Plan: I will greet the user and ask for their name and location, then tailor my response accordingly. Action: json [ { "tool_name": "directly_answer", "parameters": {} } ] Relevant Documents: None Cited Documents: None Answer: Hi! It's lovely to hear from you. What's your name, and are you based in Australia or New Zealand? Grounded answer: Hi! It's lovely to hear from you. What's your name, and are you based in Australia or New Zealand?

https://docs.cohere.com/v2/docs/implementing-a-multi-step-agent-with-langchain i found multi step agent log should be like my response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant