Closed krisnagita closed 3 months ago
I've also tried different version of langchain and also didn't work
Did you try langchain 0.1.*? I had the same problem today when I rebuilded my project because langchain~=0.1.20
in my requirements.txt installed langchain==0.2.7
that was not compatible.
I've tried your solution and its worked for me. Thank you @Selroy46
I have 0.2.18 installed I ran the example in the documentation here I am getting the same
ValidationError Traceback (most recent call last)
Cell In[11], [line 15](vscode-notebook-cell:?execution_count=11&line=15)
[6](vscode-notebook-cell:?execution_count=11&line=6) examples = [
[7](vscode-notebook-cell:?execution_count=11&line=7) {"input": "2+2", "output": "4"},
[8](vscode-notebook-cell:?execution_count=11&line=8) {"input": "2+3", "output": "5"},
[9](vscode-notebook-cell:?execution_count=11&line=9) ]
[11](vscode-notebook-cell:?execution_count=11&line=11) example_prompt = ChatPromptTemplate.from_messages(
[12](vscode-notebook-cell:?execution_count=11&line=12) [('human', '{input}'), ('ai', '{output}')]
[13](vscode-notebook-cell:?execution_count=11&line=13) )
---> [15](vscode-notebook-cell:?execution_count=11&line=15) few_shot_prompt = FewShotChatMessagePromptTemplate(
[16](vscode-notebook-cell:?execution_count=11&line=16) examples=examples,
[17](vscode-notebook-cell:?execution_count=11&line=17) # This is a prompt template used to format each individual example.
[18](vscode-notebook-cell:?execution_count=11&line=18) example_prompt=example_prompt,
[19](vscode-notebook-cell:?execution_count=11&line=19) )
[21](vscode-notebook-cell:?execution_count=11&line=21) final_prompt = ChatPromptTemplate.from_messages(
[22](vscode-notebook-cell:?execution_count=11&line=22) [
[23](vscode-notebook-cell:?execution_count=11&line=23) ('system', 'You are a helpful AI Assistant'),
(...)
[26](vscode-notebook-cell:?execution_count=11&line=26) ]
[27](vscode-notebook-cell:?execution_count=11&line=27) )
[28](vscode-notebook-cell:?execution_count=11&line=28) final_prompt.format(input="What is 4+4?")
File c:\ProgramData\Anaconda3\envs\grag\Lib\site-packages\pydantic\v1\main.py:341, in BaseModel.__init__(__pydantic_self__, **data)
[339](file:///C:/ProgramData/Anaconda3/envs/grag/Lib/site-packages/pydantic/v1/main.py:339) values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
[340](file:///C:/ProgramData/Anaconda3/envs/grag/Lib/site-packages/pydantic/v1/main.py:340) if validation_error:
--> [341](file:///C:/ProgramData/Anaconda3/envs/grag/Lib/site-packages/pydantic/v1/main.py:341) raise validation_error
[342](file:///C:/ProgramData/Anaconda3/envs/grag/Lib/site-packages/pydantic/v1/main.py:342) try:
[343](file:///C:/ProgramData/Anaconda3/envs/grag/Lib/site-packages/pydantic/v1/main.py:343) object_setattr(__pydantic_self__, '__dict__', values)
ValidationError: 1 validation error for FewShotChatMessagePromptTemplate
input_variables
field required (type=value_error.missing)`
I have 0.2.18 installed I ran the example in the documentation here I am getting the same
ValidationError Traceback (most recent call last) Cell In[11], [line 15](vscode-notebook-cell:?execution_count=11&line=15) [6](vscode-notebook-cell:?execution_count=11&line=6) examples = [ [7](vscode-notebook-cell:?execution_count=11&line=7) {"input": "2+2", "output": "4"}, [8](vscode-notebook-cell:?execution_count=11&line=8) {"input": "2+3", "output": "5"}, [9](vscode-notebook-cell:?execution_count=11&line=9) ] [11](vscode-notebook-cell:?execution_count=11&line=11) example_prompt = ChatPromptTemplate.from_messages( [12](vscode-notebook-cell:?execution_count=11&line=12) [('human', '{input}'), ('ai', '{output}')] [13](vscode-notebook-cell:?execution_count=11&line=13) ) ---> [15](vscode-notebook-cell:?execution_count=11&line=15) few_shot_prompt = FewShotChatMessagePromptTemplate( [16](vscode-notebook-cell:?execution_count=11&line=16) examples=examples, [17](vscode-notebook-cell:?execution_count=11&line=17) # This is a prompt template used to format each individual example. [18](vscode-notebook-cell:?execution_count=11&line=18) example_prompt=example_prompt, [19](vscode-notebook-cell:?execution_count=11&line=19) ) [21](vscode-notebook-cell:?execution_count=11&line=21) final_prompt = ChatPromptTemplate.from_messages( [22](vscode-notebook-cell:?execution_count=11&line=22) [ [23](vscode-notebook-cell:?execution_count=11&line=23) ('system', 'You are a helpful AI Assistant'), (...) [26](vscode-notebook-cell:?execution_count=11&line=26) ] [27](vscode-notebook-cell:?execution_count=11&line=27) ) [28](vscode-notebook-cell:?execution_count=11&line=28) final_prompt.format(input="What is 4+4?") File c:\ProgramData\Anaconda3\envs\grag\Lib\site-packages\pydantic\v1\main.py:341, in BaseModel.__init__(__pydantic_self__, **data) [339](file:///C:/ProgramData/Anaconda3/envs/grag/Lib/site-packages/pydantic/v1/main.py:339) values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data) [340](file:///C:/ProgramData/Anaconda3/envs/grag/Lib/site-packages/pydantic/v1/main.py:340) if validation_error: --> [341](file:///C:/ProgramData/Anaconda3/envs/grag/Lib/site-packages/pydantic/v1/main.py:341) raise validation_error [342](file:///C:/ProgramData/Anaconda3/envs/grag/Lib/site-packages/pydantic/v1/main.py:342) try: [343](file:///C:/ProgramData/Anaconda3/envs/grag/Lib/site-packages/pydantic/v1/main.py:343) object_setattr(__pydantic_self__, '__dict__', values) ValidationError: 1 validation error for FewShotChatMessagePromptTemplate input_variables field required (type=value_error.missing)`
I also did the example from the documentation and get the same error. Not sure if it is a problem with LangChain or an error in the documentation.
langchain=0.2.7
I encountered the same error but resolved it by adding the input_variables=[]
parameter in FewShotChatMessagePromptTemplate().
examples = [
{"input": "2+2", "output": "4"},
{"input": "2+3", "output": "5"},
]
example_prompt = ChatPromptTemplate.from_messages(
[('human', '{input}'), ('ai', '{output}')]
)
few_shot_prompt = FewShotChatMessagePromptTemplate(
examples=examples,
# This is a prompt template used to format each individual example.
example_prompt=example_prompt,
input_variables=[]
)
print(few_shot_prompt.invoke({}).to_messages())
I encountered the same error but resolved it by adding the
input_variables=[]
parameter in FewShotChatMessagePromptTemplate().examples = [ {"input": "2+2", "output": "4"}, {"input": "2+3", "output": "5"}, ] example_prompt = ChatPromptTemplate.from_messages( [('human', '{input}'), ('ai', '{output}')] ) few_shot_prompt = FewShotChatMessagePromptTemplate( examples=examples, # This is a prompt template used to format each individual example. example_prompt=example_prompt, input_variables=[] ) print(few_shot_prompt.invoke({}).to_messages())
I've tried adding input_variables=[] on my case, and it is works. So my script looked like this:
few_shot_prompt = FewShotChatMessagePromptTemplate(example_prompt = example_prompt, examples = examples, input_variables=[])
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
The error message was:
Description
System Info
functions-framework==3.* google-cloud-aiplatform google-cloud-storage google-cloud-bigquery-storage google-api-python-client google-auth langchain langchain-openai langchain-community langchain-google-vertexai langchain-openai tiktoken nest-asyncio bs4 faiss-cpu langchain_experimental tabulate pandas-gbq sqlalchemy sqlalchemy-bigquery flask
I've also tried different version of langchain and also didn't work