Skip to content

Commit 086de94

Browse files
committed
feat: DeepSeek Code Server - REST API version
- Add FastAPI server with REST endpoints - Add session management API - Add project management API - Add multi-tenant support documentation - Add Docker deployment guide
1 parent 3c05b2b commit 086de94

16 files changed

Lines changed: 350 additions & 333 deletions

README.md

Lines changed: 211 additions & 325 deletions
Large diffs are not rendered by default.

deepseek_code_server/server.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
"""DeepSeek Code Server - REST API Server."""
2+
3+
import os
4+
from typing import Any
5+
6+
import typer
7+
from fastapi import FastAPI, HTTPException
8+
from pydantic import BaseModel
9+
10+
app = FastAPI(
11+
title="DeepSeek Code Server",
12+
description="AI Coding Assistant REST API Server",
13+
version="0.1.0",
14+
)
15+
16+
# Initialize CLI
17+
cli = typer.Typer(help="DeepSeek Code Server CLI")
18+
19+
20+
class SessionCreate(BaseModel):
21+
project_id: str
22+
model: str = "deepseek-chat"
23+
trust_mode: bool = False
24+
max_turns: int = 50
25+
26+
27+
class MessageCreate(BaseModel):
28+
content: str
29+
30+
31+
class HealthResponse(BaseModel):
32+
status: str
33+
version: str
34+
35+
36+
@app.get("/health", response_model=HealthResponse)
37+
async def health_check() -> dict[str, str]:
38+
"""Health check endpoint."""
39+
return {"status": "healthy", "version": "0.1.0"}
40+
41+
42+
@app.post("/api/sessions")
43+
async def create_session(session: SessionCreate) -> dict[str, Any]:
44+
"""Create a new coding session."""
45+
import uuid
46+
session_id = f"sess_{uuid.uuid4().hex[:12]}"
47+
return {
48+
"id": session_id,
49+
"project_id": session.project_id,
50+
"model": session.model,
51+
"trust_mode": session.trust_mode,
52+
"max_turns": session.max_turns,
53+
"created_at": "2025-01-01T00:00:00Z",
54+
"status": "active",
55+
}
56+
57+
58+
@app.get("/api/sessions")
59+
async def list_sessions() -> dict[str, list]:
60+
"""List all sessions."""
61+
return {"sessions": []}
62+
63+
64+
@app.get("/api/sessions/{session_id}")
65+
async def get_session(session_id: str) -> dict[str, Any]:
66+
"""Get session by ID."""
67+
return {
68+
"id": session_id,
69+
"project_id": "default",
70+
"messages": [],
71+
"status": "active",
72+
}
73+
74+
75+
@app.delete("/api/sessions/{session_id}")
76+
async def delete_session(session_id: str) -> dict[str, str]:
77+
"""Delete a session."""
78+
return {"status": "deleted", "session_id": session_id}
79+
80+
81+
@app.post("/api/sessions/{session_id}/messages")
82+
async def send_message(session_id: str, message: MessageCreate) -> dict[str, Any]:
83+
"""Send a message to a session."""
84+
return {
85+
"id": f"msg_{uuid.uuid4().hex[:12]}",
86+
"session_id": session_id,
87+
"content": message.content,
88+
"response": f"Echo: {message.content}",
89+
"tool_calls": [],
90+
}
91+
92+
93+
@app.get("/api/projects")
94+
async def list_projects() -> dict[str, list]:
95+
"""List all projects."""
96+
return {"projects": []}
97+
98+
99+
@app.post("/api/projects")
100+
async def create_project(project_id: str) -> dict[str, str]:
101+
"""Create a new project."""
102+
return {"id": project_id, "status": "created"}
103+
104+
105+
# Need uuid for the message endpoint
106+
import uuid
107+
108+
109+
@cli.command()
110+
def main(
111+
host: str = typer.Option("0.0.0.0", help="Server host"),
112+
port: int = typer.Option(8000, help="Server port"),
113+
reload: bool = typer.Option(False, help="Enable auto-reload"),
114+
) -> None:
115+
"""Start the DeepSeek Code Server."""
116+
import uvicorn
117+
118+
typer.echo(f"Starting DeepSeek Code Server on {host}:{port}")
119+
typer.echo("API Documentation: http://localhost:8000/docs")
120+
121+
uvicorn.run(
122+
"deepseek_code_server.server:app",
123+
host=host,
124+
port=port,
125+
reload=reload,
126+
)
127+
128+
129+
if __name__ == "__main__":
130+
cli()

0 commit comments

Comments
 (0)