openapi_openai docstring (#6661)

This commit is contained in:
Davis Chase 2023-06-23 11:38:33 -07:00 committed by GitHub
parent b25933b607
commit 6988039975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 31 deletions

View File

@ -20,18 +20,10 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "08e19b64",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Attempting to load an OpenAPI 3.0.1 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for better support.\n"
]
}
],
"outputs": [],
"source": [
"from langchain.chains.openai_functions.openapi import get_openapi_chain\n",
"\n",
@ -103,19 +95,10 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "bf6cd695",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Attempting to load an OpenAPI 3.0.1 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for better support.\n",
"Attempting to load an OpenAPI 3.0.1 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for better support.\n"
]
}
],
"outputs": [],
"source": [
"chain = get_openapi_chain(\"https://api.speak.com/openapi.yaml\")"
]
@ -152,18 +135,10 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"id": "a9198f62",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Attempting to load an OpenAPI 3.0.0 spec. This may result in degraded performance. Convert your OpenAPI spec to 3.1.* spec for better support.\n"
]
}
],
"outputs": [],
"source": [
"chain = get_openapi_chain(\"https://gist.githubusercontent.com/roaldnefs/053e505b2b7a807290908fe9aa3e1f00/raw/0a212622ebfef501163f91e23803552411ed00e4/openapi.yaml\")"
]

View File

@ -207,6 +207,15 @@ def get_openapi_chain(
prompt: Optional[BasePromptTemplate] = None,
request_chain: Optional[Chain] = None,
) -> SequentialChain:
"""Create a chain for querying an API from a OpenAPI spec.
Args:
spec: OpenAPISpec or url/file/text string corresponding to one.
llm: language model, should be an OpenAI function-calling model, e.g.
`ChatOpenAI(model="gpt-3.5-turbo-0613")`.
prompt: Main prompt template to use.
request_chain: Chain for taking the functions output and executing the request.
"""
if isinstance(spec, str):
for conversion in (
OpenAPISpec.from_url,