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

Conversion issue in createOpenAPIChain? #3266

Closed
Manouchehri opened this issue Nov 14, 2023 · 4 comments · Fixed by #3267
Closed

Conversion issue in createOpenAPIChain? #3266

Manouchehri opened this issue Nov 14, 2023 · 4 comments · Fixed by #3267
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@Manouchehri
Copy link
Contributor

Looks like there's an unexpected . in the API function name somehow, can't trace down where the . -> _ replacement is supposed to be happening in langchainjs.

[llm/error] [1:llm:ChatOpenAI] [2.18s] LLM run errored with error: "400 '_api_v1_0.0/weather_get' does not match '^[a-zA-Z0-9_-]{1,64}$' - 'functions.0.name'"
A promise rejection was handled asynchronously. This warning occurs when attaching a catch handler to a promise after it rejected. (rejection #3)
[mf:err] Error: 400 '_api_v1_0.0/weather_get' does not match '^[a-zA-Z0-9_-]{1,64}$' - 'functions.0.name'
    at APIError.generate (/Users/dave/Work/langchain-workers/langchain-worker/node_modules/openai/src/error.ts:66:14)
    at OpenAI.makeStatusError (/Users/dave/Work/langchain-workers/langchain-worker/node_modules/openai/src/core.ts:358:21)
    at OpenAI.makeRequest (/Users/dave/Work/langchain-workers/langchain-worker/node_modules/openai/src/core.ts:416:24)
    at null.<anonymous> (async index.js:18794:25)
    at async RetryOperation._fn (/Users/dave/Work/langchain-workers/langchain-worker/node_modules/p-retry/index.js:50:12)

Code to reproduce:

const chain = await createOpenAPIChain("https://caymanweather.aimoda.dev/openapi.json", {
  llm: model
});

const result = await chainapi.run(`What's the current weather in Cayman?`);
Copy link

dosubot bot commented Nov 14, 2023

🤖

Hello again, @Manouchehri! Good to see you back. I see you've run into a new issue with the createOpenAPIChain function. Let me dive into this problem and I'll get back to you with a detailed response shortly.

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

dosubot bot commented Nov 14, 2023

🤖

Based on the error message you provided, it seems like the issue is with the function name 'api_v1_0.0/weather_get' not matching the expected pattern '^[a-zA-Z0-9-]{1,64}$'. This pattern does not allow for periods ('.') in the function name, which is why the error is being thrown.

The createOpenAPIChain function, which is actually defined as createOpenApiAgent in the openapi.ts file, does not handle the conversion of . to _ in API function names directly. However, the conversion is likely handled in the OpenAPISpec.getCleanedOperationId function which is called within the convertOpenAPISpecToOpenAIFunctions function. This function is used to generate the OpenAI functions from the OpenAPI specification.

Unfortunately, the OpenAPISpec.getCleanedOperationId function is not provided in the given context, so we cannot provide the exact details of how the conversion is performed. It's possible that there's a bug or oversight in this function that's causing the unexpected . in the function name.

To further investigate this issue, it would be helpful if you could provide the OpenAPI specification that you're using. This would allow us to see if the issue is with the specification itself or with how the createOpenAPIChain function is processing it.

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.

@Manouchehri
Copy link
Contributor Author

Manouchehri commented Nov 14, 2023

@dosubot The OpenAPI spec is:

{"openapi":"3.0.0","info":{"version":"1.0.0","title":"Cayman Weather API (unofficial)"},"tags":[{"name":"language","description":"en"}],"components":{"schemas":{},"parameters":{}},"paths":{"/api/v1.0.0/weather":{"get":{"operationid":"get_weather","responses":{"200":{"description":"Fetch weather data from the Cayman Weather site.","content":{"application/json":{"schema":{"type":"object","properties":{}}}}},"404":{"description":"Unable to fetch the weather data","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string"}}}}}},"500":{"description":"Unexpected internal server error.","content":{"application/json":{"schema":{"type":"object","properties":{"status_code":{"type":"number","description":"Original error code.","example":504},"message":{"type":"string"}}}}}}}}}}}

Copy link

dosubot bot commented Nov 14, 2023

🤖

The error message you're seeing is due to the function name 'api_v1_0.0/weather_get' not matching the expected pattern '^[a-zA-Z0-9-]{1,64}$'. This pattern indicates that function names should only contain alphanumeric characters, underscores, and dashes, and should be between 1 and 64 characters in length.

The issue seems to be with the version number in your OpenAPI specification's path ('/api/v1.0.0/weather'). The 'createOpenAPIChain' function in langchainjs is likely converting this path into a function name, replacing '/' with '', but it's not replacing '.' with '', which is causing the error.

To resolve this issue, you could try changing the version number in your OpenAPI specification's path to not include periods, for example '/api/v1_0_0/weather'. This should result in a function name that matches the expected pattern.

However, this is just a workaround, and it might not be ideal if you have a lot of paths with version numbers in them. A more robust solution would be to modify the 'createOpenAPIChain' function in langchainjs to also replace '.' with '_' when converting paths into function names. Unfortunately, as a technical support rep, I don't have the ability to make this change myself, but I would recommend reaching out to the maintainers of langchainjs to suggest this improvement.

In the meantime, you could also consider creating a custom function to preprocess your OpenAPI specification and replace '.' with '_' in the paths before passing it to 'createOpenAPIChain'. Here's a simple example of how you could do this:

function preprocessOpenAPISpec(spec) {
  for (let path in spec.paths) {
    let newPath = path.replace(/\./g, '_');
    if (newPath !== path) {
      spec.paths[newPath] = spec.paths[path];
      delete spec.paths[path];
    }
  }
  return spec;
}

const spec = await fetch('https://caymanweather.aimoda.dev/openapi.json').then(res => res.json());
const preprocessedSpec = preprocessOpenAPISpec(spec);

const chain = await createOpenAPIChain(preprocessedSpec, {
  llm: model
});

const result = await chainapi.run(`What's the current weather in Cayman?`);

I hope this helps! Let me know if you have any other questions.

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.

jacoblee93 pushed a commit that referenced this issue Nov 14, 2023
* Use replaceAll instead of replace when generating operationid.

Fixes #3266.

* Format code.
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

Successfully merging a pull request may close this issue.

1 participant