langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
92.26k stars 14.73k forks source link

Output Parser Exception for Tagging UseCase #18906

Closed yadavalok1 closed 2 months ago

yadavalok1 commented 6 months ago

Checked other resources

Example Code

schema = { "properties": { "sentiment": {"type": "string"}, "aggressiveness": {"type": "integer"}, "language": {"type": "string"}, } }

chain = create_tagging_chain(schema, model)

test_string = "Hey there!! We are going to celerate john's birthday. Suggest some celebration idea."

res = chain.invoke(test_string)

Error Message and Stack Trace (if applicable)

File "/python3.11/site-packages/langchain/chains/llm.py", line 104, in _call return self.create_outputs(response)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/python3.11/site-packages/langchain/chains/llm.py", line 258, in create_outputs result = [ ^ File "/python3.11/site-packages/langchain/chains/llm.py", line 261, in self.output_key: self.output_parser.parse_result(generation), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/python3.11/site-packages/langchain_core/output_parsers/openai_functions.py", line 102, in parse_result raise OutputParserException( langchain_core.exceptions.OutputParserException: Could not parse function call data: Expecting property name enclosed in double quotes: line 2 column 3 (char 4)

Description

System Info

System Information

OS: Linux OS Version: #18~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Python Version: 3.11.6 (main, Oct 23 2023, 22:47:21) [GCC 9.4.0]

Package Information

langchain_core: 0.1.29 langchain: 0.1.11 langchain_community: 0.0.25 langsmith: 0.1.22 langchain_openai: 0.0.8 langchain_text_splitters: 0.0.1

Packages not installed (Not Necessarily a Problem)

The following packages were not found:

langgraph langserve

maximeperrindev commented 6 months ago

Hi @yadavalok1

Which model are you using ? I tried to use LLM Model OpenAI() and it didn't work. However when i tried with ChatOpenAI, it worked.

So, I recommend you to use a chat model instead of llm

yadavalok1 commented 6 months ago

Hi @yadavalok1

Which model are you using ? I tried to use LLM Model OpenAI() and it didn't work. However when i tried with ChatOpenAI, it worked.

So, I recommend you to use a chat model instead of llm

Hi @maximeperrindev , I am using AzureOpenAI, I will try using AzureChatOpenAI and confirm you here if it works for me.

yadavalok1 commented 6 months ago

Still getting the same error with AzureChatOpenAI, is there any workaround for this because I am directly using the tagging usecase code from the langchain repo and it seems to be not working.

My requirement is that , whenever a conversation starts I need to collect some required info from the user like personal details and once all required data are provided then only, I can help the user with it's query/questions. Also I need to store the collected also in some memory so the AI should know the context of it. So, it will be really helpful if you can suggest something or something like this is already.

Thanks!!

maximeperrindev commented 6 months ago

@yadavalok1, Well, I tried with this code and it's working. I used the same libs versions.

from langchain_openai import AzureChatOpenAI
from langchain.chains import create_tagging_chain
schema = {
    "properties": {
        "sentiment": {"type": "string"},
        "aggressiveness": {"type": "integer"},
        "language": {"type": "string"},
    }
}

chain = create_tagging_chain(schema,AzureChatOpenAI(
            azure_deployment="gpt-4-32k",
            openai_api_version="2023-05-15",
        ))

test_string = "Hey there!! We are going to celerate john's birthday. Suggest some celebration idea."

res = chain.invoke(test_string)
print(res)
yadavalok1 commented 6 months ago

@yadavalok1, Well, I tried with this code and it's working. I used the same libs versions.

from langchain_openai import AzureChatOpenAI
from langchain.chains import create_tagging_chain
schema = {
    "properties": {
        "sentiment": {"type": "string"},
        "aggressiveness": {"type": "integer"},
        "language": {"type": "string"},
    }
}

chain = create_tagging_chain(schema,AzureChatOpenAI(
            azure_deployment="gpt-4-32k",
            openai_api_version="2023-05-15",
        ))

test_string = "Hey there!! We are going to celerate john's birthday. Suggest some celebration idea."

res = chain.invoke(test_string)
print(res)

Thanks @maximeperrindev . I tried this but no luck , still facing the same error. Tried in different machine as well but same error. I hope this is not related to the model as I am using gpt35.