Find answers from the community

Updated last year

Hi

Hi!
There is a easy way to combine a CondenseQuestionChatEngine with chatgpt functions like the ones in this example??
https://gpt-index.readthedocs.io/en/stable/examples/agent/openai_agent.html
L
e
16 comments
what kind of program flow are you imagining here?
I have already configured a chatbot class that use a VectorStorageDatabase. I want to use functions from that documentation combined with the index
I mean in terms of technical program flow -- a user sends a message to a chat bot. What steps should happen under the hood?

Just wondering why a regular agent doesnt work for you
I need to ask some user data to check info in the database to create an appointment
And why can't an agent do that? You can give any query engine or tool to an agent. It chooses to use tools based on the tool descriptions and user message/chat history

You can also force one tool/function to always be called first at least once
so in my code configured with a ContextChatEngine or a CondenseQuestionChatEngine I can just:
response = self.chat_engine.stream_chat(input_text,functions=functions)
Well, you need to setup an agent, but pretty much

Plain Text
from llama_index.agent import OpenAIAgent
from llama_index.tools import BaseTool, FunctionTool, QueryEngineTool

def multiply(a: int, b: int) -> int:
    """Multiple two integers and returns the result integer"""
    return a * b

# uses docstring as description and fn_name as name
multiply_tool = FunctionTool.from_defaults(fn=multiply)

query_engine_tool = QueryEngineTool.from_defaults(query_engine, name=name, description=description)

agent = OpenAIAgent.from_tools([query_engine_tool, multiply_tool])
agent.chat("Hello!")

# or, you can force a function to be called at least once
agent = OpenAIAgent.from_tools([query_engine_tool, multiply_tool], function_call="name to call every time")
Now, I have an agent that can use a query engine or any function I define (multiply in this case)
I am going to try that! Thankss!!
Hey, I am using that example and works fine. Thank you.
I have another issue now, I want to do different things when I access into different functions calls as in the example code:

ai_message = self._llm.chat(chat_history, functions=functions).message chat_history.append(ai_message) function_call = ai_message.additional_kwargs.get("function_call", None) if function_call is not None: function_message = self._call_function(function_call) chat_history.append(function_message) ai_message = self._llm.chat(chat_history).message chat_history.append(ai_message)
how can I access additional_kwargs.get("function_call",None) in the code that you provided?
@Logan M I tag you because I use an old thread
Hmm but what do you mean do different things?

I think you can get the kwargs by checking the chat history

agent.chat_history[-2].additional_kwargs (if a tool was called, it will be the second last element)
I want to automatically return a string if enter to some functions, and to re-enter the question with some params as the multiply function in others
Sounds like you should just make a custom function tool (like multiply) for each of your tools/query engines?
Then you have full control
yes, for example, one greeting function, another to get some user data
Add a reply
Sign up and join the conversation on Discord