Skip to content

Commit

Permalink
fix: update docs and auth behavior
Browse files Browse the repository at this point in the history
- Remove outdated web server section from README
- Keep OpenAI-compatible API documentation
- Fix authentication to be optional when no secret is set

Co-Authored-By: Han Xiao <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and hanxiao committed Feb 9, 2025
1 parent 39579d5 commit b0558e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 50 deletions.
58 changes: 16 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ export DEFAULT_MODEL_NAME=qwen2.5-7b # your local llm model name
```


## Web Server API
## Server API

### OpenAI-Compatible Chat Completions

Start the server:
```bash
Expand All @@ -114,10 +116,9 @@ npm run serve
npm run serve --secret=your_secret_token
```

The server will start on http://localhost:3000 with the following endpoints:
The server will start on http://localhost:3000 with the following endpoint:

### POST /v1/chat/completions
OpenAI-compatible chat completions endpoint:
#### POST /v1/chat/completions
```bash
# Without authentication
curl http://localhost:3000/v1/chat/completions \
Expand Down Expand Up @@ -205,60 +206,33 @@ Note: The think content in streaming responses is wrapped in XML tags:
[final answer]
```

### POST /api/v1/query
Submit a query to be answered:
```bash
curl -X POST http://localhost:3000/api/v1/query \
-H "Content-Type: application/json" \
-d '{
"q": "what is the capital of France?",
"budget": 1000000,
"maxBadAttempt": 3
}'
```

Response:
```json
{
"requestId": "1234567890"
}
```
## Server Setup

### GET /api/v1/stream/:requestId
Connect to the Server-Sent Events stream to receive progress updates and the final answer:
### Local Setup
Start the server:
```bash
curl -N http://localhost:3000/api/v1/stream/1234567890
```

The server will emit the following event types:
- Progress updates: Step number and budget usage
- Final answer with complete response data
- Error messages if something goes wrong

Example events:
```
data: {"type":"progress","trackers":{"tokenUsage":74950,"tokenBreakdown":{"agent":64631,"read":10319},"actionState":{"action":"search","think":"The provided text mentions several investors in Jina AI but doesn't specify ownership percentages. A direct search for ownership percentages is needed to answer the question definitively.","URLTargets":[],"answer":"","questionsToAnswer":[],"references":[],"searchQuery":"Jina AI investor ownership percentages"},"step":7,"badAttempts":0,"gaps":[]}}
data: {"type":"progress","trackers":{"tokenUsage":74950,"tokenBreakdown":{"agent":64631,"read":10319},"actionState":{"action":"search","think":"The provided text mentions several investors in Jina AI's funding rounds but doesn't specify ownership percentages. A search focusing on equity stakes and ownership percentages held by each investor will provide the necessary information to answer the main question.","URLTargets":[],"answer":"","questionsToAnswer":[],"references":[],"searchQuery":"Jina AI investor equity percentage ownership stake"},"step":8,"badAttempts":0,"gaps":[]}}
# Without authentication
npm run serve

data: {"type":"progress","trackers":{"tokenUsage":88096,"tokenBreakdown":{"agent":77777,"read":10319},"actionState":{"action":"search","think":"The provided text mentions several investors in Jina AI's funding rounds but doesn't specify ownership percentages. A search focusing on equity stakes and ownership percentages held by each investor will provide the necessary information to answer the main question.","URLTargets":[],"answer":"","questionsToAnswer":[],"references":[],"searchQuery":"Jina AI investor equity percentage ownership stake"},"step":8,"badAttempts":0,"gaps":[]}}
# With authentication (clients must provide this secret as Bearer token)
npm run serve --secret=your_secret_token
```

## Docker
### Docker Setup

### Build Docker Image
#### Build Docker Image
To build the Docker image for the application, run the following command:
```bash
docker build -t deepresearch:latest .
```

### Run Docker Container
#### Run Docker Container
To run the Docker container, use the following command:
```bash
docker run -p 3000:3000 --env GEMINI_API_KEY=your_gemini_api_key --env JINA_API_KEY=your_jina_api_key deepresearch:latest
```

### Docker Compose
#### Docker Compose
You can also use Docker Compose to manage multi-container applications. To start the application with Docker Compose, run:
```bash
docker-compose up
Expand Down
14 changes: 6 additions & 8 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ interface QueryRequest extends Request {

// OpenAI-compatible chat completions endpoint
app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
// Check authentication if secret is set
if (secret) {
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Bearer ') || authHeader.split(' ')[1] !== secret) {
console.log('[chat/completions] Unauthorized request');
res.status(401).json({ error: 'Unauthorized' });
return;
}
// Check authentication only if secret is set
const authHeader = req.headers.authorization;
if (secret && (!authHeader || !authHeader.startsWith('Bearer ') || authHeader.split(' ')[1] !== secret)) {
console.log('[chat/completions] Unauthorized request');
res.status(401).json({ error: 'Unauthorized' });
return;
}

// Log request details (excluding sensitive data)
Expand Down

0 comments on commit b0558e8

Please sign in to comment.