docs: update api reference messages

This commit is contained in:
hieu-jan 2023-11-23 15:08:02 +09:00
parent c45b74457a
commit 015856104c
3 changed files with 230 additions and 83 deletions

View File

@ -255,4 +255,162 @@ See [Jan Messages API](https://jan.ai/api-reference#tag/Messages)
"created_at": 1699061776, "created_at": 1699061776,
"message_id": "msg_abc123" "message_id": "msg_abc123"
} }
``` --> ``` -->
### Get list message
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/getMessage
- Example request
```shell
curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \
-H "Content-Type: application/json"
```
- Example response
```json
{
"id": "msg_abc123",
"object": "thread.message",
"created_at": 1699017614,
"thread_id": "thread_abc123",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "How does AI work? Explain it in simple terms.",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": null,
"run_id": null,
"metadata": {}
}
```
### Create message
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/createMessage
- Example request
```shell
curl -X POST {JAN_URL}/v1/threads/{thread_id}/messages \
-H "Content-Type: application/json" \
-d '{
"role": "user",
"content": "How does AI work? Explain it in simple terms."
}'
```
- Example response
```json
{
"id": "msg_abc123",
"object": "thread.message",
"created_at": 1699017614,
"thread_id": "thread_abc123",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "How does AI work? Explain it in simple terms.",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": null,
"run_id": null,
"metadata": {}
}
```
### Get message
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants/listAssistants
- Example request
```shell
curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \
-H "Content-Type: application/json"
```
- Example response
```json
{
"id": "msg_abc123",
"object": "thread.message",
"created_at": 1699017614,
"thread_id": "thread_abc123",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "How does AI work? Explain it in simple terms.",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": null,
"run_id": null,
"metadata": {}
}
```
### Modify message
> Jan: TODO: Do we need to modify message? Or let user create new message?
# Get message file
> OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files/{file_id}
- Example request
```shell
curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \
-H "Content-Type: application/json"
```
- Example response
```json
{
"id": "file-abc123",
"object": "thread.message.file",
"created_at": 1699061776,
"message_id": "msg_abc123"
}
```
# List message files
> OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files
````
- Example request
```shell
curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \
-H "Content-Type: application/json"
````
- Example response
```json
{
"id": "file-abc123",
"object": "thread.message.file",
"created_at": 1699061776,
"message_id": "msg_abc123"
}

View File

@ -17,10 +17,18 @@ tags:
- name: Chat Completion - name: Chat Completion
description: Given a list of messages comprising a conversation, the model will return a response. description: Given a list of messages comprising a conversation, the model will return a response.
- name: Messages - name: Messages
description: Operations for individual messages, including creation, retrieval, and modification description: |
Messages capture a conversation's content. This can include the content from LLM responses and other metadata from [chat completions](/specs/chats).
- Users and assistants can send multimedia messages.
- An [OpenAI Message API](https://platform.openai.com/docs/api-reference/messages) compatible endpoint at `localhost:1337/v1/messages`.
- Jan's `messages` API is compatible with [OpenAI's Messages API](https://platform.openai.com/docs/api-reference/messages), with additional methods for managing messages locally.
- name: Threads - name: Threads
description: | description: |
`Threads` are conversations between an `assistant` and the user: Threads are conversations between an `assistant` and the user:
- Users can tweak `model` params and `assistant` behavior within each thread. - Users can tweak `model` params and `assistant` behavior within each thread.
- Users can import and export threads. - Users can import and export threads.
- An [OpenAI Thread API](https://platform.openai.com/docs/api-reference/threads) compatible endpoint at `localhost:1337/v1/threads`. - An [OpenAI Thread API](https://platform.openai.com/docs/api-reference/threads) compatible endpoint at `localhost:1337/v1/threads`.
@ -428,8 +436,8 @@ paths:
operationId: listMessages operationId: listMessages
tags: tags:
- Messages - Messages
summary: Get a list of messages from a thread summary: List messaages
description: Retrieves all messages from the specified thread. description: Retrieves all messages from the given thread.
parameters: parameters:
- in: path - in: path
name: thread_id name: thread_id
@ -454,8 +462,8 @@ paths:
operationId: createMessage operationId: createMessage
tags: tags:
- Messages - Messages
summary: Create a new message in a thread summary: Create message
description: Sends a new message to the specified thread. description: Create a message
parameters: parameters:
- in: path - in: path
name: thread_id name: thread_id
@ -493,13 +501,16 @@ paths:
x-codeSamples: x-codeSamples:
- lang: "curl" - lang: "curl"
source: | source: |
curl -X POST {JAN_URL}/v1/threads/{thread_id}/messages \ curl -X POST {JAN_URL}/v1/threads/{thread_id}/messages \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"role": "user", "content": "How does AI work? Explain it in simple terms."}' -d '{
"role": "user",
"content": "How does AI work? Explain it in simple terms."
}'
/threads/{thread_id}/messages/{message_id}: /threads/{thread_id}/messages/{message_id}:
get: get:
operationId: getMessage operationId: retrieveMessage
tags: tags:
- Messages - Messages
summary: Retrieve Message summary: Retrieve Message
@ -529,16 +540,16 @@ paths:
x-codeSamples: x-codeSamples:
- lang: "curl" - lang: "curl"
source: | source: |
curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \ curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id} \
-H "Content-Type: application/json" -H "Content-Type: application/json"
/threads/{thread_id}/messages/{message_id}/files: /threads/{thread_id}/messages/{message_id}/files:
get: get:
operationId: listMessageFiles operationId: listMessageFiles
tags: tags:
- Messages - Messages
summary: message files summary: List message files
description: Retrieves a list of files associated with a specific message in a thread. description: Returns a list of message files.
parameters: parameters:
- in: path - in: path
name: thread_id name: thread_id
@ -569,10 +580,10 @@ paths:
/threads/{thread_id}/messages/{message_id}/files/{file_id}: /threads/{thread_id}/messages/{message_id}/files/{file_id}:
get: get:
operationId: getMessageFile operationId: retrieveMessageFile
tags: tags:
- Messages - Messages
summary: Get message file summary: Retrieve message file
description: Retrieves a file associated with a specific message in a thread. description: Retrieves a file associated with a specific message in a thread.
parameters: parameters:
- in: path - in: path

View File

@ -6,11 +6,11 @@ components:
id: id:
type: string type: string
description: "Sequential or UUID identifier of the message." description: "Sequential or UUID identifier of the message."
example: "0" example: 0
object: object:
type: string type: string
description: "Type of the object, typically 'thread.message'." description: "Type of the object, defaults to 'thread.message'."
default: "thread.message" example: thread.message
created_at: created_at:
type: integer type: integer
format: int64 format: int64
@ -22,7 +22,7 @@ components:
assistant_id: assistant_id:
type: string type: string
description: "Identifier of the assistant involved in the message. Defaults to parent thread." description: "Identifier of the assistant involved in the message. Defaults to parent thread."
example: "jan" example: jan
role: role:
type: string type: string
enum: ["user", "assistant"] enum: ["user", "assistant"]
@ -41,25 +41,17 @@ components:
value: value:
type: string type: string
description: "Text content of the message." description: "Text content of the message."
example: "Hi!?"
annotations: annotations:
type: array type: array
items: items:
type: string type: string
description: "Annotations for the text content, if any." description: "Annotations for the text content, if any."
example: []
metadata: metadata:
type: object type: object
description: "Metadata associated with the message, defaults to an empty object." description: "Metadata associated with the message, defaults to an empty object."
chat_completion_id: example: {}
type: string
description: "Identifier of the chat completion, if applicable."
required:
- id
- object
- created_at
- thread_id
- assistant_id
- role
- content
GetMessageResponse: GetMessageResponse:
type: object type: object
@ -67,23 +59,24 @@ components:
id: id:
type: string type: string
description: "The identifier of the message." description: "The identifier of the message."
example: "msg_abc123" example: msg_abc123
object: object:
type: string type: string
description: "Type of the object, indicating it's a thread message." description: "Type of the object, indicating it's a thread message."
default: "thread.message" default: thread.message
created_at: created_at:
type: integer type: integer
format: int64 format: int64
description: "Unix timestamp representing the creation time of the message." description: "Unix timestamp representing the creation time of the message."
example: 1699017614
thread_id: thread_id:
type: string type: string
description: "Identifier of the thread to which this message belongs." description: "Identifier of the thread to which this message belongs."
example: "thread_abc123" example: thread_abc123
role: role:
type: string type: string
description: "Role of the sender, either 'user' or 'assistant'." description: "Role of the sender, either 'user' or 'assistant'."
example: "user" example: user
content: content:
type: array type: array
items: items:
@ -92,6 +85,7 @@ components:
type: type:
type: string type: string
description: "Type of content, e.g., 'text'." description: "Type of content, e.g., 'text'."
example: text
text: text:
type: object type: object
properties: properties:
@ -104,27 +98,25 @@ components:
items: items:
type: string type: string
description: "Annotations for the text content, if any." description: "Annotations for the text content, if any."
example: []
file_ids: file_ids:
type: array type: array
items: items:
type: string type: string
description: "Array of file IDs associated with the message, if any." description: "Array of file IDs associated with the message, if any."
example: []
assistant_id: assistant_id:
type: string type: string
description: "Identifier of the assistant involved in the message, if applicable." description: "Identifier of the assistant involved in the message, if applicable."
example: null
run_id: run_id:
type: string type: string
description: "Run ID associated with the message, if applicable." description: "Run ID associated with the message, if applicable."
example: null
metadata: metadata:
type: object type: object
description: "Metadata associated with the message." description: "Metadata associated with the message."
required: example: {}
- id
- object
- created_at
- thread_id
- role
- content
CreateMessageResponse: CreateMessageResponse:
type: object type: object
@ -132,23 +124,24 @@ components:
id: id:
type: string type: string
description: "The identifier of the created message." description: "The identifier of the created message."
example: "msg_abc123" example: msg_abc123
object: object:
type: string type: string
description: "Type of the object, indicating it's a thread message." description: "Type of the object, indicating it's a thread message."
default: "thread.message" example: thread.message
created_at: created_at:
type: integer type: integer
format: int64 format: int64
description: "Unix timestamp representing the creation time of the message." description: "Unix timestamp representing the creation time of the message."
example: 1699017614
thread_id: thread_id:
type: string type: string
description: "Identifier of the thread to which this message belongs." description: "Identifier of the thread to which this message belongs."
example: "thread_abc123" example: thread_abc123
role: role:
type: string type: string
description: "Role of the sender, either 'user' or 'assistant'." description: "Role of the sender, either 'user' or 'assistant'."
example: "user" example: user
content: content:
type: array type: array
items: items:
@ -157,6 +150,7 @@ components:
type: type:
type: string type: string
description: "Type of content, e.g., 'text'." description: "Type of content, e.g., 'text'."
example: text
text: text:
type: object type: object
properties: properties:
@ -169,27 +163,25 @@ components:
items: items:
type: string type: string
description: "Annotations for the text content, if any." description: "Annotations for the text content, if any."
example: []
file_ids: file_ids:
type: array type: array
items: items:
type: string type: string
description: "Array of file IDs associated with the message, if any." description: "Array of file IDs associated with the message, if any."
example: []
assistant_id: assistant_id:
type: string type: string
description: "Identifier of the assistant involved in the message, if applicable." description: "Identifier of the assistant involved in the message, if applicable."
example: null
run_id: run_id:
type: string type: string
description: "Run ID associated with the message, if applicable." description: "Run ID associated with the message, if applicable."
example: null
metadata: metadata:
type: object type: object
description: "Metadata associated with the message." description: "Metadata associated with the message."
required: example: {}
- id
- object
- created_at
- thread_id
- role
- content
ListMessagesResponse: ListMessagesResponse:
type: object type: object
@ -214,12 +206,6 @@ components:
type: boolean type: boolean
description: "Indicates whether there are more messages to retrieve." description: "Indicates whether there are more messages to retrieve."
example: false example: false
required:
- object
- data
- first_id
- last_id
- has_more
ListMessageObject: ListMessageObject:
type: object type: object
@ -227,23 +213,24 @@ components:
id: id:
type: string type: string
description: "The identifier of the message." description: "The identifier of the message."
example: "msg_abc123" example: msg_abc123
object: object:
type: string type: string
description: "Type of the object, indicating it's a thread message." description: "Type of the object, indicating it's a thread message."
default: "thread.message" example: thread.message
created_at: created_at:
type: integer type: integer
format: int64 format: int64
description: "Unix timestamp representing the creation time of the message." description: "Unix timestamp representing the creation time of the message."
example: 1699017614
thread_id: thread_id:
type: string type: string
description: "Identifier of the thread to which this message belongs." description: "Identifier of the thread to which this message belongs."
example: "thread_abc123" example: thread_abc123
role: role:
type: string type: string
description: "Role of the sender, either 'user' or 'assistant'." description: "Role of the sender, either 'user' or 'assistant'."
example: "user" example: user
content: content:
type: array type: array
items: items:
@ -269,22 +256,19 @@ components:
items: items:
type: string type: string
description: "Array of file IDs associated with the message, if any." description: "Array of file IDs associated with the message, if any."
example: []
assistant_id: assistant_id:
type: string type: string
description: "Identifier of the assistant involved in the message, if applicable." description: "Identifier of the assistant involved in the message, if applicable."
example: null
run_id: run_id:
type: string type: string
description: "Run ID associated with the message, if applicable." description: "Run ID associated with the message, if applicable."
example: null
metadata: metadata:
type: object type: object
description: "Metadata associated with the message." description: "Metadata associated with the message."
required: example: {}
- id
- object
- created_at
- thread_id
- role
- content
MessageFileObject: MessageFileObject:
type: object type: object
@ -292,24 +276,21 @@ components:
id: id:
type: string type: string
description: "The identifier of the file." description: "The identifier of the file."
example: "file-abc123" example: file-abc123
object: object:
type: string type: string
description: "Type of the object, indicating it's a thread message file." description: "Type of the object, indicating it's a thread message file."
default: "thread.message.file" example: thread.message.file
created_at: created_at:
type: integer type: integer
format: int64 format: int64
description: "Unix timestamp representing the creation time of the file." description: "Unix timestamp representing the creation time of the file."
example: 1699061776
message_id: message_id:
type: string type: string
description: "Identifier of the message to which this file is associated." description: "Identifier of the message to which this file is associated."
example: "msg_abc123" example: msg_abc123
required:
- id
- object
- created_at
- message_id
ListMessageFilesResponse: ListMessageFilesResponse:
type: object type: object
properties: properties:
@ -320,7 +301,4 @@ components:
data: data:
type: array type: array
items: items:
$ref: '#/components/schemas/MessageFileObject' $ref: '#/components/schemas/MessageFileObject'
required:
- object
- data