feat: add swagger /docs to localhost:1337 (#1268)
## Description As a user, I would like to see all supported APIs and test them out. Local swagger hosted at /docs would be helpful.
This commit is contained in:
parent
960936e348
commit
b70c21490e
@ -27,6 +27,6 @@ Jan runs on port `1337` by default, but this can be changed in Settings.
|
|||||||
Check out the [API Reference](/api-reference) for more information on the API endpoints.
|
Check out the [API Reference](/api-reference) for more information on the API endpoints.
|
||||||
|
|
||||||
```
|
```
|
||||||
curl https://localhost:1337/v1/chat/completions
|
curl http://localhost:1337/v1/chat/completions
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
@ -14,7 +14,7 @@ license:
|
|||||||
name: AGPLv3
|
name: AGPLv3
|
||||||
url: "https://github.com/janhq/nitro/blob/main/LICENSE"
|
url: "https://github.com/janhq/nitro/blob/main/LICENSE"
|
||||||
servers:
|
servers:
|
||||||
- url: "https://localhost:1337/v1/"
|
- url: "http://localhost:1337/v1/"
|
||||||
tags:
|
tags:
|
||||||
- name: Models
|
- name: Models
|
||||||
description: List and describe the various models available in the API.
|
description: List and describe the various models available in the API.
|
||||||
@ -100,7 +100,7 @@ paths:
|
|||||||
x-codeSamples:
|
x-codeSamples:
|
||||||
- lang: cURL
|
- lang: cURL
|
||||||
source: |
|
source: |
|
||||||
curl https://localhost:1337/v1/models
|
curl http://localhost:1337/v1/models
|
||||||
post:
|
post:
|
||||||
operationId: downloadModel
|
operationId: downloadModel
|
||||||
tags:
|
tags:
|
||||||
@ -118,7 +118,7 @@ paths:
|
|||||||
x-codeSamples:
|
x-codeSamples:
|
||||||
- lang: cURL
|
- lang: cURL
|
||||||
source: |
|
source: |
|
||||||
curl -X POST https://localhost:1337/v1/models
|
curl -X POST http://localhost:1337/v1/models
|
||||||
"/models/{model_id}":
|
"/models/{model_id}":
|
||||||
get:
|
get:
|
||||||
operationId: retrieveModel
|
operationId: retrieveModel
|
||||||
@ -149,7 +149,7 @@ paths:
|
|||||||
x-codeSamples:
|
x-codeSamples:
|
||||||
- lang: cURL
|
- lang: cURL
|
||||||
source: |
|
source: |
|
||||||
curl https://localhost:1337/v1/models/{model_id}
|
curl http://localhost:1337/v1/models/{model_id}
|
||||||
delete:
|
delete:
|
||||||
operationId: deleteModel
|
operationId: deleteModel
|
||||||
tags:
|
tags:
|
||||||
@ -178,7 +178,7 @@ paths:
|
|||||||
x-codeSamples:
|
x-codeSamples:
|
||||||
- lang: cURL
|
- lang: cURL
|
||||||
source: |
|
source: |
|
||||||
curl -X DELETE https://localhost:1337/v1/models/{model_id}
|
curl -X DELETE http://localhost:1337/v1/models/{model_id}
|
||||||
"/models/{model_id}/start":
|
"/models/{model_id}/start":
|
||||||
put:
|
put:
|
||||||
operationId: startModel
|
operationId: startModel
|
||||||
@ -206,7 +206,7 @@ paths:
|
|||||||
x-codeSamples:
|
x-codeSamples:
|
||||||
- lang: cURL
|
- lang: cURL
|
||||||
source: |
|
source: |
|
||||||
curl -X PUT https://localhost:1337/v1/models/{model_id}/start
|
curl -X PUT http://localhost:1337/v1/models/{model_id}/start
|
||||||
"/models/{model_id}/stop":
|
"/models/{model_id}/stop":
|
||||||
put:
|
put:
|
||||||
operationId: stopModel
|
operationId: stopModel
|
||||||
@ -233,7 +233,7 @@ paths:
|
|||||||
x-codeSamples:
|
x-codeSamples:
|
||||||
- lang: cURL
|
- lang: cURL
|
||||||
source: |
|
source: |
|
||||||
curl -X PUT https://localhost:1337/v1/models/{model_id}/stop
|
curl -X PUT http://localhost:1337/v1/models/{model_id}/stop
|
||||||
/threads:
|
/threads:
|
||||||
post:
|
post:
|
||||||
operationId: createThread
|
operationId: createThread
|
||||||
|
|||||||
@ -10,6 +10,23 @@ const JAN_API_PORT = Number.parseInt(process.env.JAN_API_PORT || "1337");
|
|||||||
|
|
||||||
const server = fastify();
|
const server = fastify();
|
||||||
server.register(require("@fastify/cors"), {});
|
server.register(require("@fastify/cors"), {});
|
||||||
|
server.register(require("@fastify/swagger"), {
|
||||||
|
mode: "static",
|
||||||
|
specification: {
|
||||||
|
path: "./../docs/openapi/jan.yaml",
|
||||||
|
baseDir: "./../docs/openapi",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
server.register(require("@fastify/swagger-ui"), {
|
||||||
|
routePrefix: "/docs",
|
||||||
|
baseDir: path.join(__dirname, "../..", "./docs/openapi"),
|
||||||
|
uiConfig: {
|
||||||
|
docExpansion: "full",
|
||||||
|
deepLinking: false,
|
||||||
|
},
|
||||||
|
staticCSP: true,
|
||||||
|
transformSpecificationClone: true,
|
||||||
|
});
|
||||||
server.register(
|
server.register(
|
||||||
(childContext, _, done) => {
|
(childContext, _, done) => {
|
||||||
childContext.register(require("@fastify/static"), {
|
childContext.register(require("@fastify/static"), {
|
||||||
|
|||||||
@ -19,6 +19,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/cors": "^8.4.2",
|
"@fastify/cors": "^8.4.2",
|
||||||
"@fastify/static": "^6.12.0",
|
"@fastify/static": "^6.12.0",
|
||||||
|
"@fastify/swagger": "^8.13.0",
|
||||||
|
"@fastify/swagger-ui": "^2.0.1",
|
||||||
"@janhq/core": "link:./core",
|
"@janhq/core": "link:./core",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"fastify": "^4.24.3",
|
"fastify": "^4.24.3",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user