Skip to content

Commit 94ba635

Browse files
committed
update with env
1 parent 264c7b3 commit 94ba635

File tree

1 file changed

+71
-23
lines changed

1 file changed

+71
-23
lines changed

docs/Integration-OpenAI-Plugin.md

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
**OpenAI plugins** are tools that extend the capabilities of ChatGPT by allowing it to access real-time data, perform actions, or connect with external services via APIs.
1+
**OpenAI plugins** are tools that extend the capabilities of ChatGPT by allowing it to access real-time data, perform actions, or connect with external services via APIs. .
22

33
Instead of being limited to its pre-trained knowledge, ChatGPT can use plugins to retrieve up-to-date information (like live weather, stock prices, or databases) or perform tasks (like booking a flight or running a query).
44

@@ -16,8 +16,7 @@ This is to explore:
1616

1717
A value prop might be summarized: *instantly expose legacy DBs to Natural Language, including critical business logic and security, to simplify user discovery and operation.*
1818

19-
 
20-
19+
<br>
2120

2221
## Status: Technology Exploration
2322

@@ -27,19 +26,18 @@ We welcome participation in this exploration. Please contact us via [discord](h
2726

2827
This exploration is changing rapidly. For updates, replace `integration/mcp` from [integration/msp](https://github.com/ApiLogicServer/ApiLogicServer-src/tree/main/api_logic_server_cli/prototypes/nw_no_cust/integration/openai_plugin)
2928

30-
&nbsp;
29+
<br>
3130

3231
## Nat Lang ALS Access using OpenAI Plugin
3332

34-
Tunnel to local host with ngrok
3533

3634
Requires tunnel to local host such as [ngrok](https://ngrok.com/downloads/mac-os?tab=download), then
3735

3836
```
3937
ngrok config add-authtoken <obtain from https://dashboard.ngrok.com/get-started/setup/macos>
4038
```
4139

42-
then
40+
then start the tunnel
4341
```
4442
ngrok http 5656
4543
```
@@ -48,46 +46,96 @@ You should see:
4846

4947
![ngrok](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/mcp/ngrok.png?raw=true)
5048

51-
and note the url like: `https://mcp_url_eg_bca3_2601.ngrok-free.app -> http://localhost:5656`
49+
and note the url like: `https://42da-2601-644-4900-etc.ngrok-free.app -> http://localhost:5656`
5250

5351
We'll call it `tunnel_url`
5452

55-
<br>
53+
Enter this into `config/default.env`
5654

57-
### Create ai_plug_in.json
55+
<br>
5856

59-
Prepare `ai_plug_in.json` as shown in this directory. It identifies the url for finding the openapi through the tunnel.
57+
### Obtain swagger_3
6058

61-
Note: both ALS and and `ai_plug_in.json` presume the swagger and api are consistent:
59+
Obtain swagger 2 from API Logic Server, eg, http://localhost:5656/api/swagger.json)
6260

63-
* swagger is at `http://localhost:5656/api/swagger.json`,
64-
* typical API at `http://localhost:5656/api/Category`
61+
Convert to 3: https://converter.swagger.io or other.
6562

6663
<br>
6764

68-
### Add APIs for openapi and openai_plugin
65+
#### Reduce Operations
6966

70-
OpenAI requires a openai document, so create a custom endpoint - `api/api_discovery/openapi.py` - for swagger 3:
71-
* swagger is at `http://localhost:5656/api/openai.json`
67+
Reduce down to 30 operations (genai_demo has 69).
7268

73-
Note: the url needs to be the tunnelled version.
69+
For testing, you can copy `integration/openai_plugin/swagger_3_genai_demo.json` or `integration/openai_plugin/nw-swagger_3.json` over `integration/openai_plugin/swagger_3.json`.
7470

75-
Fix servers in the `openai.json`
71+
This was obtained using ChatGPT with prompts like:
72+
73+
1. Optionally collapse GET by ID and GET collection into a single endpoint using query params
74+
2. remove POST from relationship endpoints
75+
3. remove delete
76+
4. collapse relationship endpoints further
77+
78+
then fix the result:
79+
80+
1. ensure servers and paths is retained (got deleted for me), and includes https:
81+
2. version 3.1.0
82+
83+
Still seeing (fix with Chat):
84+
85+
```
86+
In path /Customer, method get is missing operationId; skipping
87+
In path /Customer, method post is missing operationId; skipping
88+
In path /Order, method get is missing operationId; skipping
89+
In path /Order, method post is missing operationId; skipping
90+
In path /Item, method get is missing operationId; skipping
91+
In path /Item, method post is missing operationId; skipping
92+
In path /Product, method get is missing operationId; skipping
93+
In path /Product, method post is missing operationId; skipping
94+
```
7695

7796
<br>
97+
### Custom endpoint for openapi
98+
99+
OpenAI requires a openai document, so observe the custom endpoint - `api/api_discovery/openapi` - eg, to test locally: `http://localhost:5656/api/openai`
100+
101+
Note: the url for use in ChatGPT is the tunnelled version, from the env variable.
78102

103+
<br>
79104
### Configure in ChatGPT
80105

81-
ChatGPT -> Create > Configure > Add Action > url
106+
Then, upload it to the Web version of ChatGPT:
107+
108+
1. Explore GPTs
109+
2. Create
110+
3. Configure
111+
4. Create New Action
82112

83113
Provide the url of the openai endpoint:
84114

85115
https://tunnel_url.ngrok-free.app/api/openapi
86116

87-
which worked, but: **OpenAPI spec can have a maximum of 30 operations**, so, created a "pruned" version with just Customer: `integration/openai_plugin/nw-swagger_3.json`
88117

89-
fix openai version, url
118+
Retrieval worked:
119+
120+
* list customers
121+
122+
* list the items of order 1 with their product names
123+
124+
<br>
125+
126+
## Appendices
127+
128+
<br>
129+
130+
### Create ai_plug_in.json
131+
132+
Prepare `ai_plug_in.json` as shown in this directory. Observe that it It identifies the url for finding the openapi through the tunnel.
133+
134+
Note: both ALS and and `ai_plug_in.json` presume the swagger and api are consistent:
135+
136+
* swagger is at `http://localhost:5656/api/swagger.json`,
137+
* typical API at `http://localhost:5656/api/Category`
90138

91-
retrieval worked:
139+
Not required for function - **Settings / Beta / Plugins > Plugin install → expects the ai-plugin.json manifest URL**
92140

93-
![openai-plugin](https://github.com/ApiLogicServer/Docs/blob/main/docs/images/integration/openai-plugin/Nat%20Lang%20Query.png?raw=true)
141+
This appears to be unavailable for ChatGPT 4o

0 commit comments

Comments
 (0)