-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopenrouter.provider.ts
More file actions
30 lines (29 loc) · 972 Bytes
/
openrouter.provider.ts
File metadata and controls
30 lines (29 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import {Provider} from '@loopback/core';
import {ChatOpenRouter} from '@langchain/openrouter';
import {LLMProvider} from '../../../../types';
import {OpenRouterInstanceConfig} from '../types';
export class OpenRouter implements Provider<LLMProvider> {
static createInstance(config: OpenRouterInstanceConfig): ChatOpenRouter {
return new ChatOpenRouter({
model: config.model,
...config.config,
});
}
value(): LLMProvider {
if (!process.env.OPENROUTER_MODEL || !process.env.OPENROUTER_API_KEY) {
throw new Error(
'OPENROUTER_MODEL and OPENROUTER_API_KEY environment variables must be set.',
);
}
return OpenRouter.createInstance({
model: process.env.OPENROUTER_MODEL,
config: {
apiKey: process.env.OPENROUTER_API_KEY,
temperature: Number.parseFloat(
process.env.OPENROUTER_TEMPERATURE ?? '0',
),
baseURL: process.env.OPENROUTER_BASE_URL,
},
});
}
}