Skip to content

add feat. kluster_ai #1082

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

Merged
merged 10 commits into from
Jun 11, 2025
Merged
2 changes: 2 additions & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const RECRAFTAI: string = 'recraft-ai';
export const MILVUS: string = 'milvus';
export const REPLICATE: string = 'replicate';
export const LEPTON: string = 'lepton';
export const KLUSTER_AI: string = 'kluster-ai';
export const NSCALE: string = 'nscale';

export const VALID_PROVIDERS = [
Expand Down Expand Up @@ -150,6 +151,7 @@ export const VALID_PROVIDERS = [
REPLICATE,
POWERED_BY,
LEPTON,
KLUSTER_AI,
NSCALE,
];

Expand Down
2 changes: 2 additions & 0 deletions src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import RecraftAIConfig from './recraft-ai';
import MilvusConfig from './milvus';
import ReplicateConfig from './replicate';
import LeptonConfig from './lepton';
import KlusterAIConfig from './kluster-ai';
import NscaleConfig from './nscale';

const Providers: { [key: string]: ProviderConfigs } = {
Expand Down Expand Up @@ -113,6 +114,7 @@ const Providers: { [key: string]: ProviderConfigs } = {
milvus: MilvusConfig,
replicate: ReplicateConfig,
lepton: LeptonConfig,
'kluster-ai': KlusterAIConfig,
nscale: NscaleConfig,
};

Expand Down
23 changes: 23 additions & 0 deletions src/providers/kluster-ai/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ProviderAPIConfig } from '../types';

const KlusterAIAPIConfig: ProviderAPIConfig = {
getBaseURL: () => `https://api.kluster.ai/v1`,
headers: ({ providerOptions }) => ({
'Content-Type': 'application/json',
Authorization: `Bearer ${providerOptions.apiKey}`,
}),
getEndpoint: ({ fn }) => {
switch (fn) {
case 'chatComplete':
return '/chat/completions';
case 'embed':
return '/embeddings';
case 'uploadFile':
return '/files';
default:
return '';
}
},
};

export default KlusterAIAPIConfig;
16 changes: 16 additions & 0 deletions src/providers/kluster-ai/chatComplete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { KLUSTER_AI } from '../../globals';
import { OpenAIErrorResponseTransform } from '../openai/utils';
import { ChatCompletionResponse, ErrorResponse } from '../types';

interface KlusterAIChatCompleteResponse extends ChatCompletionResponse {}

export const KlusterAIResponseTransform: (
response: KlusterAIChatCompleteResponse | ErrorResponse,
responseStatus: number
) => ChatCompletionResponse | ErrorResponse = (response, responseStatus) => {
if (responseStatus !== 200 && 'error' in response) {
return OpenAIErrorResponseTransform(response, KLUSTER_AI);
}

return response;
};
42 changes: 42 additions & 0 deletions src/providers/kluster-ai/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ProviderConfigs } from '../types';
import { KLUSTER_AI } from '../../globals';
import {
chatCompleteParams,
embedParams,
responseTransformers,
} from '../open-ai-base';
import KlusterAIAPIConfig from './api';
import { KlusterAIResponseTransform } from './chatComplete';
import { KlusterAIRequestTransform } from './uploadFile';

const KlusterAIConfig: ProviderConfigs = {
chatComplete: chatCompleteParams(
[],
{ model: 'klusterai/Meta-Llama-3.1-8B-Instruct-Turbo' },
{
store: {
param: 'store',
},
metadata: {
param: 'metadata',
required: true,
},
}
),
embed: embedParams([], {
model: 'klusterai/Meta-Llama-3.1-8B-Instruct-Turbo',
}),
api: KlusterAIAPIConfig,
responseTransforms: {
...responseTransformers(KLUSTER_AI, {
chatComplete: true,
embed: true,
}),
uploadFile: KlusterAIResponseTransform,
},
requestTransforms: {
uploadFile: KlusterAIRequestTransform,
},
};

export default KlusterAIConfig;
3 changes: 3 additions & 0 deletions src/providers/kluster-ai/uploadFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const KlusterAIRequestTransform = (requestBody: ReadableStream) => {
return requestBody;
};