Git Product home page Git Product logo

Comments (8)

ajndkr avatar ajndkr commented on August 23, 2024 2

it doesn't stream responses back to the chat, although it shows them in the Python output.

I see! It's likely due to this:

answer_prefix_tokens: list[str] = ["Final", " Answer", ":"]

I need to update this to handle all agent types. I think currently only zero shot agents are supported.

from lanarky.

ajndkr avatar ajndkr commented on August 23, 2024 1

@votkon sure! do you maybe have a langchain example or a use case?

from lanarky.

ajndkr avatar ajndkr commented on August 23, 2024 1

@votkon I think you can use OpenAI functions directly via initialise_agent() (https://python.langchain.com/docs/modules/agents/agent_types/openai_functions_agent). The function creates an AgentExecutor instance which is already supported. See example: https://github.com/ajndkr/lanarky/blob/main/examples/app/zero_shot_agent.py

from lanarky.

votkon avatar votkon commented on August 23, 2024 1

Thanks for the prompt reply!

I somehow missed this example.

After giving it a try it looks like it doesn't communicate correctly with the frontend app.

In the zero_shot_agent.py example, when I change the

  return initialize_agent(
        tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
    ) 

to

  return initialize_agent(
        tools, llm, agent=AgentType.OPENAI_FUNCTIONS, verbose=True
    )

it doesn't stream responses back to the chat, although it shows them in the Python output.

Also, it doesn't look like initialize_agent supports the memory parameter:
https://python.langchain.com/docs/modules/memory/how_to/agent_with_memory

I am doing a simple web chat with conversation memory and the ability to call different tools and/or functions.

Thanks!

from lanarky.

votkon avatar votkon commented on August 23, 2024

Thanks! Have you had a chance to look into it?

from lanarky.

ajndkr avatar ajndkr commented on August 23, 2024

Thanks! Have you had a chance to look into it?

nope! i have been busy these past few weeks. I will try to find more time to work on this repo.

from lanarky.

GuillaumeBeal avatar GuillaumeBeal commented on August 23, 2024

Hi @votkon,

Using this custom class

    class CustomAsyncAgentsStreamingCallback(AsyncAgentsLanarkyCallback, AsyncLLMChainStreamingCallback):
        """AsyncStreamingResponseCallback handler for AgentExecutor."""
        answer_prefix_tokens: list[str] = [""]

and using it as a callback in your StreamingResponse may be a quickfix for you

StreamingResponse.from_chain( 
        agent_executor, 
        {"input": query}, 
        media_type="text/event-stream",
        callback=CustomAsyncAgentsStreamingCallback
    )

from lanarky.

ajndkr avatar ajndkr commented on August 23, 2024

I will add native support for OpenAI functions as part of v0.9 roadmap.

from lanarky.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.