fix(API): #1511 update swagger page (#1572)

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
This commit is contained in:
NamH 2024-01-14 21:41:18 +07:00 committed by GitHub
parent 4a2f5bce8d
commit e7fcd775fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 393 deletions

View File

@ -59,7 +59,7 @@ export const retrieveBuilder = async (configuration: RouteConfiguration, id: str
const filteredData = data.filter((d: any) => d.id === id)[0] const filteredData = data.filter((d: any) => d.id === id)[0]
if (!filteredData) { if (!filteredData) {
return {} return undefined
} }
return filteredData return filteredData
@ -75,14 +75,14 @@ export const deleteBuilder = async (configuration: RouteConfiguration, id: strin
const directoryPath = join(path, configuration.dirName) const directoryPath = join(path, configuration.dirName)
try { try {
const data = await retrieveBuilder(configuration, id) const data = await retrieveBuilder(configuration, id)
if (!data || !data.keys) { if (!data) {
return { return {
message: 'Not found', message: 'Not found',
} }
} }
const myPath = join(directoryPath, id) const objectPath = join(directoryPath, id)
fs.rmdirSync(myPath, { recursive: true }) fs.rmdirSync(objectPath, { recursive: true })
return { return {
id: id, id: id,
object: configuration.delete.object, object: configuration.delete.object,

View File

@ -104,13 +104,23 @@ paths:
- lang: cURL - lang: cURL
source: | source: |
curl http://localhost:1337/v1/models curl http://localhost:1337/v1/models
post: "/models/download/{model_id}":
get:
operationId: downloadModel operationId: downloadModel
tags: tags:
- Models - Models
summary: Download model summary: Download a specific model.
description: | description: |
Download a model. Download a model.
parameters:
- in: path
name: model_id
required: true
schema:
type: string
example: mistral-ins-7b-q4
description: |
The ID of the model to use for this request.
responses: responses:
"200": "200":
description: OK description: OK
@ -121,7 +131,7 @@ paths:
x-codeSamples: x-codeSamples:
- lang: cURL - lang: cURL
source: | source: |
curl -X POST http://localhost:1337/v1/models curl -X POST http://localhost:1337/v1/models/download/{model_id}
"/models/{model_id}": "/models/{model_id}":
get: get:
operationId: retrieveModel operationId: retrieveModel
@ -139,7 +149,7 @@ paths:
required: true required: true
schema: schema:
type: string type: string
example: zephyr-7b example: mistral-ins-7b-q4
description: | description: |
The ID of the model to use for this request. The ID of the model to use for this request.
responses: responses:
@ -164,13 +174,13 @@ paths:
Equivalent to OpenAI's delete model. </a> Equivalent to OpenAI's delete model. </a>
parameters: parameters:
- in: path - in: path
name: model name: model_id
required: true required: true
schema: schema:
type: string type: string
example: zephyr-7b example: mistral-ins-7b-q4
description: | description: |
The model to delete The model id to delete
responses: responses:
"200": "200":
description: OK description: OK
@ -182,61 +192,6 @@ paths:
- lang: cURL - lang: cURL
source: | source: |
curl -X DELETE http://localhost:1337/v1/models/{model_id} curl -X DELETE http://localhost:1337/v1/models/{model_id}
"/models/{model_id}/start":
put:
operationId: startModel
tags:
- Models
summary: Start model
description: |
Starts an imported model. Loads the model into V/RAM.
parameters:
- in: path
name: model
required: true
schema:
type: string
example: zephyr-7b
description: |
The ID of the model to use for this request
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: specs/models.yaml#/components/schemas/StartModelResponse
x-codeSamples:
- lang: cURL
source: |
curl -X PUT http://localhost:1337/v1/models/{model_id}/start
"/models/{model_id}/stop":
put:
operationId: stopModel
tags:
- Models
summary: Stop model
description: |
Stop an imported model.
parameters:
- in: path
name: model
required: true
schema:
type: string
example: zephyr-7b
description: The ID of the model to use for this request
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: specs/models.yaml#/components/schemas/StopModelResponse
x-codeSamples:
- lang: cURL
source: |
curl -X PUT http://localhost:1337/v1/models/{model_id}/stop
/threads: /threads:
post: post:
operationId: createThread operationId: createThread
@ -252,13 +207,7 @@ paths:
content: content:
application/json: application/json:
schema: schema:
type: object $ref: specs/threads.yaml#/components/schemas/CreateThreadObject
properties:
messages:
type: array
description: Initial set of messages for the thread.
items:
$ref: specs/threads.yaml#/components/schemas/ThreadMessageObject
responses: responses:
"200": "200":
description: Thread created successfully description: Thread created successfully
@ -334,7 +283,6 @@ paths:
required: true required: true
schema: schema:
type: string type: string
example: thread_abc123
description: | description: |
The ID of the thread to retrieve. The ID of the thread to retrieve.
responses: responses:
@ -348,7 +296,7 @@ paths:
- lang: cURL - lang: cURL
source: | source: |
curl http://localhost:1337/v1/threads/{thread_id} curl http://localhost:1337/v1/threads/{thread_id}
post: patch:
operationId: modifyThread operationId: modifyThread
tags: tags:
- Threads - Threads
@ -363,19 +311,18 @@ paths:
required: true required: true
schema: schema:
type: string type: string
example: thread_abc123
description: | description: |
The ID of the thread to be modified. The ID of the thread to be modified.
requestBody: requestBody:
required: false required: true
content: content:
application/json: application/json:
schema: schema:
type: object type: object
properties: properties:
messages: title:
type: array type: string
description: Set of messages to update in the thread. description: Set the title of the thread
items: items:
$ref: specs/threads.yaml#/components/schemas/ThreadMessageObject $ref: specs/threads.yaml#/components/schemas/ThreadMessageObject
responses: responses:
@ -415,7 +362,6 @@ paths:
required: true required: true
schema: schema:
type: string type: string
example: thread_abc123
description: | description: |
The ID of the thread to be deleted. The ID of the thread to be deleted.
responses: responses:
@ -429,70 +375,7 @@ paths:
- lang: cURL - lang: cURL
source: | source: |
curl -X DELETE http://localhost:1337/v1/threads/{thread_id} curl -X DELETE http://localhost:1337/v1/threads/{thread_id}
"/threads/{thread_id}/assistants": /assistants:
get:
operationId: getThreadAssistants
tags:
- Threads
summary: Get Thread.Assistants
description: |
Can achieve this goal by calling Get thread API.
parameters:
- in: path
name: thread_id
required: true
schema:
type: string
example: thread_abc123
description: The ID of the thread to retrieve.
responses:
"200":
description: Thread details retrieved successfully
content:
application/json:
schema:
$ref: specs/threads.yaml#/components/schemas/GetThreadResponse
x-codeSamples:
- lang: cURL
source: |
curl http://localhost:1337/v1/threads/{thread_id}/assistants
"/threads/{thread_id}/assistants/{assistants_id}":
post:
operationId: postThreadAssistants
tags:
- Threads
summary: Modify Thread.Assistants
description: >
Can achieve this goal by calling Modify Assistant API with
thread.assistant[].
"/threads/{thread_id}/":
get:
operationId: listThreadMessage
tags:
- Threads
summary: List Thread.Messages
description: |
Can achieve this goal by calling Get Thread API.
parameters:
- in: path
name: thread_id
required: true
schema:
type: string
example: thread_abc123
description: The ID of the thread to retrieve.
responses:
"200":
description: Thread details retrieved successfully
content:
application/json:
schema:
$ref: specs/threads.yaml#/components/schemas/GetThreadResponse
x-codeSamples:
- lang: cURL
source: |
curl http://localhost:1337/v1/threads/{thread_id}
/assistants/:
get: get:
operationId: listAssistants operationId: listAssistants
tags: tags:
@ -504,7 +387,7 @@ paths:
Equivalent to OpenAI's list assistants. </a> Equivalent to OpenAI's list assistants. </a>
responses: responses:
"200": "200":
description: List of threads retrieved successfully description: List of assistants retrieved successfully
content: content:
application/json: application/json:
schema: schema:
@ -538,57 +421,11 @@ paths:
in: [] in: []
out: [] out: []
metadata: {} metadata: {}
responses: null
x-codeSamples: x-codeSamples:
- lang: cURL - lang: cURL
source: | source: |
curl http://localhost:1337/v1/assistants \ curl http://localhost:1337/v1/assistants \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
post:
operationId: createAssistant
tags:
- Assistants
summary: Create assistant
description: >
Create an assistant with a model and instructions. <a href =
"https://platform.openai.com/docs/api-reference/assistants/createAssistant">
Equivalent to OpenAI's create assistants. </a>
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
models:
type: array
description: List of models associated with the assistant. Jan-specific
property.
items:
type: object
properties:
model_id:
type: string
example: model_0
responses:
"200":
description: null
content:
application/json:
schema:
$ref: specs/assistants.yaml#/components/schemas/CreateAssistantResponse
x-codeSamples:
- lang: cURL
source: |
curl http://localhost:1337/v1/assistants \
-H "Content-Type: application/json" \
-d '{
"models": [
{
"model_id": "model_0"
}
]
}'
"/assistants/{assistant_id}": "/assistants/{assistant_id}":
get: get:
operationId: getAssistant operationId: getAssistant
@ -605,7 +442,7 @@ paths:
required: true required: true
schema: schema:
type: string type: string
example: asst_abc123 example: jan
description: | description: |
The ID of the assistant to retrieve. The ID of the assistant to retrieve.
responses: responses:
@ -620,99 +457,6 @@ paths:
source: | source: |
curl http://localhost:1337/v1/assistants/{assistant_id} \ curl http://localhost:1337/v1/assistants/{assistant_id} \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
post:
operationId: modifyAssistant
tags:
- Assistants
summary: Modify assistant
description: >
Modifies an assistant. <a href =
"https://platform.openai.com/docs/api-reference/assistants/modifyAssistant">
Equivalent to OpenAI's modify assistant. </a>
parameters:
- in: path
name: assistant_id
required: true
schema:
type: string
example: asst_abc123
description: |
The ID of the assistant to modify.
requestBody:
required: false
content:
application/json:
schema:
type: object
properties:
models:
type: array
description: List of models associated with the assistant. Jan-specific
property.
items:
type: object
properties:
model_id:
type: string
example: model_0
name:
type: string
description: Name of the assistant.
example: Physics Tutor
instructions:
type: string
description: A system prompt for the assistant.
example: Be concise!
responses:
"200":
description: null
content:
application/json:
schema:
$ref: specs/assistants.yaml#/components/schemas/ModifyAssistantResponse
x-codeSamples:
- lang: cURL
source: |
curl http://localhost:1337/v1/assistants/{assistant_id} \
-H "Content-Type: application/json" \
-d '{
"models": [
{
"model_id": "model_0"
}
],
"name": "Physics Tutor",
"instructions": "Be concise!",
}'
delete:
operationId: deleteAssistant
tags:
- Assistants
summary: Delete assistant
description: >
Delete an assistant. <a href =
"https://platform.openai.com/docs/api-reference/assistants/deleteAssistant">
Equivalent to OpenAI's delete assistant. </a>
parameters:
- in: path
name: assistant_id
required: true
schema:
type: string
example: asst_abc123
description: |
The ID of the assistant to delete.
responses:
"200":
description: Deletion status
content:
application/json:
schema:
$ref: specs/assistants.yaml#/components/schemas/DeleteAssistantResponse
x-codeSamples:
- lang: cURL
source: |
curl -X DELETE http://localhost:1337/v1/assistants/{assistant_id}
"/threads/{thread_id}/messages": "/threads/{thread_id}/messages":
get: get:
operationId: listMessages operationId: listMessages
@ -729,7 +473,6 @@ paths:
required: true required: true
schema: schema:
type: string type: string
example: thread_abc123
description: | description: |
The ID of the thread from which to retrieve messages. The ID of the thread from which to retrieve messages.
responses: responses:
@ -759,7 +502,6 @@ paths:
required: true required: true
schema: schema:
type: string type: string
example: thread_abc123
description: | description: |
The ID of the thread to which the message will be posted. The ID of the thread to which the message will be posted.
requestBody: requestBody:
@ -818,7 +560,6 @@ paths:
required: true required: true
schema: schema:
type: string type: string
example: thread_abc123
description: | description: |
The ID of the thread containing the message. The ID of the thread containing the message.
- in: path - in: path
@ -826,7 +567,6 @@ paths:
required: true required: true
schema: schema:
type: string type: string
example: msg_abc123
description: | description: |
The ID of the message to retrieve. The ID of the message to retrieve.
responses: responses:
@ -842,98 +582,6 @@ paths:
curl http://localhost:1337/v1/threads/{thread_id}/messages/{message_id} curl http://localhost:1337/v1/threads/{thread_id}/messages/{message_id}
\ \
-H "Content-Type: application/json" -H "Content-Type: application/json"
"/threads/{thread_id}/messages/{message_id}/files":
get:
operationId: listMessageFiles
tags:
- Messages
summary: |
List message files
description: >
Returns a list of message files. <a href =
"https://platform.openai.com/docs/api-reference/messages/listMessageFiles">
Equivalent to OpenAI's list message files. </a>
parameters:
- in: path
name: thread_id
required: true
schema:
type: string
example: thread_abc123
description: |
The ID of the thread containing the message.
- in: path
name: message_id
required: true
schema:
type: string
example: msg_abc123
description: |
The ID of the message whose files are to be listed.
responses:
"200":
description: List of files retrieved successfully
content:
application/json:
schema:
$ref: specs/messages.yaml#/components/schemas/ListMessageFilesResponse
x-codeSamples:
- lang: cURL
source: >
curl
http://localhost:1337/v1/threads/{thread_id}/messages/{message_id}/files
\
-H "Content-Type: application/json"
"/threads/{thread_id}/messages/{message_id}/files/{file_id}":
get:
operationId: retrieveMessageFile
tags:
- Messages
summary: Retrieve message file
description: >
Retrieves a file associated with a specific message in a
thread. <a href =
"https://platform.openai.com/docs/api-reference/messages/getMessageFile">
Equivalent to OpenAI's retrieve message file. </a>
parameters:
- in: path
name: thread_id
required: true
schema:
type: string
example: thread_abc123
description: |
The ID of the thread containing the message.
- in: path
name: message_id
required: true
schema:
type: string
example: msg_abc123
description: |
The ID of the message associated with the file.
- in: path
name: file_id
required: true
schema:
type: string
example: file-abc123
description: |
The ID of the file to retrieve.
responses:
"200":
description: File retrieved successfully
content:
application/json:
schema:
$ref: specs/messages.yaml#/components/schemas/MessageFileObject
x-codeSamples:
- lang: cURL
source: >
curl
http://localhost:1337/v1/threads/{thread_id}/messages/{message_id}/files/{file_id}
\
-H "Content-Type: application/json"
x-webhooks: x-webhooks:
ModelObject: ModelObject:
post: post:

View File

@ -377,15 +377,7 @@ components:
DownloadModelResponse: DownloadModelResponse:
type: object type: object
properties: properties:
id: message:
type: string type: string
description: The identifier of the model that was started. description: Message indicates Jan starting download corresponding model.
example: model-zephyr-7B example: Starting download mistral-ins-7b-q4
object:
type: string
description: Type of the object, indicating it's a model.
default: model
state:
type: string
description: The current state of the model after the start operation.
example: downloaded

View File

@ -112,6 +112,63 @@ components:
type: object type: object
description: Metadata associated with the newly created thread. description: Metadata associated with the newly created thread.
example: {} example: {}
CreateThreadObject:
type: object
properties:
object:
type: string
description: Type of the object, indicating it's a thread.
example: thread
title:
type: string
description: >
A brief summary or description of the thread, defaults to an empty
string.
example: funny physics joke
assistants:
type: array
description: assistant involved in the thread
items:
properties:
assistant_id:
type: string
description: |
The identifier of assistant, defaults to "jan"
example: jan
assistant_name:
type: string
description: |
The name of assistant, defaults to "Jan"
example: Jan
instructions:
type: string
description: |
The instruction of assistant, defaults to "Be my grammar corrector"
model:
type: object
properties:
id:
type: string
description: Model id
example: mistral-ins-7b-q4
settings:
type: object
description: >
Defaults to and overrides assistant.json's "settings" (and if none,
then model.json "settings")
parameters:
type: object
description: >
Defaults to and overrides assistant.json's "parameters" (and if
none, then model.json "parameters")
engine:
type: string
description: Engine id
example: nitro
metadata:
type: object
description: |
Metadata associated with the thread, defaults to an empty object.
ThreadMessageObject: ThreadMessageObject:
type: object type: object
properties: properties: