Initial commit

This commit is contained in:
John Wang
2023-05-15 08:51:32 +08:00
commit db896255d6
744 changed files with 56028 additions and 0 deletions

View File

@@ -0,0 +1,206 @@
import { CodeGroup } from '../code.tsx'
import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from '../md.tsx'
# Completion App API
For high-quality text generation, such as articles, summaries, and translations, use the completion-messages API with user input. Text generation relies on the model parameters and prompt templates set in LangGenius Prompt Engineering.
<Heading
url='/completion-messages'
method='POST'
title='Create Completion Message'
name='#Create-Completion-Message'
/>
<Row>
<Col>
Create a Completion Message to support the question-and-answer mode.
### Request Body
<Properties>
<Property name='inputs' type='object' key='inputs'>
(Optional) Provide user input fields as key-value pairs, corresponding to variables in Prompt Eng. Key is the variable name, Value is the parameter value. If the field type is Select, the submitted Value must be one of the preset choices.
<ul>
{!!props.variables.length && props.variables.map(
val => (
<SubProperty name={val.key} type={val.type} key={val.key}>
{val.name ? `${val.name}` : ''}
</SubProperty>
)
)}
</ul>
</Property>
<Property name='query' type='string' key='query'>
User input text content.
</Property>
<Property name='response_mode' type='string' key='response_mode'>
- Blocking type, waiting for execution to complete and returning results. (Requests may be interrupted if the process is long)
- streaming returns. Implementation of streaming return based on SSE (**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**).
</Property>
<Property name='user' type='string' key='user'>
The user identifier, defined by the developer, must ensure uniqueness within the app.
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/completion-messages" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/completion-messages' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "inputs": ${JSON.stringify(props.inputs)},\n "query": "Hi",\n "response_mode": "streaming"\n "user": "abc-123"\n}'\n`}>
```bash {{ title: 'cURL' }}
curl --location --request POST 'https://cloud.langgenius.dev/api/completion-messages' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"inputs": {},
"query": "Hi",
"response_mode": "streaming",
"user": "abc-123"
}'
```
</CodeGroup>
### blocking
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"id": "0b089b9a-24d9-48cc-94f8-762677276261",
"answer": "how are you?",
"created_at": 1679586667
}
```
</CodeGroup>
### streaming
<CodeGroup title="Response">
```streaming {{ title: 'Response' }}
data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/messages/{message_id}/feedbacks'
method='POST'
title='Message feedback (like)'
name='#feedbacks'
/>
<Row>
<Col>
Rate received messages on behalf of end-users with likes or dislikes. This data is visible in the Logs & Annotations page and used for future model fine-tuning.
### Path Params
<Properties>
<Property name='message_id' type='string' key='message_id'>
Message ID
</Property>
</Properties>
### Request Body
<Properties>
<Property name='rating' type='string' key='rating'>
like or dislike, null is undo
</Property>
<Property name='user' type='string' key='user'>
The user identifier, defined by the developer, must ensure uniqueness within the app.
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/messages/{message_id}/feedbacks" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/messages/{message_id}/feedbacks \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n --data-raw '{ \n "rating": "like",\n "user": "abc-123"\n}'`}>
```bash {{ title: 'cURL' }}
curl --location --request POST 'https://cloud.langgenius.dev/api/messages/{message_id}/feedbacks' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"rating": "like",
"user": "abc-123"
}'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"has_more": false,
"data": [
{
"id": "WAz8eIbvDR60rouK",
"username": "FrankMcCallister",
"phone_number": "1-800-759-3000",
"avatar_url": "https://assets.protocol.chat/avatars/frank.jpg",
"display_name": null,
"conversation_id": "xgQQXg3hrtjh7AvZ",
"last_active_at": 705103200,
"created_at": 692233200
},
{
"id": "hSIhXBhNe8X1d8Et"
// ...
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/parameters'
method='GET'
title='Obtain application parameter information'
name='#parameters'
/>
<Row>
<Col>
Retrieve configured Input parameters, including variable names, field names, types, and default values. Typically used for displaying these fields in a form or filling in default values after the client loads.
### Query
<Properties>
<Property name='user' type='string' key='user'>
The user identifier, defined by the developer, must ensure uniqueness within the app.
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/parameters" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'`}>
```bash {{ title: 'cURL' }}
curl --location --request GET 'https://cloud.langgenius.dev/api/parameters?user=abc-123' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"introduction": "nice to meet you",
"variables": [
{
"key": "book",
"name": "Which book?",
"description": null,
"type": "string",
"default": null,
"options": null
},
{
// ...
]
}
```
</CodeGroup>
</Col>
</Row>

View File

@@ -0,0 +1,206 @@
import { CodeGroup } from '../code.tsx'
import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
# 文本生成型应用 API
可用于生成高质量文本的应用,例如生成文章、摘要、翻译等,通过调用 completion-messages 接口,发送用户输入得到生成文本结果。用于生成文本的模型参数和提示词模版取决于开发者在 LangGenius 提示词编排页的设置。
<Heading
url='/completion-messages'
method='POST'
title='创建文本补全消息'
name='#Create-Completion-Message'
/>
<Row>
<Col>
创建文本补全消息,支持一问一答模式。
### Request Body
<Properties>
<Property name='inputs' type='object' key='inputs'>
选填以键值对方式提供用户输入字段与提示词编排中的变量对应。Key 为变量名称Value 是参数值。如果字段类型为 Select传入的 Value 需为预设选项之一。
<ul>
{!!props.variables.length && props.variables.map(
val => (
<SubProperty name={val.key} type={val.type} key={val.key}>
{val.name ? `${val.name}` : ''}
</SubProperty>
)
)}
</ul>
</Property>
<Property name='query' type='string' key='query'>
用户输入的文本正文。
</Property>
<Property name='response_mode' type='string' key='response_mode'>
- blocking 阻塞型,等待执行完毕后返回结果。(请求若流程较长可能会被中断)
- streaming 流式返回。基于 SSE**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)实现流式返回。
</Property>
<Property name='user' type='string' key='user'>
用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/completion-messages" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/completion-messages' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "inputs": ${JSON.stringify(props.inputs)},\n "query": "Hi",\n "response_mode": "streaming",\n "user": "abc-123"\n}'\n`}>
```bash {{ title: 'cURL' }}
curl --location --request POST 'https://cloud.langgenius.dev/api/completion-messages' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"inputs": {},
"query": "Hi",
"response_mode": "streaming",
"user": "abc-123"
}'
```
</CodeGroup>
### blocking
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"id": "0b089b9a-24d9-48cc-94f8-762677276261",
"answer": "how are you?",
"created_at": 1679586667
}
```
</CodeGroup>
### streaming
<CodeGroup title="Response">
```streaming {{ title: 'Response' }}
data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/messages/{message_id}/feedbacks'
method='POST'
title='消息反馈(点赞)'
name='#feedbacks'
/>
<Row>
<Col>
代表最终用户对返回消息进行评价,可以点赞与点踩,该数据将在“日志与标注”页中可见,并用于后续的模型微调。
### Path Params
<Properties>
<Property name='message_id' type='string' key='message_id'>
消息 ID
</Property>
</Properties>
### Request Body
<Properties>
<Property name='rating' type='string' key='rating'>
like 或 dislike 空值为撤销
</Property>
<Property name='user' type='string' key='user'>
用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/messages/{message_id}/feedbacks" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/messages/{message_id}/feedbacks \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n --data-raw '{ \n "rating": "like",\n "user": "abc-123"\n}'`}>
```bash {{ title: 'cURL' }}
curl --location --request POST 'https://cloud.langgenius.dev/api/messages/{message_id}/feedbacks' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"rating": "like",
"user": "abc-123"
}'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"has_more": false,
"data": [
{
"id": "WAz8eIbvDR60rouK",
"username": "FrankMcCallister",
"phone_number": "1-800-759-3000",
"avatar_url": "https://assets.protocol.chat/avatars/frank.jpg",
"display_name": null,
"conversation_id": "xgQQXg3hrtjh7AvZ",
"last_active_at": 705103200,
"created_at": 692233200
},
{
"id": "hSIhXBhNe8X1d8Et"
// ...
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/parameters'
method='GET'
title='获取应用配置信息'
name='#parameters'
/>
<Row>
<Col>
获取已配置的 Input 参数,包括变量名、字段名称、类型与默认值。通常用于客户端加载后显示这些字段的表单或填入默认值。
### Query
<Properties>
<Property name='user' type='string' key='user'>
用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/parameters" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'`}>
```bash {{ title: 'cURL' }}
curl --location --request GET 'https://cloud.langgenius.dev/api/parameters?user=abc-123' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"introduction": "nice to meet you",
"variables": [
{
"key": "book",
"name": "Which book?",
"description": null,
"type": "string",
"default": null,
"options": null
},
{
// ...
]
}
```
</CodeGroup>
</Col>
</Row>

View File

@@ -0,0 +1,391 @@
import { CodeGroup } from '../code.tsx'
import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from '../md.tsx'
# Chat App API
For versatile conversational apps using a Q&A format, call the chat-messages API to initiate dialogue. Maintain ongoing conversations by passing the returned conversation_id. Response parameters and templates depend on LangGenius Prompt Eng. settings.
<Heading
url='/chat-messages'
method='POST'
title='Create chat message'
name='#Create-Chat-Message'
/>
<Row>
<Col>
Create a new conversation message or continue an existing dialogue.
### Request Body
<Properties>
<Property name='inputs' type='object' key='inputs'>
(Optional) Provide user input fields as key-value pairs, corresponding to variables in Prompt Eng. Key is the variable name, Value is the parameter value. If the field type is Select, the submitted Value must be one of the preset choices.
<ul>
{!!props.variables.length && props.variables.map(
val => (
<SubProperty name={val.key} type={val.type} key={val.key}>
{val.name ? `${val.name}` : ''}
</SubProperty>
)
)}
</ul>
</Property>
<Property name='query' type='string' key='query'>
User input/question content
</Property>
<Property name='response_mode' type='string' key='response_mode'>
- Blocking type, waiting for execution to complete and returning results. (Requests may be interrupted if the process is long)
- streaming returns. Implementation of streaming return based on SSE **[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**.
</Property>
<Property name='conversation_id' type='string' key='conversation_id'>
(Optional) Conversation ID: leave empty for first-time conversation; pass conversation_id from context to continue dialogue.
</Property>
<Property name='user' type='string' key='user'>
The user identifier, defined by the developer, must ensure uniqueness within the app.
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/chat-messages" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/chat-messages' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "inputs": ${JSON.stringify(props.inputs)},\n "query": "eh",\n "response_mode": "streaming",\n "conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",\n "user": "abc-123"\n}'\n`}>
```bash {{ title: 'cURL' }}
curl --location --request POST 'https://cloud.langgenius.dev/api/chat-messages' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"inputs": {},
"query": "eh",
"response_mode": "streaming",
"conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
"user": "abc-123"
}'
```
</CodeGroup>
### blocking
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"answer": "Hi, is there anything I can help you?",
"conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
"created_at": 1679587005,
"id": "059f87d9-15c0-473a-870c-fde95cdcc1e4"
}
```
</CodeGroup>
### streaming
<CodeGroup title="Response">
```streaming {{ title: 'Response' }}
data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/messages/{message_id}/feedbacks'
method='POST'
title='Message terminal user feedback, like'
name='#feedbacks'
/>
<Row>
<Col>
Rate received messages on behalf of end-users with likes or dislikes. This data is visible in the Logs & Annotations page and used for future model fine-tuning.
### Path Params
<Properties>
<Property name='message_id' type='string' key='message_id'>
Message ID
</Property>
</Properties>
### Request Body
<Properties>
<Property name='rating' type='string' key='rating'>
like or dislike, null is undo
</Property>
<Property name='user' type='string' key='user'>
The user identifier, defined by the developer, must ensure uniqueness within the app.
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/messages/{message_id}/feedbacks" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/messages/{message_id}/feedbacks \\\n --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "rating": "like",\n "user": "abc-123"\n}'`}>
```bash {{ title: 'cURL' }}
curl --location --request POST 'https://cloud.langgenius.dev/api/messages/{message_id}/feedbacks' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"rating": "like",
"user": "abc-123"
}'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"has_more": false,
"data": [
{
"id": "WAz8eIbvDR60rouK",
"username": "FrankMcCallister",
"phone_number": "1-800-759-3000",
"avatar_url": "https://assets.protocol.chat/avatars/frank.jpg",
"display_name": null,
"conversation_id": "xgQQXg3hrtjh7AvZ",
"last_active_at": 705103200,
"created_at": 692233200
},
{
"id": "hSIhXBhNe8X1d8Et"
// ...
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/messages'
method='GET'
title='Get the chat history message'
name='#messages'
/>
<Row>
<Col>
The first page returns the latest `limit` bar, which is in reverse order.
### Query
<Properties>
<Property name='conversation_id' type='string' key='conversation_id'>
Conversation ID
</Property>
<Property name='first_id' type='string' key='first_id'>
ID of the first chat record on the current page. The default is none.
</Property>
<Property name='limit' type='int' key='limit'>
How many chats are returned in one request
</Property>
<Property name='user' type='string' key='user'>
The user identifier, defined by the developer, must ensure uniqueness within the app.
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/messages" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='\\\n --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'`}>
```bash {{ title: 'cURL' }}
curl --location --request GET 'https://cloud.langgenius.dev/api/messages?user=abc-123&conversation_id='
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"has_more": false,
"data": [
{
"id": "WAz8eIbvDR60rouK",
"username": "FrankMcCallister",
"phone_number": "1-800-759-3000",
"avatar_url": "https://assets.protocol.chat/avatars/frank.jpg",
"display_name": null,
"conversation_id": "xgQQXg3hrtjh7AvZ",
"last_active_at": 705103200,
"created_at": 692233200
},
{
"id": "hSIhXBhNe8X1d8Et"
// ...
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/conversations'
method='GET'
title='Get conversation list'
name='#conversations'
/>
<Row>
<Col>
Gets the session list of the current user. By default, the last 20 sessions are returned.
### Query
<Properties>
<Property name='last_id' type='string' key='last_id'>
The ID of the last record on the current page, default none.
</Property>
<Property name='limit' type='int' key='limit'>
"How many chats are returned in one request
</Property>
<Property name='user' type='string' key='user'>
The user identifier, defined by the developer, must ensure uniqueness within the app.
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/conversations" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20'`}>
```bash {{ title: 'cURL' }}
curl --location --request GET 'https://cloud.langgenius.dev/api/conversations?user=abc-123&last_id=&limit=20' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"limit": 20,
"has_more": false,
"data": [
{
"id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
"name": "New chat",
"inputs": {
"book": "book",
"myName": "Lucy"
},
"status": "normal",
"created_at": 1679667915
},
{
"id": "hSIhXBhNe8X1d8Et"
// ...
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/conversations/{converation_id}/name'
method='POST'
title='Conversation renaming'
name='#rename'
/>
<Row>
<Col>
Rename conversations; the name is displayed in multi-session client interfaces.
### Request Body
<Properties>
<Property name='name' type='string' key='name'>
New name
</Property>
<Property name='user' type='string' key='user'>
The user identifier, defined by the developer, must ensure uniqueness within the app.
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/conversations/{converation_id}/name" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/conversations/name' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "name": "", \n "user": "abc-123"\n}'`}>
```bash {{ title: 'cURL' }}
curl --location --request POST 'https://cloud.langgenius.dev/api/conversations/name' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--data-raw '{
"name": "",
"user": "abc-123"
}'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"result": "success"
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/parameters'
method='GET'
title='Obtain application parameter information'
name='#rename'
/>
<Row>
<Col>
Retrieve configured Input parameters, including variable names, field names, types, and default values. Typically used for displaying these fields in a form or filling in default values after the client loads.
### Query
<Properties>
<Property name='user' type='string' key='user'>
The user identifier, defined by the developer, must ensure uniqueness within the app.
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl --location --request GET '${props.appDetail.api_base_url}/parameters?user=abc-123'`}>
```bash {{ title: 'cURL' }}
curl --location --request GET 'https://cloud.langgenius.dev/api/parameters?user=abc-123' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"introduction": "nice to meet you",
"variables": [
{
"key": "book",
"name": "book",
"description": null,
"type": "string",
"default": null,
"options": null
},
{
// ...
}
]
}
```
</CodeGroup>
</Col>
</Row>

View File

@@ -0,0 +1,391 @@
import { CodeGroup } from '../code.tsx'
import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
# 对话型应用 API
可用于大部分场景的对话型应用,采用一问一答模式与用户持续对话。要开始一个对话请调用 chat-messages 接口,通过继续传入返回的 conversation_id 可持续保持该会话。
<Heading
url='/chat-messages'
method='POST'
title='发送对话消息'
name='#Create-Chat-Message'
/>
<Row>
<Col>
创建会话消息,或基于此前的对话继续发送消息。
### Request Body
<Properties>
<Property name='inputs' type='object' key='inputs'>
选填以键值对方式提供用户输入字段与提示词编排中的变量对应。Key 为变量名称Value 是参数值。如果字段类型为 Select传入的 Value 需为预设选项之一。
<ul>
{!!props.variables.length && props.variables.map(
val => (
<SubProperty name={val.key} type={val.type} key={val.key}>
{val.name ? `${val.name}` : ''}
</SubProperty>
)
)}
</ul>
</Property>
<Property name='query' type='string' key='query'>
用户输入/提问内容
</Property>
<Property name='response_mode' type='string' key='response_mode'>
- blocking 阻塞型,等待执行完毕后返回结果。(请求若流程较长可能会被中断)
- streaming 流式返回。基于 SSE**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**)实现流式返回。
</Property>
<Property name='conversation_id' type='string' key='conversation_id'>
(选填)会话标识符,首次对话可为空,如果要继续对话请传入上下文返回的 conversation_id
</Property>
<Property name='user' type='string' key='user'>
用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/chat-messages" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/chat-messages' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "inputs": ${JSON.stringify(props.inputs)},\n "query": "eh",\n "response_mode": "streaming",\n "conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",\n "user": "abc-123"\n}'\n`}>
```bash {{ title: 'cURL' }}
curl --location --request POST 'https://cloud.langgenius.dev/api/chat-messages' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"inputs": {},
"query": "eh",
"response_mode": "streaming",
"conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
"user": "abc-123"
}'
```
</CodeGroup>
### blocking
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"answer": "Hi, is there anything I can help you?",
"conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
"created_at": 1679587005,
"id": "059f87d9-15c0-473a-870c-fde95cdcc1e4"
}
```
</CodeGroup>
### streaming
<CodeGroup title="Response">
```streaming {{ title: 'Response' }}
data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/messages/{message_id}/feedbacks'
method='POST'
title='消息反馈(点赞)'
name='#feedbacks'
/>
<Row>
<Col>
代表最终用户对返回消息进行评价,可以点赞与点踩,该数据将在“日志与标注”页中可见,并用于后续的模型微调。
### Path Params
<Properties>
<Property name='message_id' type='string' key='message_id'>
消息 ID
</Property>
</Properties>
### Request Body
<Properties>
<Property name='rating' type='string' key='rating'>
like 或 dislike 空值为撤销
</Property>
<Property name='user' type='string' key='user'>
用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/messages/{message_id}/feedbacks" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/messages/{message_id}/feedbacks \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "rating": "like",\n "user": "abc-123"\n}'`}>
```bash {{ title: 'cURL' }}
curl --location --request POST 'https://cloud.langgenius.dev/api/messages/{message_id}/feedbacks' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"rating": "like",
"user": "abc-123"
}'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"has_more": false,
"data": [
{
"id": "WAz8eIbvDR60rouK",
"username": "FrankMcCallister",
"phone_number": "1-800-759-3000",
"avatar_url": "https://assets.protocol.chat/avatars/frank.jpg",
"display_name": null,
"conversation_id": "xgQQXg3hrtjh7AvZ",
"last_active_at": 705103200,
"created_at": 692233200
},
{
"id": "hSIhXBhNe8X1d8Et"
// ...
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/messages'
method='GET'
title='获取会话历史消息'
name='#messages'
/>
<Row>
<Col>
滚动加载形式返回历史聊天记录,第一页返回最新 `limit` 条,即:倒序返回。
### Query
<Properties>
<Property name='conversation_id' type='string' key='conversation_id'>
会话 ID
</Property>
<Property name='first_id' type='string' key='first_id'>
当前页第一条聊天记录的 ID默认 none
</Property>
<Property name='limit' type='int' key='limit'>
一次请求返回多少条聊天记录
</Property>
<Property name='user' type='string' key='user'>
用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/messages" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id=' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'`}>
```bash {{ title: 'cURL' }}
curl --location --request GET 'https://cloud.langgenius.dev/api/messages?user=abc-123&conversation_id='
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"has_more": false,
"data": [
{
"id": "WAz8eIbvDR60rouK",
"username": "FrankMcCallister",
"phone_number": "1-800-759-3000",
"avatar_url": "https://assets.protocol.chat/avatars/frank.jpg",
"display_name": null,
"conversation_id": "xgQQXg3hrtjh7AvZ",
"last_active_at": 705103200,
"created_at": 692233200
},
{
"id": "hSIhXBhNe8X1d8Et"
// ...
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/conversations'
method='GET'
title='获取会话列表'
name='#conversations'
/>
<Row>
<Col>
获取当前用户的会话列表,默认返回最近的 20 条。
### Query
<Properties>
<Property name='last_id' type='string' key='last_id'>
当前页最后面一条记录的 ID默认 none
</Property>
<Property name='limit' type='int' key='limit'>
一次请求返回多少条记录
</Property>
<Property name='user' type='string' key='user'>
用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/conversations" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20'\\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'`}>
```bash {{ title: 'cURL' }}
curl --location --request GET 'https://cloud.langgenius.dev/api/conversations?user=abc-123&last_id=&limit=20' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"limit": 20,
"has_more": false,
"data": [
{
"id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
"name": "New chat",
"inputs": {
"book": "book",
"myName": "Lucy"
},
"status": "normal",
"created_at": 1679667915
},
{
"id": "hSIhXBhNe8X1d8Et"
// ...
}
]
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/conversations/{converation_id}/name'
method='POST'
title='会话重命名'
name='#rename'
/>
<Row>
<Col>
对会话进行重命名,会话名称用于显示在支持多会话的客户端上。
### Request Body
<Properties>
<Property name='name' type='string' key='name'>
新的名称
</Property>
<Property name='user' type='string' key='user'>
用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/conversations/{converation_id}/name" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/conversations/name' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "name": "", \n "user": "abc-123"\n}'`}>
```bash {{ title: 'cURL' }}
curl --location --request POST 'https://cloud.langgenius.dev/api/conversations/name' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "",
"user": "abc-123"
}'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"result": "success"
}
```
</CodeGroup>
</Col>
</Row>
---
<Heading
url='/parameters'
method='GET'
title='获取应用配置信息'
name='#rename'
/>
<Row>
<Col>
获取已配置的 Input 参数,包括变量名、字段名称、类型与默认值。通常用于客户端加载后显示这些字段的表单或填入默认值。
### Query
<Properties>
<Property name='user' type='string' key='user'>
用户标识,由开发者定义规则,需保证用户标识在应用内唯一。
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/parameters" targetCode={` curl --location --request GET '${props.appDetail.api_base_url}/parameters'\\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'`}>
```bash {{ title: 'cURL' }}
curl --location --request GET 'https://cloud.langgenius.dev/api/parameters?user=abc-123' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"introduction": "nice to meet you",
"variables": [
{
"key": "book",
"name": "book",
"description": null,
"type": "string",
"default": null,
"options": null
},
{
// ...
}
]
}
```
</CodeGroup>
</Col>
</Row>