Skip to content

Cannot stream response from cohere #592

@hizbul-inument

Description

@hizbul-inument

I am using langgraph stream_events and inside tools i am using cohere.

from langgraph.prebuilt import create_react_agent

async def generate_stream_response(message: str, user: dict, prompt_dict: dict):
    tools = [search_for_australia, search_for_newzealand]
    langgraph_agent_executor = create_react_agent(
        llm,
        tools=tools,
        state_modifier=None,
        checkpointer=memory
    )

    config = {"configurable": {"thread_id": prompt_dict['group_id']}}
    
    prompt = {"messages": [{"role": "user", "content": message}]}
    async for event in langgraph_agent_executor.astream_events(prompt, config, stream_mode="values", version="v2"):
         print(event)

I can not yeild response from tools.


@tool
def search_for_australia(query: str):
    """Searches Australia for relevant information"""
    documents = query_faiss(faiss_index, query, model, texts)
    llm_response_stream = co.chat_stream(
        messages=[{"role": "user", "content": query}],
        documents=documents,
        model="command-r-plus-08-2024",
        temperature=0.4
    )
    for event in llm_response_stream:
        if event:
            if event.type == "content-delta":
                print(event.delta.message.content.text)

But, can print like above. And If I co.chat and return response the data the it works. But, it's not a solution, cause it's return all data at a time and langgraph_agent_executor.astream_events is waiting until get the response.

Note: I can not show the citations also.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions