import * as JSX from './jsx'; import $ from 'jquery'; import { Page, GroupBox } from './components'; export default function Api() { return

POST /update-settings

Updates user settings based on the preferences provided.

Request

Body:

{ `{
  "token": "JWT token",
  "prefs": {
    "nickname": "string",
    "prompt_data": { "system": "string" },
    "site_prefs": { "model": "string" }
  }
}` }

Responses

{ $( `{
  "status": "ok" | "error",
  "msg": "settings updated" | "error message",
  "userprefs": {
    "uuid": "string", /* the user uuid */
    "nickname": "string", /* the user's set nickname */
    "prompt_data": { "system": "string" }, /* the custom system prompt */
    "site_prefs": { "model": "string" },  /* the user preferred model */
    "chat_files": { "files": [ { "id": "string", "name": "string" } ] }, /* list of user's chat files */
  }
}` )[0] }
  • 200 OK: Settings updated successfully
  • 400 Bad Request: Invalid value or nickname out of allowed range
  • 401 Unauthorized: Invalid or expired token
  • 500 Internal Server Error: General server error

POST /settings

Fetches user settings.

Request

Body:

{ `{
  "token": "JWT token"
}` }

Responses

{ $( `{
  "uuid": "string", /* the user uuid */
  "nickname": "string", /* the user's set nickname */
  "prompt_data": { "system": "string" }, /* the custom system prompt */
  "site_prefs": { "model": "string" },  /* the user preferred model */
  "chat_files": { "files": [ { "id": "string", "name": "string" } ] }, /* list of user's chat files */
}` )[0] }
  • 200 OK: Returns user preferences
  • 401 Unauthorized: Invalid or expired token
  • 500 Internal Server Error: No user data found

POST /create-chat

Creates a new chat file for the user.

Request

Body:

{ `{
  "token": "JWT token"
}` }

Responses

{ $( `{
  "status": "ok" | "nodata" | "error",
  "msg": "chat created" | "error message",
  "chatId": "string" /* the uuid/filename of the newly created chat. */
}` )[0] }
  • 200 OK: Chat created with ID and topic name
  • 400 Bad Request: Missing user data
  • 401 Unauthorized: Invalid or expired token
  • 500 Internal Server Error: Error creating chat file or updating database

POST /get-chat

Fetches the contents of a specified chat file.

Request

Body:

{ $( `{
  "token": "JWT token",
  "chatId": "string" /* chat file uuid */
}` )[0] }

Responses

~
{ `{
  "status": "ok" | "error",
  "msg": "chat not found" | "error message",
  "contents": [ { }, ... ]
}` }
  • 200 OK: Returns chat file contents
  • 401 Unauthorized: Invalid or expired token
  • 404 Not Found: Chat does not exist
  • 500 Internal Server Error: User data not found

POST /models

Lists available models for chat.

Request

Body:

{ `{
  "token": "JWT token"
}` }

Responses

  • 200 OK: Returns list of models with their attributes
  • 401 Unauthorized: Invalid or expired token

POST /generate

Generates text based on the input prompt. Can optionally be used for in-the-middle generation.

Request

Body:

{ $( `{
  "token": "JWT token",
  "prompt": "string", /* the text before the generated text */
  "suffix": "string", /* optional - the text after the generated text */
  "model": "string",
  "options": { "seed": Number, "temperature": Number } /* optional */
}` )[0] }

Response

Body:

{ $( `{
  "status": "ok" | "error",
  "response": "string",
  "finalMsg": "string" /* optional - only at the end of chunked transmission */
}` )[0] }
  • 200 OK: Returns streamed chat response
  • 400 Bad Request: Missing required parameters
  • 401 Unauthorized: Invalid or expired token
  • 429 Too Many Requests: A request from this user is already being processed
  • 504 Gateway Timeout: No chat instance available
  • 500 Internal Server Error: Chat server error

POST /chat

Sends a message to the chat server and streams the response back to the user.

Request

Body:

{ $( `{
  "token": "JWT token",
  "model": "string",
  "messages": [ {
    "role": "user" | "assistant" | "tool" | "system",
    "content": "string",
    timestamp: "string"
  } ],
  "system": "string",  /* optional */
  "options": { "seed": Number, "temperature": Number }, /* optional */
  "chatfile": "string" /* optional - chat file uuid */
}` )[0] }

Responses

Message:

{ `{
  "status": "ok" | "error",
  "msg": "string",
  "done": false,
  "tool": "string"
}` }

End:

{ `{
  "status": "ok" | "error",
  "msg": "string",
  "fullMsg": "full message returned by the model",
  "done": true | false
}` }
  • 200 OK: Returns streamed chat response
  • 400 Bad Request: Missing required parameters
  • 401 Unauthorized: Invalid or expired token
  • 429 Too Many Requests: A request from this user is already being processed
  • 504 Gateway Timeout: No chat instance available
  • 500 Internal Server Error: Chat server error
}