Merge pull request #707 from janhq/fix/spec_assistants_v1
[WIP] Update assistant spec v1
This commit is contained in:
commit
77f20db5dd
@ -2,239 +2,101 @@
|
|||||||
title: "Assistants"
|
title: "Assistants"
|
||||||
---
|
---
|
||||||
|
|
||||||
Assistants can use models and tools.
|
:::caution
|
||||||
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants
|
|
||||||
- Jan's `Assistants` are even more powerful than OpenAI due to customizable code in `index.js`
|
|
||||||
|
|
||||||
## User Stories
|
This is currently under development.
|
||||||
|
|
||||||
_Users can download an assistant via a web URL_
|
:::
|
||||||
|
|
||||||
- Wireframes here
|
## Overview
|
||||||
|
|
||||||
_Users can import an assistant from local directory_
|
In Jan, assistants are `primary` entities with the following capabilities:
|
||||||
|
|
||||||
- Wireframes here
|
- Assistants can use `models`, `tools`, handle and emit `events`, and invoke `custom code`.
|
||||||
|
- Users can create custom assistants with saved `model` settings and parameters.
|
||||||
|
- An [OpenAI Assistants API](https://platform.openai.com/docs/api-reference/assistants) compatible endpoint at `localhost:3000/v1/assistants`.
|
||||||
|
- Jan ships with a default assistant called "Jan" that lets you use all models.
|
||||||
|
|
||||||
_Users can configure assistant settings_
|
## Folder Structure
|
||||||
|
|
||||||
- Wireframes here
|
```yaml
|
||||||
|
/jan
|
||||||
|
/models/
|
||||||
|
/threads/
|
||||||
|
/assistants
|
||||||
|
/jan # An assistant available to you by default
|
||||||
|
assistant.json # See below
|
||||||
|
/src # Assistants can invoke custom code
|
||||||
|
index.js # Entrypoint
|
||||||
|
process.js # For server processes (needs better name)
|
||||||
|
package.json # Import any npm libraries, e.g. Langchain, Llamaindex
|
||||||
|
/shakespeare # You can create custom assistants
|
||||||
|
assistant.json
|
||||||
|
/chicken_man
|
||||||
|
```
|
||||||
|
|
||||||
## Assistant Object
|
## `assistant.json`
|
||||||
|
|
||||||
- `assistant.json`
|
```js
|
||||||
> OpenAI Equivalen: https://platform.openai.com/docs/api-reference/assistants/object
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
{
|
||||||
// Jan specific properties
|
"id": "asst_abc123", // Defaults to foldername
|
||||||
"avatar": "https://lala.png",
|
"object": "assistant", // Always "assistant"
|
||||||
"thread_location": "ROOT/threads", // Default to root (optional field)
|
"version": 1, // Defaults to 1
|
||||||
// TODO: add moar
|
|
||||||
|
|
||||||
// OpenAI compatible properties: https://platform.openai.com/docs/api-reference/assistants
|
|
||||||
"id": "asst_abc123",
|
|
||||||
"object": "assistant",
|
|
||||||
"created_at": 1698984975,
|
"created_at": 1698984975,
|
||||||
"name": "Math Tutor",
|
"name": "Math Tutor", // Defaults to foldername
|
||||||
"description": null,
|
"description": null,
|
||||||
"instructions": "...",
|
"avatar": "https://pic.png",
|
||||||
"tools": [
|
"models": [ // Defaults to "*" all models
|
||||||
{
|
{ ...model_0 }
|
||||||
"type": "retrieval"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "web_browsing"
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"file_ids": ["file_id"],
|
"events": [], // Defaults to "*"
|
||||||
"models": ["<model_id>"],
|
"metadata": {}, // Defaults to {}
|
||||||
"metadata": {}
|
// "tools": [], // Coming soon
|
||||||
|
// "file_ids": [], // Coming soon
|
||||||
|
// "memory/threads": true, // Coming soon
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Assistant lifecycle
|
### Examples
|
||||||
Assistant has 4 states (enum)
|
|
||||||
- `to_download`
|
|
||||||
- `downloading`
|
|
||||||
- `ready`
|
|
||||||
- `running`
|
|
||||||
|
|
||||||
## Assistants API
|
Here's what the default Jan assistant's json file looks like:
|
||||||
|
|
||||||
- What would modifying Assistant do? (doesn't mutate `index.js`?)
|
```js
|
||||||
- By default, `index.js` loads `assistant.json` file and executes exactly like so. This supports builders with little time to write code.
|
|
||||||
- The `assistant.json` is 1 source of truth for the definitions of `models` and `built-in tools` that they can use it without writing more code.
|
|
||||||
|
|
||||||
### Get list assistants
|
|
||||||
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants/listAssistants
|
|
||||||
- Example request
|
|
||||||
```shell
|
|
||||||
curl {JAN_URL}/v1/assistants?order=desc&limit=20 \
|
|
||||||
-H "Content-Type: application/json"
|
|
||||||
```
|
|
||||||
- Example response
|
|
||||||
```json
|
|
||||||
{
|
{
|
||||||
"object": "list",
|
"name": "Jan",
|
||||||
"data": [
|
"description": "A global assistant that lets you chat with all downloaded models",
|
||||||
{
|
"avatar": "https://jan.ai/img/logo.svg",
|
||||||
"id": "asst_abc123",
|
// All other properties are not explicitly declared and use the default values (see above).
|
||||||
"object": "assistant",
|
|
||||||
"created_at": 1698982736,
|
|
||||||
"name": "Coding Tutor",
|
|
||||||
"description": null,
|
|
||||||
"models": ["model_zephyr_7b", "azure-openai-gpt4-turbo"],
|
|
||||||
"instructions": "You are a helpful assistant designed to make me better at coding!",
|
|
||||||
"tools": [],
|
|
||||||
"file_ids": [],
|
|
||||||
"metadata": {},
|
|
||||||
"state": "ready"
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"first_id": "asst_abc123",
|
|
||||||
"last_id": "asst_abc789",
|
|
||||||
"has_more": false
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Get assistant
|
## Events
|
||||||
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants/getAssistant
|
|
||||||
- Example request
|
Jan assistants can respond to event hooks. More powerfully, Jan assistants can register their own pubsub, so other entities, like other assistants can respond to your assistants events.
|
||||||
```shell
|
|
||||||
curl {JAN_URL}/v1/assistants/{assistant_id} \
|
## Custom Code
|
||||||
-H "Content-Type: application/json"
|
|
||||||
```
|
Jan assistants are Turing complete. This means you can write freeform code, and use any dependencies, when customizing your assistant.
|
||||||
- Example response
|
|
||||||
```json
|
```typescript
|
||||||
{
|
import {events, models} from "@janhq/core"
|
||||||
"id": "asst_abc123",
|
import {retrieval} from "@hiro/best-rag-ever" // This can be featured on Jan hub but install from npm
|
||||||
"object": "assistant",
|
|
||||||
"created_at": 1699009709,
|
events.on('assistant:asst_abc123', (event) => async {
|
||||||
"name": "HR Helper",
|
const result = models[0].process(event)
|
||||||
"description": null,
|
events.emit("assistant:asst_abc123", result)
|
||||||
"models": ["model_zephyr_7b", "azure-openai-gpt4-turbo"],
|
resolve()
|
||||||
"instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.",
|
})
|
||||||
"tools": [
|
|
||||||
{
|
|
||||||
"type": "retrieval"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"file_ids": [
|
|
||||||
"file-abc123"
|
|
||||||
],
|
|
||||||
"metadata": {},
|
|
||||||
"state": "ready"
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create an assistant
|
## Tools
|
||||||
Create an assistant with models and instructions.
|
|
||||||
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants/createAssistant
|
|
||||||
- Example request
|
|
||||||
```shell
|
|
||||||
curl -X POST {JAN_URL}/v1/assistants \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d {
|
|
||||||
"instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
|
|
||||||
"name": "Math Tutor",
|
|
||||||
"tools": [{"type": "retrieval"}],
|
|
||||||
"model": ["model_zephyr_7b", "azure-openai-gpt4-turbo"]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- Example response
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"id": "asst_abc123",
|
|
||||||
"object": "assistant",
|
|
||||||
"created_at": 1698984975,
|
|
||||||
"name": "Math Tutor",
|
|
||||||
"description": null,
|
|
||||||
"model": ["model_zephyr_7b", "azure-openai-gpt4-turbo"]
|
|
||||||
"instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
|
|
||||||
"tools": [
|
|
||||||
{
|
|
||||||
"type": "retrieval"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"file_ids": [],
|
|
||||||
"metadata": {},
|
|
||||||
"state": "ready"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
### Modify an assistant
|
|
||||||
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants/modifyAssistant
|
|
||||||
- Example request
|
|
||||||
```shell
|
|
||||||
curl -X POST {JAN_URL}/v1/assistants/{assistant_id} \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d {
|
|
||||||
"instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
|
|
||||||
"name": "Math Tutor",
|
|
||||||
"tools": [{"type": "retrieval"}],
|
|
||||||
"model": ["model_zephyr_7b", "azure-openai-gpt4-turbo"]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- Example response
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"id": "asst_abc123",
|
|
||||||
"object": "assistant",
|
|
||||||
"created_at": 1698984975,
|
|
||||||
"name": "Math Tutor",
|
|
||||||
"description": null,
|
|
||||||
"model": ["model_zephyr_7b", "azure-openai-gpt4-turbo"]
|
|
||||||
"instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
|
|
||||||
"tools": [
|
|
||||||
{
|
|
||||||
"type": "retrieval"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"file_ids": [],
|
|
||||||
"metadata": {},
|
|
||||||
"state": "ready"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
### Delete Assistant
|
|
||||||
> OpenAI Equivalent: https://platform.openai.com/docs/api-reference/assistants/deleteAssistant
|
|
||||||
`- Example request
|
|
||||||
```shell
|
|
||||||
curl -X DELETE {JAN_URL}/v1/assistant/model-zephyr-7B
|
|
||||||
```
|
|
||||||
- Example response
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"id": "asst_abc123",
|
|
||||||
"object": "assistant.deleted",
|
|
||||||
"deleted": true,
|
|
||||||
"state": "to_download"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Assistants Filesystem
|
> Coming soon
|
||||||
|
|
||||||
```sh
|
## Functions
|
||||||
/assistants
|
|
||||||
/jan
|
|
||||||
assistant.json # Assistant configs (see below)
|
|
||||||
|
|
||||||
# For any custom code
|
> Coming soon
|
||||||
package.json # Import npm modules
|
|
||||||
# e.g. Langchain, Llamaindex
|
|
||||||
/src # Supporting files (needs better name)
|
|
||||||
index.js # Entrypoint
|
|
||||||
process.js # For electron IPC processes (needs better name)
|
|
||||||
|
|
||||||
# `/threads` at root level
|
## Files
|
||||||
# `/models` at root level
|
|
||||||
/shakespeare
|
|
||||||
assistant.json
|
|
||||||
package.json
|
|
||||||
/src
|
|
||||||
index.js
|
|
||||||
process.js
|
|
||||||
|
|
||||||
/threads # Assistants remember conversations in the future
|
> Coming soon
|
||||||
/models # Users can upload custom models
|
|
||||||
/finetuned-model
|
|
||||||
```
|
|
||||||
|
|||||||
@ -103,7 +103,7 @@ const sidebars = {
|
|||||||
"specs/models",
|
"specs/models",
|
||||||
"specs/threads",
|
"specs/threads",
|
||||||
"specs/messages",
|
"specs/messages",
|
||||||
// "specs/assistants",
|
"specs/assistants",
|
||||||
// "specs/files",
|
// "specs/files",
|
||||||
// "specs/jan",
|
// "specs/jan",
|
||||||
// "specs/fine-tuning",
|
// "specs/fine-tuning",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user