# Is anyone developing a ChatGPT plugin that uses an SWI-Prolog server?

**URL:** <https://swi-prolog.discourse.group/t/is-anyone-developing-a-chatgpt-plugin-that-uses-an-swi-prolog-server/6556>\
**Category:** General\
**Tags:** chatgpt\
**Created:** [May 18, 2023, 11:24am UTC](https://swi-prolog.discourse.group/t/is-anyone-developing-a-chatgpt-plugin-that-uses-an-swi-prolog-server/6556 "2023-05-18T11:24:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [May 18, 2023, 11:24am UTC](https://swi-prolog.discourse.group/t/is-anyone-developing-a-chatgpt-plugin-that-uses-an-swi-prolog-server/6556/1 "2023-05-18T11:24:42Z")

</div>

Is anyone developing a ChatGPT plugin that uses an SWI-Prolog server?

* * *

Currently have TODO demo based on Python working using server on localhost. ([ref](https://github.com/openai/plugins-quickstart))  
Converted TODO demo based on Python (ChatGPT did conversation) to SWI-Prolog but had to work around lack of HTTP method `delete`. ([ref](https://swi-prolog.discourse.group/t/adding-delete-as-http-method-for-http-json-read-data/6555))

Having problems getting CORS to work so using TODO demo based on Python to see what is happening and recreate commands using cURL for testing with TODO demo based on SWI-Prolog.

* * *

Output when using TODO demo based on Python.

> **Click triangle to expand**
>
> ```plaintext
> C:\Users\Groot\plugins-quickstart-main>python main.py
> * Serving Quart app 'main'
> * Environment: production
> * Please use an ASGI server (e.g. Hypercorn) directly in production
> * Debug mode: True
> * Running on http://0.0.0.0:5003 (CTRL + C to quit)
> [2023-05-18 07:01:32 -0400] [15008] [INFO] Running on http://0.0.0.0:5003 (CTRL + C to quit)
> [2023-05-18 07:03:06 -0400] [15008] [INFO] 127.0.0.1:63017 OPTIONS /.well-known/ai-plugin.json 1.1 200 0 19001
> [2023-05-18 07:03:06 -0400] [15008] [INFO] 127.0.0.1:63017 GET /.well-known/ai-plugin.json 1.1 200 641 18982
> [2023-05-18 07:03:06 -0400] [15008] [INFO] 127.0.0.1:63017 OPTIONS /openapi.yaml 1.1 200 0 10976
> [2023-05-18 07:03:06 -0400] [15008] [INFO] 127.0.0.1:63017 GET /openapi.yaml 1.1 200 2337 17019
> [2023-05-18 07:03:07 -0400] [15008] [INFO] 127.0.0.1:63017 OPTIONS /logo.png 1.1 200 0 15002
> [2023-05-18 07:03:07 -0400] [15008] [INFO] 127.0.0.1:63025 GET /logo.png 1.1 200 1268 139032
> [2023-05-18 07:03:15 -0400] [15008] [INFO] 127.0.0.1:63029 OPTIONS /.well-known/ai-plugin.json 1.1 200 0 10003
> [2023-05-18 07:03:15 -0400] [15008] [INFO] 127.0.0.1:63029 GET /.well-known/ai-plugin.json 1.1 200 641 12006
> [2023-05-18 07:03:15 -0400] [15008] [INFO] 127.0.0.1:63029 OPTIONS /openapi.yaml 1.1 200 0 11006
> [2023-05-18 07:03:15 -0400] [15008] [INFO] 127.0.0.1:63029 GET /openapi.yaml 1.1 200 2337 9989
> [2023-05-18 07:03:37 -0400] [15008] [INFO] 127.0.0.1:63038 OPTIONS /.well-known/ai-plugin.json 1.1 200 0 9002
> [2023-05-18 07:03:37 -0400] [15008] [INFO] 127.0.0.1:63038 GET /.well-known/ai-plugin.json 1.1 200 641 12001
> [2023-05-18 07:03:37 -0400] [15008] [INFO] 127.0.0.1:63038 OPTIONS /openapi.yaml 1.1 200 0 10998
> [2023-05-18 07:03:37 -0400] [15008] [INFO] 127.0.0.1:63038 GET /openapi.yaml 1.1 200 2337 11988
> [2023-05-18 07:04:06 -0400] [15008] [INFO] 127.0.0.1:63046 OPTIONS /todos/user 1.1 200 0 9979
> [2023-05-18 07:04:06 -0400] [15008] [INFO] 127.0.0.1:63046 POST /todos/user 1.1 200 2 19988
> [2023-05-18 07:04:24 -0400] [15008] [INFO] 127.0.0.1:63052 OPTIONS /todos/user 1.1 200 0 10002
> [2023-05-18 07:04:24 -0400] [15008] [INFO] 127.0.0.1:63052 POST /todos/user 1.1 200 2 19999
> [2023-05-18 07:04:37 -0400] [15008] [INFO] 127.0.0.1:63056 OPTIONS /todos/user 1.1 200 0 11027
> [2023-05-18 07:04:37 -0400] [15008] [INFO] 127.0.0.1:63056 GET /todos/user 1.1 200 27 13002
> [2023-05-18 07:05:04 -0400] [15008] [INFO] 127.0.0.1:63060 OPTIONS /todos/user 1.1 200 0 11005
> [2023-05-18 07:05:04 -0400] [15008] [INFO] 127.0.0.1:63060 DELETE /todos/user 1.1 200 2 16987
> [2023-05-18 07:05:20 -0400] [15008] [INFO] 127.0.0.1:63066 OPTIONS /todos/user 1.1 200 0 10980
> [2023-05-18 07:05:20 -0400] [15008] [INFO] 127.0.0.1:63066 GET /todos/user 1.1 200 15 13015
> 
> ```

* * *

Recreation of ChatGPT HTTP request (cURL commands) to TODO server. Created these to test the SWI-Prolog TODO server independent of ChatGPT.

> **Click triangle to expand**
>
> ```plaintext
> C:\Users\Groot>curl -X OPTIONS "http://localhost:5003/.well-known/ai-plugin.json" -i
> HTTP/1.1 200
> allow: OPTIONS, HEAD, GET
> content-type: text/html; charset=utf-8
> content-length: 0
> date: Thu, 18 May 2023 11:45:09 GMT
> server: hypercorn-h11
> 
> ```
> 
> Server log
> 
> ```plaintext
> [2023-05-18 07:45:09 -0400] [15008] [INFO] 127.0.0.1:63214 OPTIONS /.well-known/ai-plugin.json 1.1 200 0 11011
> 
> ```
> 
> * * *
> 
> ```plaintext
> C:\Users\Groot>curl -X GET "http://localhost:5003/.well-known/ai-plugin.json"
> {
> "schema_version": "v1",
> "name_for_human": "TODO Plugin (no auth)",
> "name_for_model": "todo",
> "description_for_human": "Plugin for managing a TODO list, you can add, remove and view your TODOs.",
> "description_for_model": "Plugin for managing a TODO list, you can add, remove and view your TODOs.",
> "auth": {
> "type": "none"
> },
> "api": {
> "type": "openapi",
> "url": "http://localhost:5003/openapi.yaml",
> "is_user_authenticated": false
> },
> "logo_url": "http://localhost:5003/logo.png",
> "contact_email": "legal@example.com",
> "legal_info_url": "http://example.com/legal"
> }
> 
> ```
> 
> Server log
> 
> ```plaintext
> [2023-05-18 07:48:03 -0400] [15008] [INFO] 127.0.0.1:63218 GET /.well-known/ai-plugin.json 1.1 200 641 24988
> 
> ```
> 
> * * *
> 
> ```plaintext
> C:\Users\Groot>curl -X OPTIONS "http://localhost:5003/openapi.yaml" -i
> HTTP/1.1 200
> allow: OPTIONS, HEAD, GET
> content-type: text/html; charset=utf-8
> content-length: 0
> date: Thu, 18 May 2023 11:57:13 GMT
> server: hypercorn-h11
> 
> ```
> 
> Server log
> 
> ```plaintext
> [2023-05-18 07:57:13 -0400] [15008] [INFO] 127.0.0.1:63246 OPTIONS /openapi.yaml 1.1 200 0 9999
> 
> ```
> 
> * * *
> 
> ```plaintext
> C:\Users\Groot>curl -X GET "http://localhost:5003/openapi.yaml"
> openapi: 3.0.1
> info:
> title: TODO Plugin
> description: A plugin that allows the user to create and manage a TODO list using ChatGPT. If you do not know the user's username, ask them first before making queries to the plugin. Otherwise, use the username "global".
> version: 'v1'
> servers:
> - url: http://localhost:5003
> paths:
> /todos/{username}:
> get:
> operationId: getTodos
> summary: Get the list of todos
> parameters:
> - in: path
> name: username
> schema:
> type: string
> required: true
> description: The name of the user.
> responses:
> "200":
> description: OK
> content:
> application/json:
> schema:
> $ref: '#/components/schemas/getTodosResponse'
> post:
> operationId: addTodo
> summary: Add a todo to the list
> parameters:
> - in: path
> name: username
> schema:
> type: string
> required: true
> description: The name of the user.
> requestBody:
> required: true
> content:
> application/json:
> schema:
> $ref: '#/components/schemas/addTodoRequest'
> responses:
> "200":
> description: OK
> delete:
> operationId: deleteTodo
> summary: Delete a todo from the list
> parameters:
> - in: path
> name: username
> schema:
> type: string
> required: true
> description: The name of the user.
> requestBody:
> required: true
> content:
> application/json:
> schema:
> $ref: '#/components/schemas/deleteTodoRequest'
> responses:
> "200":
> description: OK
> 
> components:
> schemas:
> getTodosResponse:
> type: object
> properties:
> todos:
> type: array
> items:
> type: string
> description: The list of todos.
> addTodoRequest:
> type: object
> required:
> - todo
> properties:
> todo:
> type: string
> description: The todo to add to the list.
> required: true
> deleteTodoRequest:
> type: object
> required:
> - todo_idx
> properties:
> todo_idx:
> type: integer
> description: The index of the todo to delete.
> required: true
> 
> ```
> 
> Server log
> 
> ```plaintext
> [2023-05-18 07:59:22 -0400] [15008] [INFO] 127.0.0.1:63250 GET /openapi.yaml 1.1 200 2337 19989
> 
> ```
> 
> * * *
> 
> ```plaintext
> C:\Users\Groot>curl -X OPTIONS "http://localhost:5003/logo.png" -i
> HTTP/1.1 200
> allow: OPTIONS, HEAD, GET
> content-type: text/html; charset=utf-8
> content-length: 0
> date: Thu, 18 May 2023 12:07:48 GMT
> server: hypercorn-h11
> 
> ```
> 
> Server log
> 
> ```plaintext
> [2023-05-18 08:07:48 -0400] [15008] [INFO] 127.0.0.1:63273 OPTIONS /logo.png 1.1 200 0 11997
> 
> ```
> 
> * * *
> 
> ```plaintext
> C:\Users\Groot>curl -X GET "http://localhost:5003/logo.png"
> Warning: Binary output can mess up your terminal. Use "--output -" to tell
> Warning: curl to output it to your terminal anyway, or consider "--output
> Warning: <FILE>" to save to a file.
> 
> ```
> 
> Server log
> 
> ```plaintext
> [2023-05-18 08:10:47 -0400] [15008] [INFO] 127.0.0.1:63281 GET /logo.png 1.1 200 1268 35994
> 
> ```
> 
> * * *
> 
> ```plaintext
> C:\Users\Groot>curl -X OPTIONS "http://localhost:5003/todos/user" -i
> HTTP/1.1 200
> allow: DELETE, OPTIONS, HEAD, POST, GET
> content-type: text/html; charset=utf-8
> content-length: 0
> date: Thu, 18 May 2023 12:12:24 GMT
> server: hypercorn-h11
> 
> ```
> 
> Server log
> 
> ```plaintext
> [2023-05-18 08:12:24 -0400] [15008] [INFO] 127.0.0.1:63287 OPTIONS /todos/user 1.1 200 0 9999
> 
> ```
> 
> * * *
> 
> ```plaintext
> C:\Users\Groot>curl -X POST -H "Content-Type: application/json" -d "{\"todo\":\"Send flowers\"}" http://localhost:5003/todos/user?username=john
> OK
> 
> ```
> 
> Server log
> 
> ```plaintext
> [2023-05-18 08:30:42 -0400] [15008] [INFO] 127.0.0.1:63351 POST /todos/user 1.1 200 2 13999
> 
> ```
> 
> * * *
> 
> ```plaintext
> C:\Users\Groot>curl -X GET http://localhost:5003/todos/user?username=john
> ["Buy flowers", "Send flowers"]
> 
> ```
> 
> Server log
> 
> ```plaintext
> [2023-05-18 08:32:28 -0400] [15008] [INFO] 127.0.0.1:63356 GET /todos/user 1.1 200 31 11022
> 
> ```
> 
> * * *
> 
> ```plaintext
> C:\Users\Groot>curl -X DELETE -H "Content-Type: application/json" -d "{\"todo_idx\":1}" http://localhost:5003/todos/user?username=johnn
> OK
> 
> ```
> 
> Server log
> 
> ```plaintext
> [2023-05-18 08:35:30 -0400] [15008] [INFO] 127.0.0.1:63361 DELETE /todos/user 1.1 200 2 14014
> 
> ```

* * *

May 19,2023

Since the [OpenAI](https://openai.com/) [TODO](https://github.com/openai/plugins-quickstart) API spec ([openapi.yml](https://github.com/openai/plugins-quickstart/blob/main/openapi.yaml)) is an [OpenAPI](https://www.openapis.org/) (not to be confused with OpenAI) and Jan W. created a SWI-Prolog repository some years ago for [OpenAPI](https://github.com/JanWielemaker/openapi) will give it a try.

One really nice feature, cross my fingers, is that given an `spec.yaml` file this can generate the code for an SWI-Prolog HTTP server, e.g. `swi-openapi --server=server.pl spec.yaml` ([ref](https://github.com/JanWielemaker/openapi#using-this-package)).

* * *

May 20, 2023

The SWI-Prolog OpenAPI code ([ref](https://github.com/JanWielemaker/openapi)) was created for Linux and as I use Windows ran into a problem with [library(uri)](https://www.swi-prolog.org/pldoc/man?section=uri) not working as expected with Windows. The specific problem AFAIK is that uri\_components/2 is converting  
`'file:///c%3A/users/Groot/projects/swi-prolog%20openapi/examples/petstore/petstore.yaml#/components/schemas/Pets'` into

```prolog
uri_components(file,'','/c%3A/users/Groot/projects/swi-prolog%20openapi/examples/petstore/petstore.yaml',A,'/components/schemas/Pets')

```

with the `Path` component being invalid on Windows, e.g. starts with `/`. Not even sure if there is more problems after that but stopped at that point.

* * *

June 2, 2023

 ![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/7/7dfd46960233c5ed80564e209b3b5756c97e8cff.png)

![image](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/1/1b9e9c7943f7cf8951ee13ee7373bbc5dcfa73d3.png)  
Slowly making progress.

* * *

> **Personal Notes**
>
> Parking some notes here so that they are easier for me to find in the future.
> 
> [Try Gorilla: A Large Language Model Connected with Massive APIs](https://medium.com/@dan.avila7/try-gorilla-a-large-language-model-connected-with-massive-apis-442f3b554ffb) ([pdf](https://arxiv.org/pdf/2305.15334.pdf))  
> I have had varying success with including just the function/method header, (think \*.h line), in the prompt but Gorilla also made use of the documentation for the function/method in the search.  
> While Gorilla looks interesting as is often the case with Prolog and LLMs, the quantity and quality of the data in the training set or document store is often so small that hallucinations tend to be the norm rather than the exception.  
> One thought on my todo list but very low is to try a modified variation of [type inference](https://en.wikipedia.org/wiki/Type_inference) to identify which predicates can be used to fill the hole. Yes it will be all holes at the start but having some sort of filter up front is faster than just brute force.
> 
> * * *
> 
> CodeCompose: A Large-Scale Industrial Deployment of AI-assisted Code Authoring ([pdf](https://arxiv.org/pdf/2305.12050.pdf))
> 
> How Program History Can Improve Code Completion ([pdf](https://www.inf.usi.ch/faculty/lanza/Downloads/Robb2008b.pdf))  
> ML-Enhanced Code Completion Improves Developer Productivity ([blog entry](https://ai.googleblog.com/2022/07/ml-enhanced-code-completion-improves.html))

---

<div class="post-metadata">

**Author:** ![BoxingDay](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@BoxingDay](https://swi-prolog.discourse.group/u/BoxingDay)\
**Post date:** [May 19, 2023, 12:30am UTC](https://swi-prolog.discourse.group/t/is-anyone-developing-a-chatgpt-plugin-that-uses-an-swi-prolog-server/6556/2 "2023-05-19T00:30:00Z")

</div>

Unrelated note - I read your [glossary](https://swi-prolog.discourse.group/t/chatgpt-prompts-prolog-basics/6257), great work. I have a simple correction - Byrd Box was created by a man named Lawrence Byrd not Rodney Byrd.
