deep-chat
deep-chat copied to clipboard
Add OpenRouter Support to Express Sample Server
Summary
This PR adds comprehensive OpenRouter support to the Express sample server, enabling users to easily integrate with OpenRouter's AI services through the deep-chat component.
Changes
-
Added OpenRouter service endpoints in the Express server:
/openrouter-chat- Standard chat completion endpoint/openrouter-chat-stream- Streaming chat completion endpoint/openrouter-list-models- Model listing endpoint
-
Implemented OpenRouter service class with:
- Chat completion support with both standard and streaming responses
- Image generation capabilities
- Model listing functionality
- Proper error handling and forwarding to error middleware
-
Updated serviceIOFactory.ts to properly route OpenRouter requests:
- Added case for 'openrouter' in the service routing switch statement
- Configured OpenRouterIO to handle forwarded request bodies correctly
Service URL Pattern
The endpoint follows the pattern: http://host:port/openrouter-chat
Example configuration in deep-chat:
<deep-chat
connect='{
"url": "http://localhost:8080/openrouter-chat"
}'>
</deep-chat>
Environment Variables
To use the OpenRouter service, set the following environment variables in your .env file:
OPENROUTER_API_KEY- Your OpenRouter API keyOPENROUTER_DEFAULT_MODEL- Default model to use (optional, defaults to 'moonshotai/kimi-k2:free')OPENROUTER_IMAGE_MODEL- Default image model to use (optional, defaults to 'qwen/qwen2.5-vl-72b-instruct:free')OPENROUTER_HTTP_REFERER- HTTP referer header (optional)OPENROUTER_X_TITLE- X-Title header (optional)
Features
- Full support for text-based chat completions
- Streaming response support for real-time message delivery
- Image generation capabilities
- Model listing functionality
- Proper error handling with middleware integration
- CORS support for local development
Testing
The implementation has been tested with:
- Standard chat requests
- Streaming chat requests
- Error scenarios (invalid API keys, network issues)
- Various OpenRouter models
This integration allows developers to quickly set up an OpenRouter-powered chat interface using the deep-chat component with minimal configuration.
Important Note
Before starting work on a new feature or making changes to our API, please open a new issue first.
This helps us to:
- Confirm that your idea aligns with our project's vision
- Ensure it's not something we're already working on internally
- Assess whether it's something we can realistically support or implement
Creating an issue first allows for better collaboration and helps avoid duplicated or misaligned efforts. Thank you!
Hi @wongchichong. Thankyou for the PR. Unfortunately I am currently not accepting any more example server additions as we will soon be creating a separate repo for Deep Chat implementation examples. I will keep this PR open until this has been created. Please hang tight until it does.