Skip to content

Commit d5865fc

Browse files
authored
feat: add Openrouter support (#75)
* feat: add openrouter support - Introduce ModelProvider abstraction for LLM service - Added ModelProviderName enum and ModelProviders mapping to centralize model provider definitions, enhancing maintainability and readability. - Updated LLMService to utilize the new ModelProviderName for provider identification, improving code clarity. - Refactored getProviderFromModel method to return ModelProviderName values, streamlining model provider retrieval logic. - Introduced openrouter support in LLMService, expanding model provider capabilities. * test: add ModelAdapter tests for unsupported provider handling - Introduced a new test suite for ModelAdapter to validate error handling for unsupported providers. - Enhanced existing tests for DummyLLM to ensure comprehensive coverage of LLM functionalities. - This update improves the robustness of the testing framework and ensures adherence to expected behaviors in the LLM module. * chore: update package dependencies - Upgraded versions of several @AI-SDK packages to their latest releases for improved functionality and compatibility. - Updated the "ai" package from version 4.3 to 4.3.15 to ensure alignment with the latest features and enhancements. - Added @openrouter/ai-sdk-provider dependency to support new functionalities. * refactor: update RevenueProjectSchema and handle null values in project data - Modified RevenueProjectSchema to allow nullable fields for arr, mrr, and normalizedRevenueFor30Days, enhancing data flexibility. - Updated RevenueDataExecutor to handle null values by converting them to 0, ensuring consistent data structure when fetching project data. - Added error handling for cases where no project data is returned, improving robustness and user feedback. * chore: update pnpm-lock.yaml with dependency version changes - Upgraded several @AI-SDK packages to their latest versions, including '@ai-sdk/anthropic' to 1.2.11, '@ai-sdk/deepseek' to 0.2.14, and '@ai-sdk/openai' to 1.3.22, enhancing functionality and compatibility. - Added '@openrouter/ai-sdk-provider' version 0.4.5 to support new features. - Updated the 'ai' package from version 4.3.13 to 4.3.15 for improved performance and stability.
1 parent 7170636 commit d5865fc

File tree

8 files changed

+156
-94
lines changed

8 files changed

+156
-94
lines changed

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@
2020
"author": "",
2121
"license": "ISC",
2222
"dependencies": {
23-
"@ai-sdk/anthropic": "^1.1.9",
24-
"@ai-sdk/deepseek": "^0.1.11",
25-
"@ai-sdk/openai": "^1.1.13",
23+
"@ai-sdk/anthropic": "^1.2.11",
24+
"@ai-sdk/deepseek": "^0.2.14",
25+
"@ai-sdk/openai": "^1.3.22",
2626
"@dimo-network/data-sdk": "1.2.3",
2727
"@langchain/community": "^0.3.32",
2828
"@langchain/core": "^0.3.40",
2929
"@langchain/openai": "^0.4.4",
3030
"@langchain/qdrant": "^0.1.1",
3131
"@modelcontextprotocol/sdk": "^1.10.2",
32+
"@openrouter/ai-sdk-provider": "^0.4.5",
3233
"@qdrant/js-client-rest": "^1.13.0",
3334
"@upstash/redis": "^1.34.4",
34-
"ai": "^4.3",
35+
"ai": "^4.3.15",
3536
"axios": "^1.7.9",
3637
"chalk": "^4.1.2",
3738
"dotenv": "^16.4.7",

pnpm-lock.yaml

Lines changed: 70 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__tests__/llm.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from 'vitest';
22

3-
import { DummyLLM } from '../llm/llm';
3+
import { DummyLLM, ModelAdapter } from '../llm/llm';
44

55
describe('LLM', () => {
66
describe('DummyLLM', () => {
@@ -10,4 +10,12 @@ describe('LLM', () => {
1010
expect(response).toBe(`{"tool":null,"tool_input":"Dummy LLM Response to the user's request."}`);
1111
});
1212
});
13+
14+
describe('ModelAdapter', () => {
15+
it('should throw error for unsupported provider', () => {
16+
expect(() => {
17+
new ModelAdapter({ provider: 'nonexistent' as any, model: 'some-model' });
18+
}).toThrow('Unsupported provider: nonexistent');
19+
});
20+
});
1321
});

src/llm/llm-service.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ describe('LLMService', () => {
4646
expect((service.llm as ModelAdapter).model.modelId).toBe('deepseek-reasoner');
4747
});
4848

49+
it('should initialize with OpenRouter models', () => {
50+
const service = new LLMService({
51+
fastLLMModel: 'mistralai/mistral-large',
52+
LLMModel: 'anthropic/claude-3-opus',
53+
});
54+
55+
expect((service.fastllm as ModelAdapter).model.modelId).toBe('mistralai/mistral-large');
56+
expect((service.llm as ModelAdapter).model.modelId).toBe('anthropic/claude-3-opus');
57+
});
58+
4959
it('should mix different providers based on models', () => {
5060
const service = new LLMService({
5161
fastLLMModel: 'claude-3-5-haiku-latest',

0 commit comments

Comments
 (0)