_ChatModelBase.start_chat() got an unexpected keyword argument 'functions' #23839
Replies: 1 comment 7 replies
-
Hey @AthulMohanDevkar! I'm here to help you out. If you need assistance with any bugs or questions, feel free to ask. I'm looking forward to assisting you! The Here is an updated version of your code that correctly handles the from langchain.prompts import ChatPromptTemplate
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_google_vertexai import ChatVertexAI
from langchain.output_parsers.openai_functions import JsonKeyOutputFunctionsParser
with open('test.txt') as file:
essay = file.read()
splitter = RecursiveCharacterTextSplitter(chunk_size=4000, chunk_overlap=0)
docs = splitter.create_documents([essay])
print(f"You have {len(docs)} docs")
functions = [
{
"name": "hypothetical_questions",
"description": "Generate hypothetical questions",
"parameters": {
"type": "object",
"properties": {
"questions": {
"type": "array",
"items": {"type": "string"},
},
},
"required": ["questions"],
},
}
]
from langchain.chains.openai_functions.base import convert_to_openai_function
# Convert functions to the required format
formatted_functions = [convert_to_openai_function(fn) for fn in functions]
chain = (
{"doc": lambda x: x.page_content}
| ChatPromptTemplate.from_template(
"Generate a list of exactly 3 hypothetical questions that the below document could be used to answer:\n\n{doc}"
)
| ChatVertexAI(max_retries=0, model="chat-bison@001").bind_functions(
functions=formatted_functions, function_call={"name": "hypothetical_questions"}
)
| JsonKeyOutputFunctionsParser(key_name="questions")
)
chain.invoke(docs[0]) In this updated code, the |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I'm trying to implement Multi-Vector - Hypothetical queries as per the instructions given here: https://python.langchain.com/v0.1/docs/modules/data_connection/retrievers/multi_vector/#hypothetical-queries.
However, running into the below error when using ChatVertexAI. It works fine when you do not pass the functions variable. Also seems to work fine for the OpenAI model.
File "/Users/user/PycharmProjects/testProject/.venv/lib/python3.12/site-packages/langchain_google_vertexai/chat_models.py", line 1615, in _start_chat
return self.client.start_chat(message_history=history.history, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: _ChatModelBase.start_chat() got an unexpected keyword argument 'functions'
System Info
langchain==0.2.6
langchain-community==0.2.6
langchain-core==0.2.10
langchain-experimental==0.0.61
langchain-google-vertexai==1.0.6
langchain-openai==0.1.9
langchain-text-splitters==0.2.2
Platform: mac
Python: Python 3.12.1
Beta Was this translation helpful? Give feedback.
All reactions