Closed Manouchehri closed 4 months ago
π€
Hello again @Manouchehri, good to see you! I hope you're doing well.
Thanks for detailed report. I'm diving into this issue that you've brought up about the createOpenAPIChain
error, and I'll get back to you with a more comprehensive response shortly.
π€
Thank you for bringing this to our attention. It seems like the createOpenAPIChain
function is indeed throwing an error when the servers
field is missing from the OpenAPI specification. This is because the function is trying to access the url
property of the first server in the servers
array, which is undefined when the servers
field is missing.
To fix this issue, we can modify the baseUrl
getter method in the OpenAPISpec
class to extract the base URL from the spec URL when the servers
field is not present. Here's how you can do it:
get baseUrl() {
if (this.document.servers) {
return this.document.servers[0].url;
} else {
const url = new URL(this.document.url);
return url.origin;
}
}
In the above code, URL
is a built-in JavaScript class for parsing URLs. url.origin
gives the origin of the URL (protocol + hostname + port), which is the base URL you need.
Please note that this change should be made in the openapi.ts
file in the langchain/src/chains/openai_functions/
directory of the langchainjs repository.
I hope this helps! If you have any further questions or run into any issues, please don't hesitate to ask.
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.
Hi, @Manouchehri,
I'm helping the langchainjs team manage their backlog and am marking this issue as stale. From what I understand, you raised an issue regarding a TypeError thrown by the createOpenAPIChain
function when the servers
field is missing in the OpenAPI spec. Dosubot responded with a detailed explanation of the issue, suggesting a modification to the baseUrl
getter method in the OpenAPISpec
class to handle the absence of the servers
field. The issue was marked as resolved, and Dosubot provided code snippets and links to relevant files in the repository for making the necessary changes.
Could you please confirm if this issue is still relevant to the latest version of the langchainjs repository? If it is, please let the langchainjs team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.
Thank you!
We should fix this by defaulting to the same server as the spec if the
servers
object is missing. e.g. if the spec is onhttps://caymanweather.aimoda.dev/openapi.json
, we can safely assume that the server is also onhttps://caymanweather.aimoda.dev
.Related to #3267 and semi-related to https://github.com/honojs/middleware/issues/243.