From e7fcd775fbc01ce6e2449100205a43c2101ce271 Mon Sep 17 00:00:00 2001 From: NamH Date: Sun, 14 Jan 2024 21:41:18 +0700 Subject: [PATCH] fix(API): #1511 update swagger page (#1572) Signed-off-by: James Co-authored-by: James --- core/src/node/api/common/builder.ts | 8 +- docs/openapi/jan.yaml | 404 ++-------------------------- docs/openapi/specs/models.yaml | 14 +- docs/openapi/specs/threads.yaml | 57 ++++ 4 files changed, 90 insertions(+), 393 deletions(-) diff --git a/core/src/node/api/common/builder.ts b/core/src/node/api/common/builder.ts index dbc52b430..3291e4217 100644 --- a/core/src/node/api/common/builder.ts +++ b/core/src/node/api/common/builder.ts @@ -59,7 +59,7 @@ export const retrieveBuilder = async (configuration: RouteConfiguration, id: str const filteredData = data.filter((d: any) => d.id === id)[0] if (!filteredData) { - return {} + return undefined } return filteredData @@ -75,14 +75,14 @@ export const deleteBuilder = async (configuration: RouteConfiguration, id: strin const directoryPath = join(path, configuration.dirName) try { const data = await retrieveBuilder(configuration, id) - if (!data || !data.keys) { + if (!data) { return { message: 'Not found', } } - const myPath = join(directoryPath, id) - fs.rmdirSync(myPath, { recursive: true }) + const objectPath = join(directoryPath, id) + fs.rmdirSync(objectPath, { recursive: true }) return { id: id, object: configuration.delete.object, diff --git a/docs/openapi/jan.yaml b/docs/openapi/jan.yaml index fc3e7ccc8..e3463c94c 100644 --- a/docs/openapi/jan.yaml +++ b/docs/openapi/jan.yaml @@ -104,13 +104,23 @@ paths: - lang: cURL source: | curl http://localhost:1337/v1/models - post: + "/models/download/{model_id}": + get: operationId: downloadModel tags: - Models - summary: Download model + summary: Download a specific model. description: | 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: "200": description: OK @@ -121,7 +131,7 @@ paths: x-codeSamples: - lang: cURL source: | - curl -X POST http://localhost:1337/v1/models + curl -X POST http://localhost:1337/v1/models/download/{model_id} "/models/{model_id}": get: operationId: retrieveModel @@ -139,7 +149,7 @@ paths: required: true schema: type: string - example: zephyr-7b + example: mistral-ins-7b-q4 description: | The ID of the model to use for this request. responses: @@ -164,13 +174,13 @@ paths: Equivalent to OpenAI's delete model. parameters: - in: path - name: model + name: model_id required: true schema: type: string - example: zephyr-7b + example: mistral-ins-7b-q4 description: | - The model to delete + The model id to delete responses: "200": description: OK @@ -182,61 +192,6 @@ paths: - lang: cURL source: | 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: post: operationId: createThread @@ -252,13 +207,7 @@ paths: content: application/json: schema: - type: object - properties: - messages: - type: array - description: Initial set of messages for the thread. - items: - $ref: specs/threads.yaml#/components/schemas/ThreadMessageObject + $ref: specs/threads.yaml#/components/schemas/CreateThreadObject responses: "200": description: Thread created successfully @@ -334,7 +283,6 @@ paths: required: true schema: type: string - example: thread_abc123 description: | The ID of the thread to retrieve. responses: @@ -348,7 +296,7 @@ paths: - lang: cURL source: | curl http://localhost:1337/v1/threads/{thread_id} - post: + patch: operationId: modifyThread tags: - Threads @@ -363,19 +311,18 @@ paths: required: true schema: type: string - example: thread_abc123 description: | The ID of the thread to be modified. requestBody: - required: false + required: true content: application/json: schema: type: object properties: - messages: - type: array - description: Set of messages to update in the thread. + title: + type: string + description: Set the title of the thread items: $ref: specs/threads.yaml#/components/schemas/ThreadMessageObject responses: @@ -415,7 +362,6 @@ paths: required: true schema: type: string - example: thread_abc123 description: | The ID of the thread to be deleted. responses: @@ -429,70 +375,7 @@ paths: - lang: cURL source: | curl -X DELETE http://localhost:1337/v1/threads/{thread_id} - "/threads/{thread_id}/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/: + /assistants: get: operationId: listAssistants tags: @@ -504,7 +387,7 @@ paths: Equivalent to OpenAI's list assistants. responses: "200": - description: List of threads retrieved successfully + description: List of assistants retrieved successfully content: application/json: schema: @@ -538,57 +421,11 @@ paths: in: [] out: [] metadata: {} - responses: null x-codeSamples: - lang: cURL source: | curl http://localhost:1337/v1/assistants \ -H "Content-Type: application/json" \ - post: - operationId: createAssistant - tags: - - Assistants - summary: Create assistant - description: > - Create an assistant with a model and instructions. - Equivalent to OpenAI's create assistants. - 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}": get: operationId: getAssistant @@ -605,7 +442,7 @@ paths: required: true schema: type: string - example: asst_abc123 + example: jan description: | The ID of the assistant to retrieve. responses: @@ -620,99 +457,6 @@ paths: source: | curl http://localhost:1337/v1/assistants/{assistant_id} \ -H "Content-Type: application/json" \ - post: - operationId: modifyAssistant - tags: - - Assistants - summary: Modify assistant - description: > - Modifies an assistant. - Equivalent to OpenAI's modify assistant. - 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. - Equivalent to OpenAI's delete assistant. - 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": get: operationId: listMessages @@ -729,7 +473,6 @@ paths: required: true schema: type: string - example: thread_abc123 description: | The ID of the thread from which to retrieve messages. responses: @@ -759,7 +502,6 @@ paths: required: true schema: type: string - example: thread_abc123 description: | The ID of the thread to which the message will be posted. requestBody: @@ -818,7 +560,6 @@ paths: required: true schema: type: string - example: thread_abc123 description: | The ID of the thread containing the message. - in: path @@ -826,7 +567,6 @@ paths: required: true schema: type: string - example: msg_abc123 description: | The ID of the message to retrieve. responses: @@ -842,98 +582,6 @@ paths: curl http://localhost:1337/v1/threads/{thread_id}/messages/{message_id} \ -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. - Equivalent to OpenAI's list message files. - 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. - Equivalent to OpenAI's retrieve message file. - 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: ModelObject: post: diff --git a/docs/openapi/specs/models.yaml b/docs/openapi/specs/models.yaml index 3bf524f79..418be9563 100644 --- a/docs/openapi/specs/models.yaml +++ b/docs/openapi/specs/models.yaml @@ -377,15 +377,7 @@ components: DownloadModelResponse: type: object properties: - id: + message: type: string - description: The identifier of the model that was started. - example: model-zephyr-7B - 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 \ No newline at end of file + description: Message indicates Jan starting download corresponding model. + example: Starting download mistral-ins-7b-q4 diff --git a/docs/openapi/specs/threads.yaml b/docs/openapi/specs/threads.yaml index b04839cc6..fe00f7588 100644 --- a/docs/openapi/specs/threads.yaml +++ b/docs/openapi/specs/threads.yaml @@ -112,6 +112,63 @@ components: type: object description: Metadata associated with the newly created thread. 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: type: object properties: