docs: roughing in a messages spec

This commit is contained in:
0xSage 2023-11-21 21:05:39 +08:00
parent 7565b876e3
commit cab49b700d
3 changed files with 132 additions and 103 deletions

View File

@ -2,57 +2,70 @@
title: Messages title: Messages
--- ---
:::warning :::caution
Draft Specification: functionality has not been implemented yet. This is currently under development.
Feedback: [HackMD: Threads Spec](https://hackmd.io/BM_8o_OCQ-iLCYhunn2Aug)
::: :::
Messages are within `threads` and capture additional metadata. ## Overview
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages
`Messages` are in `threads` and capture additional metadata:
- Users can ...
## Folder Structure
- `Message` objects are in `thread.json` files under `messages` property. See [threads](./threads.md)
## `message` object
### Example
Here's a standard example `message` json.
## Message Object
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/object
```json ```json
{ "id": "0", // Sequential or UUID?
// Jan specific properties "object": "thread.message", // Defaults to "thread.message"
"updatedAt": "...", // that's it I think "created_at": 1698983503,
"thread_id": "thread_asdf", // Defaults to parent thread
// OpenAI compatible properties: https://platform.openai.com/docs/api-reference/messages) "role": "assistant", // Defaults to "user" or "assistant"
"id": "msg_dKYDWyQvtjDBi3tudL1yWKDa", "content": [
"object": "thread.message", {
"created_at": 1698983503, "type": "text",
"thread_id": "thread_RGUhOuO9b2nrktrmsQ2uSR6I", "text": {
"role": "assistant", "value": "Hi! How can I help you today?",
"content": [ "annotations": []
{
"type": "text",
"text": {
"value": "Hi! How can I help you today?",
"annotations": []
}
} }
], }
"file_ids": [], ],
"assistant_id": "asst_ToSF7Gb04YMj8AMMm50ZLLtY", "assistant_id": "...",
"run_id": "run_BjylUJgDqYK9bOhy4yjAiMrn", "run_id": "...", // The `run` resulting in this message
"metadata": {} "metadata": {}, // Defaults to {}
} // "file_ids": [],
``` ```
## Messages API ## API Reference
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages
Jan's Threads API is compatible with [OpenAI's Messages API](https://platform.openai.com/docs/api-reference/messages), with additional methods for managing messages locally.
See [Jan Messages API](https://jan.ai/api-reference#tag/Messages)
<!-- TODO clean this part up into API -->
### Get list message ### Get list message
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/getMessage > OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/getMessage
- Example request - Example request
```shell ```shell
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"
``` ```
- Example response - Example response
```json ```json
{ {
"id": "msg_abc123", "id": "msg_abc123",
@ -75,9 +88,13 @@ Messages are within `threads` and capture additional metadata.
"metadata": {} "metadata": {}
} }
``` ```
### Create message ### Create message
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/createMessage > OpenAI Equivalent: https://platform.openai.com/docs/api-reference/messages/createMessage
- Example request - Example request
```shell ```shell
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" \
@ -86,93 +103,112 @@ Messages are within `threads` and capture additional metadata.
"content": "How does AI work? Explain it in simple terms." "content": "How does AI work? Explain it in simple terms."
}' }'
``` ```
- Example response - Example response
```json ```json
{ {
"id": "msg_abc123", "id": "msg_abc123",
"object": "thread.message", "object": "thread.message",
"created_at": 1699017614, "created_at": 1699017614,
"thread_id": "thread_abc123", "thread_id": "thread_abc123",
"role": "user", "role": "user",
"content": [ "content": [
{ {
"type": "text", "type": "text",
"text": { "text": {
"value": "How does AI work? Explain it in simple terms.", "value": "How does AI work? Explain it in simple terms.",
"annotations": [] "annotations": []
}
} }
], }
"file_ids": [], ],
"assistant_id": null, "file_ids": [],
"run_id": null, "assistant_id": null,
"metadata": {} "run_id": null,
} "metadata": {}
}
``` ```
### Get message ### Get message
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants/listAssistants > OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants/listAssistants
- Example request - Example request
```shell ```shell
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"
``` ```
- Example response - Example response
```json ```json
{ {
"id": "msg_abc123", "id": "msg_abc123",
"object": "thread.message", "object": "thread.message",
"created_at": 1699017614, "created_at": 1699017614,
"thread_id": "thread_abc123", "thread_id": "thread_abc123",
"role": "user", "role": "user",
"content": [ "content": [
{ {
"type": "text", "type": "text",
"text": { "text": {
"value": "How does AI work? Explain it in simple terms.", "value": "How does AI work? Explain it in simple terms.",
"annotations": [] "annotations": []
}
} }
], }
"file_ids": [], ],
"assistant_id": null, "file_ids": [],
"run_id": null, "assistant_id": null,
"metadata": {} "run_id": null,
} "metadata": {}
}
``` ```
### Modify message ### Modify message
> Jan: TODO: Do we need to modify message? Or let user create new message? > Jan: TODO: Do we need to modify message? Or let user create new message?
# Get message file # Get message file
> OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} > OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files/{file_id}
- Example request - Example request
```shell ```shell
curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \ curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \
-H "Content-Type: application/json" -H "Content-Type: application/json"
``` ```
- Example response - Example response
```json ```json
{ {
"id": "file-abc123", "id": "file-abc123",
"object": "thread.message.file", "object": "thread.message.file",
"created_at": 1699061776, "created_at": 1699061776,
"message_id": "msg_abc123" "message_id": "msg_abc123"
} }
``` ```
# List message files # List message files
> OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files > OpenAI Equivalent: https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files
```
````
- Example request - Example request
```shell ```shell
curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \ curl {JAN_URL}/v1/threads/{thread_id}/messages/{message_id}/files/{file_id} \
-H "Content-Type: application/json" -H "Content-Type: application/json"
``` ````
- Example response - Example response
```json ```json
{ {
"id": "file-abc123", "id": "file-abc123",
"object": "thread.message.file", "object": "thread.message.file",
"created_at": 1699061776, "created_at": 1699061776,
"message_id": "msg_abc123" "message_id": "msg_abc123"
} }
``` ```

View File

@ -53,12 +53,12 @@ Here's a standard example `model.json` for a GGUF model.
- `source_url`: https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/. - `source_url`: https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/.
```json ```json
"source_url": "https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/blob/main/zephyr-7b-beta.Q4_K_M.gguf",
"type": "model", // Defaults to "model"
"version": "1", // Defaults to 1
"id": "zephyr-7b" // Defaults to foldername "id": "zephyr-7b" // Defaults to foldername
"object": "model", // Defaults to "model"
"source_url": "https://huggingface.co/TheBloke/zephyr-7B-beta-GGUF/blob/main/zephyr-7b-beta.Q4_K_M.gguf",
"name": "Zephyr 7B" // Defaults to foldername "name": "Zephyr 7B" // Defaults to foldername
"owned_by": "you" // Defaults to you "owned_by": "you" // Defaults to you
"version": "1", // Defaults to 1
"created": 1231231 // Defaults to file creation time "created": 1231231 // Defaults to file creation time
"description": "" "description": ""
"state": enum[null, "downloading", "ready", "starting", "stopping", ...] "state": enum[null, "downloading", "ready", "starting", "stopping", ...]

View File

@ -41,23 +41,16 @@ jan/
Here's a standard example `thread.json` for a conversation between the user and the default Jan assistant. Here's a standard example `thread.json` for a conversation between the user and the default Jan assistant.
```json ```json
"type": "thread", // Defaults to "thread" "id": "thread_....", // Defaults to foldername
"object": "thread", // Defaults to "thread"
"summary": "funny physics joke", // Defaults to "" "summary": "funny physics joke", // Defaults to ""
"assistants": ["jan"], // Defaults to "jan" "assistants": ["jan"], // Defaults to "jan"
"created": 1231231 // Defaults to file creation time "created": 1231231 // Defaults to file creation time
"metadata": {}, // Defaults to {} "metadata": {}, // Defaults to {}
"messages": [ "messages": [],
{...message_0}, {...message_1} "model_id": "...", // Defaults to assistant.model ???
], "settings": {}, // Defaults to and overrides assistant.settings
"model_id": "...", // Do we need this property? "parameters": {}, // Defaults to and overrides assistant.settings
// Overrides assistant.settings && model.settings
"settings": {
...
},
// Overrides assistant.settings && model.settings
"parameters": {
...
},
``` ```
## API Reference ## API Reference
@ -66,7 +59,7 @@ Jan's Threads API is compatible with [OpenAI's Threads API](https://platform.ope
See [Jan Threads API](https://jan.ai/api-reference#tag/Threads) See [Jan Threads API](https://jan.ai/api-reference#tag/Threads)
<!-- TODO clean this part up into api --> <!-- TODO clean this part up into API -->
### Get thread ### Get thread