deepreasoning
repository·main·Indexed 26 days ago
https://github.com/winfunc/deepreasoningA high-performance LLM inference API and Chat UI (version 0.1.0) that integrates DeepSeek R1's Chain of Thought (CoT) reasoning traces with Anthropic Claude models into a single unified stream. Built with Rust, it provides a REST API supporting streaming and non-streaming responses, token usage tracking, and cost statistics via a configurable config.toml file.
What's inside deepreasoning
- The easiest way to deploy this Next.js application is using the Vercel Platform. Refer to the official Next.js deployment documentation for detailed steps.
Run the frontend development server
mainTo start the development server for the
frontendpackage, use one of the following package manager commands. Once running, the application will be accessible athttp://localhost:3000.npm run dev # or yarn dev # or pnpm dev # or bun devInstall and build DeepReasoning
mainTo install DeepReasoning, clone the repository and build the project using Cargo.
Prerequisites:
- Rust 1.75 or higher
- DeepSeek API key
- Anthropic API key
git clone https://github.com/getasterisk/deepreasoning.git cd deepreasoning cargo build --releaseConfigure DeepReasoning via config.toml
mainCreate a
config.tomlfile in the project root to configure server settings and pricing for usage tracking.[server] host = "127.0.0.1" port = 3000 [pricing] # Configure pricing settings for usage trackingDeploy the deepreasoning API using Docker Compose
mainYou can deploy the
deepreasoning_apiservice using Docker Compose. The service builds from the local directory and exposes the API on127.0.0.1:1337.To configure the API, you must provide a local
config.tomlfile, which is mounted into the container at/usr/local/bin/config.toml.services: api: build: . container_name: deepreasoning_api restart: unless-stopped ports: - "127.0.0.1:1337:1337" volumes: - ./config.toml:/usr/local/bin/config.toml networks: - deepreasoning_network networks: deepreasoning_network: name: deepreasoning_networkRun the DeepReasoning service
mainThe DeepReasoning service is a high-performance LLM inference API that integrates DeepSeek R1's Chain-of-Thought (CoT) reasoning traces with Anthropic Claude models. It provides a REST API for chat interactions, supporting both streaming and non-streaming responses, token usage tracking, and cost statistics.
To run the service, ensure you have a
config.tomlfile available in the working directory. If the configuration file is missing, the service will attempt to use default settings.API Endpoint
POST /: The primary endpoint for chat interactions, handled byhandlers::handle_chat.
Use the DeepReasoning API (Basic Example)
mainSend a POST request to the DeepReasoning server. You must provide your DeepSeek and Anthropic API keys in the request headers using
X-DeepSeek-API-TokenandX-Anthropic-API-Token.import requests response = requests.post( "http://127.0.0.1:1337/", headers={ "X-DeepSeek-API-Token": "<YOUR_DEEPSEEK_API_KEY>", "X-Anthropic-API-Token": "<YOUR_ANTHROPIC_API_KEY>" }, json={ "messages": [ {"role": "user", "content": "How many 'r's in the word 'strawberry'?"} ] } ) print(response.json())Stream responses from the DeepReasoning API
mainTo receive a stream of responses (combining R1's CoT and Claude's response), set
"stream": truein your JSON request body. The server emits data in thedata: <json_string>format.import asyncio import json import httpx async def stream_response(): async with httpx.AsyncClient() as client: async with client.stream( "POST", "http://127.0.0.1:1337/", headers={ "X-DeepSeek-API-Token": "<YOUR_DEEPSEEK_API_KEY>", "X-Anthropic-API-Token": "<YOUR_ANTHROPIC_API_KEY>" }, json={ "stream": True, "messages": [ {"role": "user", "content": "How many 'r's in the word 'strawberry'?"} ] } ) as response: response.raise_for_status() async for line in response.aiter_lines(): if line: if line.startswith('data: '): data = line[6:] try: parsed_data = json.loads(data) if 'content' in parsed_data: content = parsed_data.get('content', '')[0]['text'] print(content, end='',flush=True) else: print(data, flush=True) except json.JSONDecodeError: pass if __name__ == "__main__": asyncio.run(stream_response())Reference: API Request Body Options
mainThe DeepReasoning API accepts the following configuration options in the request body:
{ "stream": false, "verbose": false, "system": "Optional system prompt", "messages": [...], "deepseek_config": { "headers": {}, "body": {} }, "anthropic_config": { "headers": {}, "body": {} } }Initialize the DeepSeekClient
mainTo interact with DeepSeek's AI models, initialize a
DeepSeekClientby providing your API token. The client handles authentication, request construction, and response parsing for both streaming and non-streaming modes.use deepreasoning::clients::DeepSeekClient; let client = DeepSeekClient::new("your-api-key".to_string());Perform a non-streaming chat request with DeepSeekClient::chat
mainUse the
chatmethod to send a single request and receive a completeDeepSeekResponse. This method is asynchronous and requires a vector ofMessageobjects and anApiConfig.Parameters:
messages:Vec<Message>containing the conversation history.config:&ApiConfigcontaining request parameters likemodel,max_tokens, andtemperaturevia thebodyfield.
Returns:
Result<DeepSeekResponse>: The full response containingchoices,usagestatistics, and model metadata.
use crate::clients::DeepSeekClient; use crate::models::{ApiConfig, Message}; // Initialize the client let client = DeepSeekClient::new("your-api-key".to_string()); // Prepare messages and configuration let messages = vec![Message { role: "user".to_string(), content: "Hello, how are you?".to_string(), }]; let config = ApiConfig::default(); // Make a non-streaming request let response = client.chat(messages, &config).await?; println!("Response: {:?}", response.choices[0].message.content);Perform a streaming chat request with DeepSeekClient::chat_stream
mainUse the
chat_streammethod to receive real-time updates from the model. This method returns a pinned, boxed stream ofStreamResponseobjects. Each chunk in the stream contains adeltawhich may includecontentorreasoning_content(for reasoning models).Parameters:
messages:Vec<Message>containing the conversation history.config:&ApiConfigcontaining request parameters.
Returns:
Pin<Box<dyn Stream<Item = Result<StreamResponse>> + Send>>>: A stream of response chunks.