-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from omar-araboghli/main
Initialting SmartChat API Reference and deprecating the demo.
- Loading branch information
Showing
18 changed files
with
325 additions
and
728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ note.txt | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# IDEA | ||
.idea |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--- | ||
sidebar_position: 7 | ||
id: eRAG API Reference | ||
title: API Reference | ||
tags: | ||
- Getting started | ||
- RAG | ||
- API | ||
--- | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
## Introduction | ||
|
||
You can interact with the API via HTTP requests from any language through our API Gateway. Behind the gateway there are a set of [services](#services) that you will need to communicate with to achieve a certain task. To communicate with one service, you will need to add the **\<service_path\>** between the **\<base_url\>** and the endpoint **\<route\>** you're trying to hit. This means, requests are of the format **\<base_url/>/\<service_path\>/\<route\>**. | ||
|
||
E.g. **https://api-gateway.erag.prod.llmhub.t-systems.net/config-manager/redoc**, where: | ||
* **\<base_url\>**: **https://api-gateway.erag.prod.llmhub.t-systems.net** | ||
* **\<service_path\>**: **config-manager** | ||
* **\<route\>**: **redoc** | ||
|
||
## Registration | ||
|
||
For registration please contact the AIFS team via [email protected] | ||
|
||
## Authentication | ||
|
||
To authenticate you need to obtain a **Bearer Token** from the [authentication endpoint](https://api-gateway.erag.prod.llmhub.t-systems.net/redoc#tag/Auth/operation/get_user_token_api_v1_auth_user_post) and then set the **access_token** in the header of all your subsequent requests. | ||
|
||
### Example Authentication | ||
<Tabs> | ||
<TabItem value="cURL" label="cURL" default> | ||
``` | ||
# Authenticate via | ||
curl --location '<BASE_URL>/api/v1/auth/user' \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{ | ||
"username": "<USERNAME>", | ||
"password": "<PASSWORD>" | ||
}' | ||
|
||
# And then get chat sessions via | ||
curl --location '<BASE_URL>/chat-session-manager/api/v1/sessions/' \ | ||
--header 'Authorization: Bearer <ACCESS_TOKEN>' | ||
``` | ||
</TabItem> | ||
<TabItem value="py" label="Python" default> | ||
```py showLineNumbers | ||
import requests | ||
import json | ||
|
||
base_url = "<BASE_URL>" | ||
|
||
payload = json.dumps({ | ||
"username": "<USERNAME>", | ||
"password": "<PASSWORD>" | ||
}) | ||
headers = { | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
response = requests.post(f"{base_url}/api/v1/auth/user", headers=headers, data=payload) | ||
|
||
headers["Authorization"] = f"Bearer {response.json()['access_token']}" | ||
|
||
response = requests.get(f"{base_url}/chat-session-manager/api/v1/sessions/", headers=headers) | ||
|
||
print(response.json()) | ||
|
||
``` | ||
</TabItem> | ||
</Tabs> | ||
|
||
|
||
## Services | ||
|
||
| Name | \<service_path\> | Docs | Description | | ||
|:---:|:---:|:---:|:---:| | ||
| **API Gateway** | - | [link](https://api-gateway.erag.prod.llmhub.t-systems.net/redoc) | Entrypoint for authentication and all backend services. | | ||
| **Config Manager** | **config-manager** | [link](https://api-gateway.erag.prod.llmhub.t-systems.net/config-manager/redoc) | Management of Tenant and RAG Configurations. | | ||
| **User Manager** | **user-manager** | [link](https://api-gateway.erag.prod.llmhub.t-systems.net/user-manager/redoc) | Management of Users, Roles, and User-Groups. | | ||
| **File Manager** | **file-manager** | [link](https://api-gateway.erag.prod.llmhub.t-systems.net/file-manager/redoc) | Management of Files, File-Groups, Knowledge Bases (KBs) and File-Access-Management. | | ||
| **Ingest Master** | **ingest-master** | [link](https://api-gateway.erag.prod.llmhub.t-systems.net/ingest-master/redoc) | Orchestration of file ingestion tasks, based on the selected ingestion pipeline via the Config Manager. | | ||
| **Chat Session Manager** | **chat-session-manager** | [link](https://api-gateway.erag.prod.llmhub.t-systems.net/chat-session-manager/redoc) | Management of chat sessions, session configurations, session history, and messages feedback. | | ||
| **Query Pipelines** | **query-pipelines** | [link](https://api-gateway.erag.prod.llmhub.t-systems.net/query-pipelines/redoc) | Generation of chat responses based on the selected query pipeline via the Config Manager. | | ||
| **Web Extraction** | **web-extraction-api** | [link](https://api-gateway.erag.prod.llmhub.t-systems.net/web-extraction-api/redoc) | Web crawling with built-in file management and ingestion. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--- | ||
sidebar_position: 8 | ||
id: global_chat_guide | ||
title: How to Chat using the global KB? | ||
tags: | ||
- Demo | ||
- Getting started | ||
- RAG | ||
--- | ||
|
||
# How to Chat using the global KB? | ||
|
||
## 0. Prerequisites | ||
|
||
* **Credentials** to authenticate to a hosted SmartChat RAG API on **BASE_URL** with a user with a `CHAT_USER` role. | ||
* A **pre-configured** SmartChat RAG API server. | ||
|
||
## 1. Authenticate | ||
```py showLineNumbers | ||
import requests | ||
import json | ||
|
||
base_url = "<BASE_URL>" | ||
|
||
payload = json.dumps({ | ||
"username": "<USERNAME>", | ||
"password": "<PASSWORD>" | ||
}) | ||
headers = { | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
response = requests.post(f"{base_url}/api/v1/auth/user", headers=headers, data=payload) | ||
|
||
headers["Authorization"] = f"Bearer {response.json()['access_token']}" | ||
``` | ||
|
||
## 2. Obtain the default Chat Configuration | ||
```py showLineNumbers | ||
response = requests.get(f"{base_url}/config-manager/api/v1/user/configs", headers=headers ) | ||
|
||
configs = response.json() | ||
default_config = [config for config in configs if config["userGroupId"] == "default"][0] | ||
|
||
default_local_config_id = default_config["localKbConfigs"][0]["id"] | ||
allowed_llms = default_config["localKbConfigs"][0]["allowed_llms"] | ||
``` | ||
|
||
## 3. Create a global Chat Session | ||
```py showLineNumbers | ||
body = { | ||
"title": "Testing the SmartChat RAG API", | ||
"config": { | ||
"localConfigId": default_local_config_id, | ||
"globalContext": True, | ||
"chatModel": allowed_llms[0]["name"] | ||
} | ||
} | ||
response = requests.post(f"{base_url}/chat-session-manager/api/v1/sessions/", headers=headers, json=body) | ||
session_id = response.json()["sessionId"] | ||
``` | ||
|
||
## 4. Chat | ||
```py showLineNumbers | ||
body = { | ||
"sessionId": session_id, | ||
"userPrompt": "Can you summarize the context to me?" | ||
} | ||
response = requests.post(f"{base_url}/query-pipelines/api/v1/chat", headers=headers, json=body) | ||
|
||
print(response.json()) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
--- | ||
sidebar_position: 8 | ||
id: local_chat_guide | ||
title: How to Chat using the local KB? | ||
tags: | ||
- Demo | ||
- Getting started | ||
- RAG | ||
--- | ||
|
||
# How to Chat using the local KB? | ||
|
||
## 0. Prerequisites | ||
|
||
* **Credentials** to authenticate to a hosted SmartChat RAG API on **BASE_URL** with a user with a `CHAT_USER` role. | ||
* A **pre-configured** SmartChat RAG API server. | ||
* A **pdf file**. | ||
|
||
## 1. Authenticate | ||
```py showLineNumbers | ||
import requests | ||
import json | ||
|
||
base_url = "<BASE_URL>" | ||
|
||
payload = json.dumps({ | ||
"username": "<USERNAME>", | ||
"password": "<PASSWORD>" | ||
}) | ||
headers = { | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
response = requests.post(f"{base_url}/api/v1/auth/user", headers=headers, data=payload) | ||
|
||
headers["Authorization"] = f"Bearer {response.json()['access_token']}" | ||
``` | ||
|
||
## 2. Obtain the default Chat Configuration | ||
```py showLineNumbers | ||
response = requests.get(f"{base_url}/config-manager/api/v1/user/configs", headers=headers ) | ||
|
||
configs = response.json() | ||
default_config = [config for config in configs if config["userGroupId"] == "default"][0] | ||
|
||
default_local_config_id = default_config["localKbConfigs"][0]["id"] | ||
allowed_llms = default_config["localKbConfigs"][0]["allowed_llms"] | ||
``` | ||
|
||
## 3. Upload files | ||
```py showLineNumbers | ||
import time | ||
|
||
file_paths = [ | ||
"PATH_TO_FILE_1", | ||
"PATH_TO_FILE_2", | ||
] | ||
params = {"kb": "local"} | ||
files = [("files", open(file_path, "rb")) for file_path in file_paths] | ||
|
||
response = requests.post(f"{base_url}/file-manager/api/v1/files/", headers=headers, params=params, files=files) | ||
|
||
pending_files = response.json() | ||
pending_file_ids = [pending_file["fileId"] for pending_file in pending_files] | ||
|
||
# Poll the upload jobs | ||
while True: | ||
params = { | ||
"kb": "local", | ||
"fileIds": pending_file_ids | ||
} | ||
response = requests.get(f"{base_url}/file-manager/api/v1/files/", headers=headers, params=params) | ||
|
||
files = response.json() | ||
|
||
if all(file["status"] in ["uploaded", "duplicated"] for file in files): | ||
break | ||
|
||
if all(file["status"] in ["error", "file_too_large", "file_type_not_supported"] for file in files): | ||
raise Exception("couldn't upload files") | ||
|
||
time.sleep(2) | ||
|
||
uploaded_files = files | ||
``` | ||
|
||
## 4. Ingest files | ||
```py showLineNumbers | ||
|
||
for uploaded_file in uploaded_files: | ||
url = f"{base_url}/ingest-master/api/v1/task" | ||
metadata = { | ||
"file_id": uploaded_file["fileId"], | ||
"user_id": uploaded_file["userId"], | ||
"file_name": uploaded_file["fileName"], | ||
"file_uri": uploaded_file["fileUri"], # most important one. Retrieval doesn't work properly without it. | ||
} | ||
body = { | ||
"filePath": uploaded_file["fileUri"], | ||
"role": "user", | ||
"metadata": metadata, | ||
} | ||
|
||
response = requests.post(f"{base_url}/ingest-master/api/v1/task", headers=headers, json=body) | ||
|
||
# Poll the ingestion task | ||
while True: | ||
params = {"file_path": uploaded_file["fileUri"], "role": "user"} | ||
response = requests.post(f"{base_url}/ingest-master/api/v1/tasks/file", headers=headers, params=params) | ||
|
||
status = response.json()[-1]["status"] # for simplicity, only take the latest ingestion task | ||
|
||
if status == "ingested": | ||
break | ||
|
||
if status == "ingestion_failed": | ||
raise Exception("Couldn't ingest file") | ||
|
||
ingested_files = uploaded_files | ||
``` | ||
|
||
|
||
## 5. Create a local Chat Session | ||
```py showLineNumbers | ||
body = { | ||
"title": "Testing the SmartChat RAG API", | ||
"config": { | ||
"localConfigId": default_local_config_id, | ||
"globalContext": False, | ||
"activeFiles": [ingested_files["fileId"] for uploaded_file in uploaded_files] # you can also leave empty. In that case, all files in the local context will be used for retrieval. | ||
"chatModel": allowed_llms[0]["name"] | ||
} | ||
} | ||
response = requests.post(f"{base_url}/chat-session-manager/api/v1/sessions/", headers=headers, json=body) | ||
session_id = response.json()["sessionId"] | ||
``` | ||
|
||
## 6. Chat | ||
```py showLineNumbers | ||
body = { | ||
"sessionId": session_id, | ||
"userPrompt": "Can you summarize the context to me?" | ||
} | ||
response = requests.post(f"{base_url}/query-pipelines/api/v1/chat", headers=headers, json=body) | ||
|
||
print(response.json()) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"label": "SmartChat RAG API", | ||
"position": 6, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "Get started with the SmartChat RAG API" | ||
} | ||
} |
Oops, something went wrong.