Skip to content

Commit

Permalink
feat: add models API endpoints (#52)
Browse files Browse the repository at this point in the history
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Han Xiao <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and hanxiao authored Feb 10, 2025
1 parent a1b7c85 commit 1dc73f2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
ChatCompletionResponse,
ChatCompletionChunk,
AnswerAction,
TOKEN_CATEGORIES
TOKEN_CATEGORIES,
Model
} from './types';
import fs from 'fs/promises';
import path from 'path';
Expand Down Expand Up @@ -119,6 +120,44 @@ async function completeCurrentStreaming(
}

// 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) => {
// Check authentication only if secret is set
if (secret) {
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ export interface StreamMessage {
}

// OpenAI API Types
export interface Model {
id: string;
object: 'model';
created: number;
owned_by: string;
}

export interface ChatCompletionRequest {
model: string;
messages: Array<{
Expand Down

0 comments on commit 1dc73f2

Please sign in to comment.