Skip to content

Commit 9728edd

Browse files
authored
Merge pull request #988 from Ajay-Satish-01/cortex
2 parents cc328ee + 45f12c4 commit 9728edd

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

src/globals.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export const UPSTAGE: string = 'upstage';
7777
export const LAMBDA: string = 'lambda';
7878
export const DASHSCOPE: string = 'dashscope';
7979
export const X_AI: string = 'x-ai';
80+
export const CORTEX: string = 'cortex';
8081
export const SAGEMAKER: string = 'sagemaker';
8182
export const NEBIUS: string = 'nebius';
8283
export const RECRAFTAI: string = 'recraft-ai';
@@ -131,6 +132,7 @@ export const VALID_PROVIDERS = [
131132
LAMBDA,
132133
DASHSCOPE,
133134
X_AI,
135+
CORTEX,
134136
SAGEMAKER,
135137
NEBIUS,
136138
RECRAFTAI,

src/handlers/handlerUtils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
STABILITY_AI,
1717
SAGEMAKER,
1818
FIREWORKS_AI,
19+
CORTEX,
1920
} from '../globals';
2021
import Providers from '../providers';
2122
import { ProviderAPIConfig, endpointStrings } from '../providers/types';
@@ -1072,6 +1073,10 @@ export function constructConfigFromRequestHeaders(
10721073
}
10731074
}
10741075

1076+
const cortexConfig = {
1077+
snowflakeAccount: requestHeaders[`x-${POWERED_BY}-snowflake-account`],
1078+
};
1079+
10751080
const defaultsConfig = {
10761081
input_guardrails: requestHeaders[`x-portkey-default-input-guardrails`]
10771082
? JSON.parse(requestHeaders[`x-portkey-default-input-guardrails`])
@@ -1171,6 +1176,13 @@ export function constructConfigFromRequestHeaders(
11711176
...stabilityAiConfig,
11721177
};
11731178
}
1179+
1180+
if (parsedConfigJson.provider === CORTEX) {
1181+
parsedConfigJson = {
1182+
...parsedConfigJson,
1183+
...cortexConfig,
1184+
};
1185+
}
11741186
}
11751187
return convertKeysToCamelCase(parsedConfigJson, [
11761188
'override_params',
@@ -1215,6 +1227,7 @@ export function constructConfigFromRequestHeaders(
12151227
stabilityAiConfig),
12161228
...(requestHeaders[`x-${POWERED_BY}-provider`] === FIREWORKS_AI &&
12171229
fireworksConfig),
1230+
...(requestHeaders[`x-${POWERED_BY}-provider`] === CORTEX && cortexConfig),
12181231
};
12191232
}
12201233

src/providers/cortex/api.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ProviderAPIConfig } from '../types';
2+
3+
const CortexAPIConfig: ProviderAPIConfig = {
4+
getBaseURL: ({ providerOptions }) =>
5+
`https://${(providerOptions as any).snowflakeAccount}.snowflakecomputing.com/api/v2`,
6+
headers: ({ providerOptions }) => ({
7+
'X-Snowflake-Authorization-Token-Type': 'KEYPAIR_JWT',
8+
Authorization: `Bearer ${providerOptions.apiKey}`,
9+
'Content-Type': 'application/json',
10+
Accept: 'application/json, text/event-stream',
11+
}),
12+
getEndpoint: ({ fn }) => {
13+
switch (fn) {
14+
case 'chatComplete':
15+
return '/cortex/inference:complete';
16+
default:
17+
return '';
18+
}
19+
},
20+
};
21+
22+
export default CortexAPIConfig;

src/providers/cortex/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ProviderConfigs } from '../types';
2+
import CortexAPIConfig from './api';
3+
import { CORTEX } from '../../globals';
4+
import {
5+
chatCompleteParams,
6+
completeParams,
7+
embedParams,
8+
responseTransformers,
9+
} from '../open-ai-base';
10+
11+
const CortexConfig: ProviderConfigs = {
12+
chatComplete: chatCompleteParams([], { model: 'mistral-large' }),
13+
complete: completeParams([], { model: 'mistral-large' }),
14+
embed: embedParams([], { model: 'mistral-large' }),
15+
api: CortexAPIConfig,
16+
responseTransforms: responseTransformers(CORTEX, {
17+
chatComplete: true,
18+
}),
19+
};
20+
21+
export default CortexConfig;

src/types/requestBody.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ export interface Options {
150150

151151
/** Fireworks finetune required fields */
152152
fireworksAccountId?: string;
153+
154+
/** Cortex specific fields */
155+
snowflakeAccount?: string;
153156
}
154157

155158
/**

0 commit comments

Comments
 (0)