Skip to content

Commit

Permalink
Merge pull request #467 from keshavkrishna/mistralai-fim-completions
Browse files Browse the repository at this point in the history
Added Support for the new /fim/completions route on Mistral AI API
  • Loading branch information
VisargD authored Sep 19, 2024
2 parents 132d6ad + 3b107d0 commit 114895d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/handlers/handlerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,8 @@ export function constructConfigFromRequestHeaders(
anthropicConfig),
...(requestHeaders[`x-${POWERED_BY}-provider`] === HUGGING_FACE &&
huggingfaceConfig),
mistralFimCompletion:
requestHeaders[`x-${POWERED_BY}-mistral-fim-completion`],
};
}

Expand Down
10 changes: 8 additions & 2 deletions src/providers/mistral-ai/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ const MistralAIAPIConfig: ProviderAPIConfig = {
headers: ({ providerOptions }) => {
return { Authorization: `Bearer ${providerOptions.apiKey}` };
},
getEndpoint: ({ fn }) => {
switch (fn) {
getEndpoint: ({ fn, providerOptions }) => {
let mappedfn = fn;
if (providerOptions.mistralFimCompletion === 'true') {
mappedfn = 'fimComplete';
}
switch (mappedfn) {
case 'chatComplete':
return '/chat/completions';
case 'embed':
return '/embeddings';
case 'fimComplete':
return '/fim/completions';
default:
return '';
}
Expand Down
10 changes: 10 additions & 0 deletions src/providers/mistral-ai/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export const MistralAIChatCompleteConfig: ProviderConfig = {
param: 'safe_prompt',
default: false,
},
prompt: {
param: 'prompt',
required: false,
default: '',
},
suffix: {
param: 'suffix',
required: false,
default: '',
},
};

interface MistralAIChatCompleteResponse extends ChatCompletionResponse {
Expand Down
3 changes: 2 additions & 1 deletion src/types/requestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export interface Options {

/** The parameter to determine if extra non-openai compliant fields should be returned in response */
strictOpenAiCompliance?: boolean;

/** Parameter to determine if fim/completions endpoint is to be used */
mistralFimCompletion?: String;
/** Anthropic specific headers */
anthropicBeta?: string;
anthropicVersion?: string;
Expand Down

0 comments on commit 114895d

Please sign in to comment.