2023-10-17 06:58:50 +00:00
|
|
|
# API Endpoints Documentation
|
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
*Currently, the application provides the following main API endpoints:*
|
2023-09-07 11:36:39 +00:00
|
|
|
|
|
|
|
|
2023-10-17 02:58:13 +00:00
|
|
|
### 1. /api/answer
|
2023-10-16 15:05:17 +00:00
|
|
|
**Description:**
|
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
This endpoint is used to request answers to user-provided questions.
|
|
|
|
|
|
|
|
**Request:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-29 22:18:52 +00:00
|
|
|
**Method**: `POST`
|
|
|
|
|
|
|
|
**Headers**: Content-Type should be set to `application/json; charset=utf-8`
|
|
|
|
|
|
|
|
**Request Body**: JSON object with the following fields:
|
|
|
|
* `question` — The user's question.
|
|
|
|
* `history` — (Optional) Previous conversation history.
|
|
|
|
* `api_key`— Your API key.
|
|
|
|
* `embeddings_key` — Your embeddings key.
|
|
|
|
* `active_docs` — The location of active documentation.
|
2023-10-16 14:51:24 +00:00
|
|
|
|
|
|
|
Here is a JavaScript Fetch Request example:
|
2023-09-16 00:18:01 +00:00
|
|
|
```js
|
2023-09-07 11:36:39 +00:00
|
|
|
// answer (POST http://127.0.0.1:5000/api/answer)
|
|
|
|
fetch("http://127.0.0.1:5000/api/answer", {
|
|
|
|
"method": "POST",
|
|
|
|
"headers": {
|
|
|
|
"Content-Type": "application/json; charset=utf-8"
|
|
|
|
},
|
|
|
|
"body": JSON.stringify({"question":"Hi","history":null,"api_key":"OPENAI_API_KEY","embeddings_key":"OPENAI_API_KEY",
|
|
|
|
"active_docs": "javascript/.project/ES2015/openai_text-embedding-ada-002/"})
|
|
|
|
})
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then(console.log.bind(console))
|
|
|
|
```
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
**Response**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-29 22:18:52 +00:00
|
|
|
In response, you will get a JSON document containing the `answer`, `query` and `result`:
|
2023-09-16 00:18:01 +00:00
|
|
|
```json
|
2023-09-07 11:36:39 +00:00
|
|
|
{
|
2023-10-29 11:28:23 +00:00
|
|
|
"answer": "Hi there! How can I help you?\n",
|
2023-09-07 11:36:39 +00:00
|
|
|
"query": "Hi",
|
2023-10-29 11:28:23 +00:00
|
|
|
"result": "Hi there! How can I help you?\nSOURCES:"
|
2023-09-07 11:36:39 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2023-10-17 02:58:13 +00:00
|
|
|
### 2. /api/docs_check
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
**Description:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
This endpoint will make sure documentation is loaded on the server (just run it every time user is switching between libraries (documentations)).
|
2023-09-07 11:36:39 +00:00
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
**Request:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-31 12:59:09 +00:00
|
|
|
**Method**: `POST`
|
|
|
|
|
2023-10-29 22:18:52 +00:00
|
|
|
**Headers**: Content-Type should be set to `application/json; charset=utf-8`
|
|
|
|
|
|
|
|
**Request Body**: JSON object with the field:
|
|
|
|
* `docs` — The location of the documentation:
|
2023-09-16 00:18:01 +00:00
|
|
|
```js
|
2023-11-21 15:15:27 +00:00
|
|
|
// docs_check (POST http://127.0.0.1:5000/api/docs_check)
|
2023-09-07 11:36:39 +00:00
|
|
|
fetch("http://127.0.0.1:5000/api/docs_check", {
|
|
|
|
"method": "POST",
|
|
|
|
"headers": {
|
|
|
|
"Content-Type": "application/json; charset=utf-8"
|
|
|
|
},
|
|
|
|
"body": JSON.stringify({"docs":"javascript/.project/ES2015/openai_text-embedding-ada-002/"})
|
|
|
|
})
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then(console.log.bind(console))
|
|
|
|
```
|
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
**Response:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-29 22:18:52 +00:00
|
|
|
In response, you will get a JSON document like this one indicating whether the documentation exists or not:
|
2023-09-16 00:18:01 +00:00
|
|
|
```json
|
2023-09-07 11:36:39 +00:00
|
|
|
{
|
|
|
|
"status": "exists"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2023-10-17 02:58:13 +00:00
|
|
|
### 3. /api/combine
|
2023-10-16 14:51:24 +00:00
|
|
|
**Description:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
This endpoint provides information about available vectors and their locations with a simple GET request.
|
|
|
|
|
|
|
|
**Request:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-29 22:18:52 +00:00
|
|
|
**Method**: `GET`
|
2023-09-07 11:36:39 +00:00
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
**Response:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-05 17:27:48 +00:00
|
|
|
Response will include:
|
2023-10-29 22:18:52 +00:00
|
|
|
* `date`
|
|
|
|
* `description`
|
|
|
|
* `docLink`
|
|
|
|
* `fullName`
|
|
|
|
* `language`
|
|
|
|
* `location` (local or docshub)
|
|
|
|
* `model`
|
|
|
|
* `name`
|
|
|
|
* `version`
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-08 16:29:27 +00:00
|
|
|
Example of JSON in Docshub and local:
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-09-07 11:36:39 +00:00
|
|
|
<img width="295" alt="image" src="https://user-images.githubusercontent.com/15183589/224714085-f09f51a4-7a9a-4efb-bd39-798029bb4273.png">
|
|
|
|
|
2023-10-17 06:57:38 +00:00
|
|
|
### 4. /api/upload
|
2023-10-16 14:51:24 +00:00
|
|
|
**Description:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
This endpoint is used to upload a file that needs to be trained, response is JSON with task ID, which can be used to check on task's progress.
|
|
|
|
|
|
|
|
**Request:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-29 22:18:52 +00:00
|
|
|
**Method**: `POST`
|
2023-10-31 09:45:23 +00:00
|
|
|
|
2023-10-29 22:18:52 +00:00
|
|
|
**Request Body**: A multipart/form-data form with file upload and additional fields, including `user` and `name`.
|
2023-10-16 14:51:24 +00:00
|
|
|
|
2023-09-07 11:36:39 +00:00
|
|
|
HTML example:
|
|
|
|
|
2023-09-16 00:18:01 +00:00
|
|
|
```html
|
2023-09-07 11:36:39 +00:00
|
|
|
<form action="/api/upload" method="post" enctype="multipart/form-data" class="mt-2">
|
2023-10-05 17:27:48 +00:00
|
|
|
<input type="file" name="file" class="py-4" id="file-upload">
|
|
|
|
<input type="text" name="user" value="local" hidden>
|
|
|
|
<input type="text" name="name" placeholder="Name:">
|
|
|
|
|
2023-10-07 15:12:32 +00:00
|
|
|
<button type="submit" class="py-2 px-4 text-white bg-purple-30 rounded-md hover:bg-purple-30 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-purple-30">
|
2023-10-05 17:27:48 +00:00
|
|
|
Upload
|
|
|
|
</button>
|
|
|
|
</form>
|
2023-09-07 11:36:39 +00:00
|
|
|
```
|
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
**Response:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-16 14:57:09 +00:00
|
|
|
JSON response with a status and a task ID that can be used to check the task's progress.
|
2023-09-07 11:36:39 +00:00
|
|
|
|
|
|
|
|
2023-10-17 06:57:38 +00:00
|
|
|
### 5. /api/task_status
|
2023-10-16 14:51:24 +00:00
|
|
|
**Description:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
This endpoint is used to get the status of a task (`task_id`) from `/api/upload`
|
|
|
|
|
|
|
|
**Request:**
|
2023-10-31 09:45:23 +00:00
|
|
|
|
|
|
|
**Method**: `GET`
|
|
|
|
|
2023-10-29 22:18:52 +00:00
|
|
|
**Query Parameter**: `task_id` (task ID to check)
|
2023-10-16 14:51:24 +00:00
|
|
|
|
|
|
|
**Sample JavaScript Fetch Request:**
|
2023-09-16 00:18:01 +00:00
|
|
|
```js
|
2023-10-09 12:15:50 +00:00
|
|
|
// Task status (Get http://127.0.0.1:5000/api/task_status)
|
2023-10-16 14:51:24 +00:00
|
|
|
fetch("http://localhost:5001/api/task_status?task_id=YOUR_TASK_ID", {
|
2023-09-07 11:36:39 +00:00
|
|
|
"method": "GET",
|
|
|
|
"headers": {
|
|
|
|
"Content-Type": "application/json; charset=utf-8"
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then(console.log.bind(console))
|
|
|
|
```
|
|
|
|
|
2023-10-16 14:57:09 +00:00
|
|
|
**Response:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-01 15:25:23 +00:00
|
|
|
There are two types of responses:
|
2023-10-14 18:52:25 +00:00
|
|
|
|
2023-10-08 12:32:54 +00:00
|
|
|
1. While the task is still running, the 'current' value will show progress from 0 to 100.
|
2023-10-29 22:18:52 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"result": {
|
|
|
|
"current": 1
|
|
|
|
},
|
|
|
|
"status": "PROGRESS"
|
|
|
|
}
|
|
|
|
```
|
2023-09-07 11:36:39 +00:00
|
|
|
|
2023-10-09 12:25:41 +00:00
|
|
|
2. When task is completed:
|
2023-10-29 22:18:52 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"result": {
|
|
|
|
"directory": "temp",
|
|
|
|
"filename": "install.rst",
|
|
|
|
"formats": [
|
|
|
|
".rst",
|
|
|
|
".md",
|
|
|
|
".pdf"
|
|
|
|
],
|
|
|
|
"name_job": "somename",
|
|
|
|
"user": "local"
|
|
|
|
},
|
|
|
|
"status": "SUCCESS"
|
|
|
|
}
|
|
|
|
```
|
2023-09-07 11:36:39 +00:00
|
|
|
|
2023-10-17 06:57:38 +00:00
|
|
|
### 6. /api/delete_old
|
2023-10-16 14:51:24 +00:00
|
|
|
**Description:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
This endpoint is used to delete old Vector Stores.
|
2023-10-08 12:32:54 +00:00
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
**Request:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-29 22:18:52 +00:00
|
|
|
**Method**: `GET`
|
|
|
|
|
2023-11-21 15:15:27 +00:00
|
|
|
**Query Parameter**: `task_id`
|
|
|
|
|
|
|
|
**Sample JavaScript Fetch Request:**
|
2023-09-16 00:18:01 +00:00
|
|
|
```js
|
2023-11-21 15:15:27 +00:00
|
|
|
// delete_old (GET http://127.0.0.1:5000/api/delete_old)
|
|
|
|
fetch("http://localhost:5001/api/delete_old?task_id=YOUR_TASK_ID", {
|
2023-09-07 11:36:39 +00:00
|
|
|
"method": "GET",
|
|
|
|
"headers": {
|
|
|
|
"Content-Type": "application/json; charset=utf-8"
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then(console.log.bind(console))
|
2023-10-05 17:27:48 +00:00
|
|
|
|
2023-10-16 14:51:24 +00:00
|
|
|
```
|
|
|
|
**Response:**
|
2023-10-16 15:05:17 +00:00
|
|
|
|
2023-10-29 22:18:52 +00:00
|
|
|
JSON response indicating the status of the operation:
|
|
|
|
|
2023-09-16 00:18:01 +00:00
|
|
|
```json
|
|
|
|
{ "status": "ok" }
|
2023-09-07 11:36:39 +00:00
|
|
|
```
|
2024-04-01 17:07:27 +00:00
|
|
|
|
|
|
|
### 7. /api/get_api_keys
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
The endpoint retrieves a list of API keys for the user.
|
|
|
|
|
|
|
|
**Request:**
|
|
|
|
|
|
|
|
**Method**: `GET`
|
|
|
|
|
|
|
|
**Sample JavaScript Fetch Request:**
|
|
|
|
```js
|
|
|
|
// get_api_keys (GET http://127.0.0.1:5000/api/get_api_keys)
|
|
|
|
fetch("http://localhost:5001/api/get_api_keys", {
|
|
|
|
"method": "GET",
|
|
|
|
"headers": {
|
|
|
|
"Content-Type": "application/json; charset=utf-8"
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then((res) => res.text())
|
|
|
|
.then(console.log.bind(console))
|
|
|
|
|
|
|
|
```
|
|
|
|
**Response:**
|
|
|
|
|
|
|
|
JSON response with a list of created API keys:
|
|
|
|
|
|
|
|
```json
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"id": "string",
|
|
|
|
"name": "string",
|
|
|
|
"key": "string",
|
|
|
|
"source": "string"
|
|
|
|
},
|
|
|
|
...
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
### 8. /api/create_api_key
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
Create a new API key for the user.
|
|
|
|
|
|
|
|
**Request:**
|
|
|
|
|
|
|
|
**Method**: `POST`
|
|
|
|
|
|
|
|
**Headers**: Content-Type should be set to `application/json; charset=utf-8`
|
|
|
|
|
|
|
|
**Request Body**: JSON object with the following fields:
|
|
|
|
* `name` — A name for the API key.
|
|
|
|
* `source` — The source documents that will be used.
|
2024-04-08 09:35:15 +00:00
|
|
|
* `prompt_id` — The prompt ID.
|
|
|
|
* `chunks` — The number of chunks used to process an answer.
|
2024-04-01 17:07:27 +00:00
|
|
|
|
|
|
|
Here is a JavaScript Fetch Request example:
|
|
|
|
```js
|
|
|
|
// create_api_key (POST http://127.0.0.1:5000/api/create_api_key)
|
|
|
|
fetch("http://127.0.0.1:5000/api/create_api_key", {
|
|
|
|
"method": "POST",
|
|
|
|
"headers": {
|
|
|
|
"Content-Type": "application/json; charset=utf-8"
|
|
|
|
},
|
2024-04-08 09:35:15 +00:00
|
|
|
"body": JSON.stringify({"name":"Example Key Name",
|
|
|
|
"source":"Example Source",
|
|
|
|
"prompt_id":"creative",
|
|
|
|
"chunks":"2"})
|
2024-04-01 17:07:27 +00:00
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then(console.log.bind(console))
|
|
|
|
```
|
|
|
|
|
|
|
|
**Response**
|
|
|
|
|
|
|
|
In response, you will get a JSON document containing the `id` and `key`:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"id": "string",
|
|
|
|
"key": "string"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### 9. /api/delete_api_key
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
Delete an API key for the user.
|
|
|
|
|
|
|
|
**Request:**
|
|
|
|
|
|
|
|
**Method**: `POST`
|
|
|
|
|
|
|
|
**Headers**: Content-Type should be set to `application/json; charset=utf-8`
|
|
|
|
|
|
|
|
**Request Body**: JSON object with the field:
|
|
|
|
* `id` — The unique identifier of the API key to be deleted.
|
|
|
|
|
|
|
|
Here is a JavaScript Fetch Request example:
|
|
|
|
```js
|
|
|
|
// delete_api_key (POST http://127.0.0.1:5000/api/delete_api_key)
|
|
|
|
fetch("http://127.0.0.1:5000/api/delete_api_key", {
|
|
|
|
"method": "POST",
|
|
|
|
"headers": {
|
|
|
|
"Content-Type": "application/json; charset=utf-8"
|
|
|
|
},
|
|
|
|
"body": JSON.stringify({"id":"API_KEY_ID"})
|
|
|
|
})
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then(console.log.bind(console))
|
|
|
|
```
|
|
|
|
|
|
|
|
**Response:**
|
|
|
|
|
|
|
|
In response, you will get a JSON document indicating the status of the operation:
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"status": "ok"
|
|
|
|
}
|
|
|
|
```
|