-
Couldn't load subscription status.
- Fork 768
feat: add krutrim as provider #1201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { ProviderAPIConfig } from '../types'; | ||
|
|
||
| const KrutrimAPIConfig: ProviderAPIConfig = { | ||
| getBaseURL: () => 'https://cloud.olakrutrim.com/v1', | ||
| headers: ({ providerOptions, fn }) => { | ||
| const headersObj: Record<string, string> = { | ||
| Authorization: `Bearer ${providerOptions.apiKey}`, | ||
| }; | ||
| return headersObj; | ||
| }, | ||
| getEndpoint: ({ fn }) => { | ||
| switch (fn) { | ||
| case 'chatComplete': | ||
| return '/chat/completions'; | ||
| default: | ||
| return ''; | ||
| } | ||
| }, | ||
| }; | ||
|
|
||
| export default KrutrimAPIConfig; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ChatCompletionResponse, ErrorResponse } from '../types'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { generateErrorResponse } from '../utils'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import { KRUTRIM } from '../../globals'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| interface KrutrimChatCompleteResponse extends ChatCompletionResponse {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| interface KrutrimChatCompleteErrorResponse extends ErrorResponse { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 'html-message'?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| export const KrutrimChatCompleteResponseTransform: ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| response: KrutrimChatCompleteResponse | KrutrimChatCompleteErrorResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| responseStatus: number | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) => ChatCompletionResponse | ErrorResponse = (response, responseStatus) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (responseStatus !== 200 && 'html-message' in response) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // Handle Krutrim's error format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return generateErrorResponse( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| message: response['html-message'] ?? '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'error', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| param: null, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| code: String(responseStatus), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| KRUTRIM | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+13
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Code Refactor Issue: The error handling only checks for 'html-message' property but doesn't handle standard error responses that might not have this property.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Success case - add provider info | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.defineProperty(response, 'provider', { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| value: KRUTRIM, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| enumerable: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| return response as ChatCompletionResponse; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { ProviderConfigs } from '../types'; | ||
| import KrutrimAPIConfig from './api'; | ||
| import { chatCompleteParams } from '../open-ai-base'; | ||
| import { KrutrimChatCompleteResponseTransform } from './chatComplete'; | ||
| const KrutrimConfig: ProviderConfigs = { | ||
| api: KrutrimAPIConfig, | ||
| chatComplete: chatCompleteParams([], { model: 'Llama-3.3-70B-Instruct' }), | ||
| responseTransforms: { | ||
| chatComplete: KrutrimChatCompleteResponseTransform, | ||
| }, | ||
| }; | ||
|
|
||
| export default KrutrimConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚡️ Performance Improvement
Issue: The headers function creates a new object on every call, which is unnecessary since the object structure is static.
Fix: Optimize the headers function to directly return the object without the intermediate variable.
Impact: Slightly improves performance by reducing unnecessary object creation and variable assignment.