Open doyu opened 1 week ago
An openapi.json file is automatically generated when a web is created and I have a function to extract the necessary information from OAS to be compatible with Function Calling. FC can also be made automated with further investigation.
Digitraffic provides OAS. Can we automatically convert into FC? Requested by FVH today.
I would say it is possible because OAS has quite some necessary information to pass in a tools
list.
Can you play with the above Digitraffic OAS on chatGPT and see if we could easily play with it via natural language? This should be another backlog item.
How does this OAS->FC conversion work?
Does this work as below?
Is this my understanding right? If so, for the part of the above 2, 06_class_to_fc.ipynb
can be used after the above 1? 06_class_to_fc.ipynb
needs some more modification to accept any functions, though.
Then, please use class_to_fc
(actually, fn_to_fc
, though) in 04_oas_to_fc.ipynb
Does the above make sense?
04_oas_to_fc.ipynb
--renamed--> 04_oas_to_fn.ipynb
Once 04_oas_to_fc.ipynb
can work with any OAS basically, please try Digitraffic OAS which FVH is interested to see how it's easy or difficult. I'll put this on our backlog item in the description.
Here are some summary and information about the Open Spec file that can be useful in constructing a function, which I am using in my testing with OAS -> fastAPI
Some important attributes of this Open Spec file include:
openapi
: Specifies the version of the OpenAPI Specification being used (e.g., 3.0.0 or 3.1.0). info
: Contains metadata about the API. Common Fields:
title
: The title of the API. description
: A brief description of the API. version
: The version of the API (not the OAS version). termsOfService
: URL to the terms of service. contact
: Contact information for the API. license
: License information for the API. servers
: Lists the server URLs where the API is available. Common Fields:
url
: The URL of the server. description
: Description of the server environment (e.g., production, development). paths
: Describes the available API endpoints and their operations. Each key in paths represents an endpoint (e.g., /users, /items/{itemId}). Common Fields per Path:
HTTP methods (get, post, put, delete, etc.)
: Each method contains details about the operation in a nested format: summary
: A brief summary of the operation. description:
A detailed description of the operation. operationId
: A unique identifier of the operation. parameters
: Describes the input parameters for the operation. requestBody
: Defines the body of a request (for post, put, etc.). responses
: Describes the possible responses, with HTTP status codes and content. components
: Houses reusable components for the API, which can be referenced elsewhere in the document. Sections:
schemas
: Reusable data models, typically defining request/response structures. parameters
: Predefined parameters to reuse across multiple endpoints. requestBodies
: Reusable request body definitions. securitySchemes
: Defines security protocols (e.g., API keys, OAuth2).And for each endpoint, I am extracting hese attributes:
Furthermore, regarding the inputs and outputs of an endpoint, here is a rough summary of different types of inputs and outputs:
components
and referred to in the endpoint, e.g.,
Reference in endpoint:
Definition in component
endpoint?query1=...
or using requests
library in Python. Defined directly in endpoint:accounts/{user_id}
. Defined directly in endpoint:2...
, e.g., 200
(retrieving information successfully), 204
(operation success but no further outputs). User-side errors will have status codes starting with 4...
, e.g., 400
(bad request), 404
(not found), 401
(unauthorized). Any kind of unrecognized error will usually result in 500
(internal server error).components
and referred to in endpoint definition.Here are some summary and information about the Open Spec file that can be useful in constructing a function, which I am using in my testing with OAS -> fastAPI
Look like there should be some common component to be used "OAS->Fn" since "OAS->fastHTML" can be implemented on the top of "OAS->Fn". @nghivo94 Where can we take a look at the implementation? @linhktran Probably you can factor out some of the features from there?
Validate the automated conversion from OAS to Function Calling via OpenAI API
Task List
[x] Create Minimal OpenAPI Specification (OAS)
/hello
endpoint.name
query parameter and return a JSON greeting message.[x] Implement Simple Web Server
/hello
endpoint to handle thename
parameter and return a dynamic greeting message.[x] Run and Test Web Server
main.py
).uvicorn
, ensuring it serves athttp://127.0.0.1:8000
.http://127.0.0.1:8000/docs
.[x] Validate GPT-4O OAS Conversion
/hello
endpoint:name
parameter (should return a personalized greeting).[x] Document Results and Findings
[ ] #29
References
There are sample OAS & fastAPI code listed below.
https://chatgpt.com/share/6720630a-827c-8002-85f7-6f02eff3d382