Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "No function_call in message" on TaggingChain #2362

Closed
AlexPagnotta opened this issue Aug 22, 2023 · 2 comments
Closed

Error "No function_call in message" on TaggingChain #2362

AlexPagnotta opened this issue Aug 22, 2023 · 2 comments
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@AlexPagnotta
Copy link

Hello,

I'm using the tagging chain from the createTaggingChainFromZod method, to extract the intent and some other data form the user input, and it works pretty well, but sometimes, randomly, I get the following error during the execution:

[chain/error] [1:chain:LLMChain] [7.71s] Chain run errored with error: "No function_call in message [{\"text\":\"{\\n  \\\"intent\\\": \\\"room_dimensions_retrieval\\\",\\n  \\\"product_category\\\": \\\"kitchen_appliances\\\",\\n  \\\"room_dimensions\\\": {\\n    \\\"room_width_in_meters_x\\\": 12,\\n    \\\"room_length_in_meters_y\\\": 6,\\n    \\\"room_height_in_meters_z\\\": 3\\n  }\\n}\",\"message\":{\"lc\":1,\"type\":\"constructor\",\"id\":[\"langchain\",\"schema\",\"AIMessage\"],\"kwargs\":{\"content\":\"{\\n  \\\"intent\\\": \\\"room_dimensions_retrieval\\\",\\n  \\\"product_category\\\": \\\"kitchen_appliances\\\",\\n  \\\"room_dimensions\\\": {\\n    \\\"room_width_in_meters_x\\\": 12,\\n    \\\"room_length_in_meters_y\\\": 6,\\n    \\\"room_height_in_meters_z\\\": 3\\n  }\\n}\",\"additional_kwargs\":{}}}}]"
- error node_modules/langchain/dist/output_parsers/openai_functions.js (30:22) @ OutputFunctionsParser.parseResult
- error unhandledRejection: Error: No function_call in message [{"text":"{\n  \"intent\": \"room_dimensions_retrieval\",\n  \"product_category\": \"kitchen_appliances\",\n  \"room_dimensions\": {\n    \"room_width_in_meters_x\": 12,\n    \"room_length_in_meters_y\": 6,\n    \"room_height_in_meters_z\": 3\n  }\n}","message":{"lc":1,"type":"constructor","id":["langchain","schema","AIMessage"],"kwargs":{"content":"{\n  \"intent\": \"room_dimensions_retrieval\",\n  \"product_category\": \"kitchen_appliances\",\n  \"room_dimensions\": {\n    \"room_width_in_meters_x\": 12,\n    \"room_length_in_meters_y\": 6,\n    \"room_height_in_meters_z\": 3\n  }\n}","additional_kwargs":{}}}}]
    at OutputFunctionsParser.parseResult (webpack-internal:///(sc_server)/./node_modules/langchain/dist/output_parsers/openai_functions.js:41:23)
    at JsonOutputFunctionsParser.parseResult (webpack-internal:///(sc_server)/./node_modules/langchain/dist/output_parsers/openai_functions.js:90:48)
    at JsonOutputFunctionsParser.parseResultWithPrompt (webpack-internal:///(sc_server)/./node_modules/langchain/dist/schema/output_parser.js:11:21)
    at LLMChain._getFinalOutput (webpack-internal:///(sc_server)/./node_modules/langchain/dist/chains/llm_chain.js:96:55)
    at LLMChain._call (webpack-internal:///(sc_server)/./node_modules/langchain/dist/chains/llm_chain.js:127:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async LLMChain.call (webpack-internal:///(sc_server)/./node_modules/langchain/dist/chains/base.js:98:28)
    at async LLMChain.run (webpack-internal:///(sc_server)/./node_modules/langchain/dist/chains/base.js:66:30)
    at async sequence.run (webpack-internal:///(sc_server)/./app/api/v1/story/[sessionId]/message/route.ts:237:45) {
  digest: undefined
}
null

As I said it does not happen all the times, I tried to understand what causes it, but seems totally random.
I've also tried to understand the error, and it seems that no OpenAI function is passed, but I saw in the code that the function is directly added by the chain, so not sure how this could happen.

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Aug 22, 2023
@dosubot
Copy link

dosubot bot commented Aug 22, 2023

🤖

Hello,

Thank you for reaching out and providing detailed information about the issue you're experiencing.

The error message you're seeing, "No function_call in message", is typically thrown when the language model (LLM) you're using does not support OpenAI function calling. The createTaggingChainFromZod function, as well as the createTaggingChain function it calls, require an LLM that supports OpenAI function calling.

Here's the relevant part of the code from the createTaggingChainFromZod function:

/**
 * Function that creates a tagging chain from a Zod schema. It converts
 * the Zod schema to a JSON schema using the zodToJsonSchema function and
 * then calls createTaggingChain with the converted schema.
 * @param schema The Zod schema which extracted data should match.
 * @param llm LLM to use in the chain. Must support OpenAI function calling.
 * @param options Options for creating the tagging chain.
 * @returns A new instance of LLMChain configured for tagging.
 */
export function createTaggingChainFromZod(
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  schema: z.ZodObject<any, any, any, any>,
  llm: ChatOpenAI,
  options?: TaggingChainOptions
) {
  return createTaggingChain(
    zodToJsonSchema(schema) as JsonSchema7ObjectType,
    llm,
    options
  );
}

You can find this in the langchain/src/chains/openai_functions/tagging.ts file.

If the LLM you're using does not support OpenAI function calling, you'll need to use an LLM that does, or modify your existing LLM to add this support.

However, since you mentioned that the error occurs intermittently, it might be due to some other factors as well. It could be related to the specific input you're processing at the time the error occurs, or it could be a timing issue where the function call is not ready when the chain is run.

To help narrow down the cause, could you provide more information about the specific circumstances when the error occurs? For example, does it happen with specific inputs or after a certain amount of time or number of requests? Any additional information you can provide will be helpful in diagnosing the issue.

Best,
Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

Copy link

dosubot bot commented Nov 21, 2023

Hi, @AlexPagnotta! I'm Dosu, and I'm here to help the langchainjs team manage their backlog. I wanted to let you know that we are marking this issue as stale.

Based on the information provided, it seems that you were experiencing a random error message stating "No function_call in message" when using the tagging chain from the createTaggingChainFromZod method. It appears that the cause of the error is unknown, and you were unsure why this was happening since the function is directly added by the chain. In response, Dosubot suggested that this error message is typically thrown when the language model being used does not support OpenAI function calling. Dosubot provided code snippets and suggested using an LLM that supports OpenAI function calling or modifying the existing LLM to add this support.

Now, we would like to know if this issue is still relevant to the latest version of the langchainjs repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days.

Thank you for your understanding and cooperation. Let us know if you have any further questions or concerns!

Best regards,
Dosu

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 21, 2023
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2023
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant