From e758e9e7f59ee0bf3a4d19f93e57fbd51f321126 Mon Sep 17 00:00:00 2001 From: "lars.gersmann" Date: Fri, 28 Jul 2023 02:58:43 +0200 Subject: [PATCH] =?UTF-8?q?fix(openapi):=20openapi=20chain=20will=20work?= =?UTF-8?q?=20without/empty=20description/summa=E2=80=A6=20(#8351)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: This PR will enable the Open API chain to work with valid Open API specifications missing `description` and `summary` properties for path and operation nodes in open api specs. Since both `description` and `summary` property are declared optional we cannot be sure they are defined. This PR resolves this problem by providing an empty (`''`) description as fallback. The previous behavior of the Open API chain was that the underlying LLM (OpenAI) throw ed an exception since `None` is not of type string: ``` openai.error.InvalidRequestError: None is not of type 'string' - 'functions.0.description' ``` Using this PR the Open API chain will succeed also using Open API specs lacking `description` and `summary` properties for path and operation nodes. Thanks for your amazing work ! Tag maintainer: @baskaryan --------- Co-authored-by: Lars Gersmann Co-authored-by: Bagatur --- libs/langchain/langchain/tools/openapi/utils/api_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/langchain/langchain/tools/openapi/utils/api_models.py b/libs/langchain/langchain/tools/openapi/utils/api_models.py index f86ba49c77..42e8f13a35 100644 --- a/libs/langchain/langchain/tools/openapi/utils/api_models.py +++ b/libs/langchain/langchain/tools/openapi/utils/api_models.py @@ -480,7 +480,7 @@ class APIOperation(BaseModel): description = spec.paths[path].description or spec.paths[path].summary return cls( operation_id=operation_id, - description=description, + description=description or "", base_url=spec.base_url, path=path, method=method,