You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DocsGPT/docs/pages/Developing/API-docs.md

227 lines
5.3 KiB
Markdown

12 months ago
# API Endpoints Documentation
*Currently, the application provides the following main API endpoints:*
1 year ago
12 months ago
### 1. /api/answer
12 months ago
**Description:**
This endpoint is used to request answers to user-provided questions.
**Request:**
12 months ago
11 months ago
**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.
Here is a JavaScript Fetch Request example:
```js
1 year ago
// 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))
```
12 months ago
**Response**
12 months ago
11 months ago
In response, you will get a JSON document containing the `answer`, `query` and `result`:
```json
1 year ago
{
11 months ago
"answer": "Hi there! How can I help you?\n",
1 year ago
"query": "Hi",
11 months ago
"result": "Hi there! How can I help you?\nSOURCES:"
1 year ago
}
```
12 months ago
### 2. /api/docs_check
12 months ago
**Description:**
12 months ago
This endpoint will make sure documentation is loaded on the server (just run it every time user is switching between libraries (documentations)).
1 year ago
**Request:**
12 months ago
**Method**: `POST`
11 months ago
**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:
```js
1 year ago
// answer (POST http://127.0.0.1:5000/api/docs_check)
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))
```
**Response:**
12 months ago
11 months ago
In response, you will get a JSON document like this one indicating whether the documentation exists or not:
```json
1 year ago
{
"status": "exists"
}
```
12 months ago
### 3. /api/combine
**Description:**
12 months ago
This endpoint provides information about available vectors and their locations with a simple GET request.
**Request:**
12 months ago
11 months ago
**Method**: `GET`
1 year ago
**Response:**
12 months ago
Response will include:
11 months ago
* `date`
* `description`
* `docLink`
* `fullName`
* `language`
* `location` (local or docshub)
* `model`
* `name`
* `version`
12 months ago
12 months ago
Example of JSON in Docshub and local:
12 months ago
1 year ago
<img width="295" alt="image" src="https://user-images.githubusercontent.com/15183589/224714085-f09f51a4-7a9a-4efb-bd39-798029bb4273.png">
12 months ago
### 4. /api/upload
**Description:**
12 months ago
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:**
12 months ago
11 months ago
**Method**: `POST`
11 months ago
**Request Body**: A multipart/form-data form with file upload and additional fields, including `user` and `name`.
1 year ago
HTML example:
```html
1 year ago
<form action="/api/upload" method="post" enctype="multipart/form-data" class="mt-2">
<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:">
<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">
Upload
</button>
</form>
1 year ago
```
**Response:**
12 months ago
12 months ago
JSON response with a status and a task ID that can be used to check the task's progress.
1 year ago
12 months ago
### 5. /api/task_status
**Description:**
12 months ago
This endpoint is used to get the status of a task (`task_id`) from `/api/upload`
**Request:**
**Method**: `GET`
11 months ago
**Query Parameter**: `task_id` (task ID to check)
**Sample JavaScript Fetch Request:**
```js
12 months ago
// Task status (Get http://127.0.0.1:5000/api/task_status)
fetch("http://localhost:5001/api/task_status?task_id=YOUR_TASK_ID", {
1 year ago
"method": "GET",
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
})
.then((res) => res.text())
.then(console.log.bind(console))
```
12 months ago
**Response:**
12 months ago
1 year ago
There are two types of responses:
1. While the task is still running, the 'current' value will show progress from 0 to 100.
11 months ago
```json
{
"result": {
"current": 1
},
"status": "PROGRESS"
}
```
1 year ago
12 months ago
2. When task is completed:
11 months ago
```json
{
"result": {
"directory": "temp",
"filename": "install.rst",
"formats": [
".rst",
".md",
".pdf"
],
"name_job": "somename",
"user": "local"
},
"status": "SUCCESS"
}
```
1 year ago
12 months ago
### 6. /api/delete_old
**Description:**
12 months ago
This endpoint is used to delete old Vector Stores.
**Request:**
12 months ago
11 months ago
**Method**: `GET`
```js
1 year ago
// Task status (GET http://127.0.0.1:5000/api/docs_check)
fetch("http://localhost:5001/api/task_status?task_id=b2d2a0f4-387c-44fd-a443-e4fe2e7454d1", {
"method": "GET",
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
})
.then((res) => res.text())
.then(console.log.bind(console))
```
**Response:**
12 months ago
11 months ago
JSON response indicating the status of the operation:
```json
{ "status": "ok" }
1 year ago
```