mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2026-03-22 07:29:35 +08:00
feat: add models API endpoints (#52)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Han Xiao <han.xiao@jina.ai>
This commit is contained in:
committed by
GitHub
parent
a1b7c853a7
commit
1dc73f2a18
@@ -10,7 +10,8 @@ import {
|
|||||||
ChatCompletionResponse,
|
ChatCompletionResponse,
|
||||||
ChatCompletionChunk,
|
ChatCompletionChunk,
|
||||||
AnswerAction,
|
AnswerAction,
|
||||||
TOKEN_CATEGORIES
|
TOKEN_CATEGORIES,
|
||||||
|
Model
|
||||||
} from './types';
|
} from './types';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@@ -119,6 +120,44 @@ async function completeCurrentStreaming(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OpenAI-compatible chat completions endpoint
|
// OpenAI-compatible chat completions endpoint
|
||||||
|
// Models API endpoints
|
||||||
|
app.get('/v1/models', (async (_req: Request, res: Response) => {
|
||||||
|
const models: Model[] = [{
|
||||||
|
id: 'jina-deepsearch-v1',
|
||||||
|
object: 'model',
|
||||||
|
created: 1686935002,
|
||||||
|
owned_by: 'jina-ai'
|
||||||
|
}];
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
object: 'list',
|
||||||
|
data: models
|
||||||
|
});
|
||||||
|
}) as RequestHandler);
|
||||||
|
|
||||||
|
app.get('/v1/models/:model', (async (req: Request, res: Response) => {
|
||||||
|
const modelId = req.params.model;
|
||||||
|
|
||||||
|
if (modelId === 'jina-deepsearch-v1') {
|
||||||
|
res.json({
|
||||||
|
id: 'jina-deepsearch-v1',
|
||||||
|
object: 'model',
|
||||||
|
created: 1686935002,
|
||||||
|
owned_by: 'jina-ai'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(404).json({
|
||||||
|
error: {
|
||||||
|
message: `Model '${modelId}' not found`,
|
||||||
|
type: 'invalid_request_error',
|
||||||
|
param: null,
|
||||||
|
code: 'model_not_found'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}) as RequestHandler);
|
||||||
|
|
||||||
|
|
||||||
app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
|
app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
|
||||||
// Check authentication only if secret is set
|
// Check authentication only if secret is set
|
||||||
if (secret) {
|
if (secret) {
|
||||||
|
|||||||
@@ -159,6 +159,13 @@ export interface StreamMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OpenAI API Types
|
// OpenAI API Types
|
||||||
|
export interface Model {
|
||||||
|
id: string;
|
||||||
|
object: 'model';
|
||||||
|
created: number;
|
||||||
|
owned_by: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ChatCompletionRequest {
|
export interface ChatCompletionRequest {
|
||||||
model: string;
|
model: string;
|
||||||
messages: Array<{
|
messages: Array<{
|
||||||
|
|||||||
Reference in New Issue
Block a user