mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
Hope it works
This commit is contained in:
parent
b7f764799c
commit
bc6f68e105
1 changed files with 57 additions and 17 deletions
|
|
@ -7,11 +7,8 @@ import Anthropic from '@anthropic-ai/sdk';
|
|||
import { Ollama } from 'ollama';
|
||||
import OpenAI, { ClientOptions } from 'openai';
|
||||
|
||||
|
||||
/* Mistral standalone Fim endpoint */
|
||||
import { MistralCore } from "@mistralai/mistralai/core.js";
|
||||
import Mistral from '@mistralai/mistralai';
|
||||
import { fimComplete } from "@mistralai/mistralai/funcs/fimComplete.js";
|
||||
/* End Mistral standalone Fim endpoint */
|
||||
|
||||
|
||||
import { Model as OpenAIModel } from 'openai/resources/models.js';
|
||||
|
|
@ -121,7 +118,7 @@ const newOpenAICompatibleSDK = ({ settingsOfProvider, providerName, includeInPay
|
|||
}
|
||||
else if (providerName === 'mistral') {
|
||||
const thisConfig = settingsOfProvider[providerName]
|
||||
return new OpenAI({ baseURL: 'https://api.mistral.ai/v1', apiKey: thisConfig.apiKey })
|
||||
return new Mistral({ apiKey: thisConfig.apiKey, ...commonPayloadOpts })
|
||||
}
|
||||
|
||||
else throw new Error(`Void providerName was invalid: ${providerName}.`)
|
||||
|
|
@ -475,6 +472,59 @@ const sendOllamaFIM = ({ messages: messages_, onFinalMessage, onError, settingsO
|
|||
})
|
||||
}
|
||||
|
||||
const _sendMistralChat = ({ messages: messages_, onText, onFinalMessage, onError, settingsOfProvider, modelName: modelName_, _setAborter, providerName, aiInstructions, tools: tools_ }: SendChatParams_Internal) => {
|
||||
const {
|
||||
modelName,
|
||||
supportsReasoning,
|
||||
supportsSystemMessage,
|
||||
supportsTools,
|
||||
// maxOutputTokens, right now we are ignoring this
|
||||
} = getModelCapabilities(providerName, modelName_)
|
||||
|
||||
const {
|
||||
canIOReasoning,
|
||||
openSourceThinkTags,
|
||||
} = supportsReasoning || {}
|
||||
|
||||
const { providerReasoningIOSettings } = getProviderCapabilities(providerName)
|
||||
|
||||
const { messages } = prepareMessages({ messages: messages_, aiInstructions, supportsSystemMessage, supportsTools, supportsAnthropicReasoningSignature: false })
|
||||
|
||||
const thisConfig = settingsOfProvider[providerName]
|
||||
const mistral = new Mistral({ apiKey: thisConfig.apiKey })
|
||||
|
||||
let fullTextSoFar = ''
|
||||
let fullReasoningSoFar = ''
|
||||
|
||||
const { needsManualParse: needsManualReasoningParse } = providerReasoningIOSettings?.output ?? {}
|
||||
const manuallyParseReasoning = needsManualReasoningParse && canIOReasoning && openSourceThinkTags
|
||||
if (manuallyParseReasoning) {
|
||||
onText = extractReasoningOnTextWrapper(onText, openSourceThinkTags)
|
||||
}
|
||||
|
||||
mistral.chat.complete({
|
||||
model: modelName,
|
||||
messages: messages,
|
||||
stream: false,
|
||||
})
|
||||
.then(response => {
|
||||
const content = response.choices?.[0]?.message?.content
|
||||
const fullText = typeof content === 'string' ? content :
|
||||
Array.isArray(content) ? content.map(chunk => chunk.type === 'text' ? chunk.text : '').join('') : '';
|
||||
|
||||
onFinalMessage({ fullText, fullReasoning: '', toolCalls: [], anthropicReasoning: null });
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.status === 401) {
|
||||
onError({ message: invalidApiKeyMessage(providerName), fullError: error });
|
||||
} else {
|
||||
onError({ message: error + '', fullError: error });
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
const _sendMistralFIM = ({ messages: messages_, onFinalMessage, onError, settingsOfProvider, modelName: modelName_, _setAborter, providerName, aiInstructions }: SendFIMParams_Internal) => {
|
||||
const { modelName, supportsFIM } = getModelCapabilities(providerName, modelName_)
|
||||
if (!supportsFIM) {
|
||||
|
|
@ -486,16 +536,7 @@ const _sendMistralFIM = ({ messages: messages_, onFinalMessage, onError, setting
|
|||
}
|
||||
const messages = prepareFIMMessage({ messages: messages_, aiInstructions })
|
||||
|
||||
const mistral = new MistralCore({ apiKey: settingsOfProvider.mistral.apiKey })
|
||||
|
||||
// DEBUG : request params
|
||||
console.log('🔍 Sending FIM request with params:', {
|
||||
model: modelName,
|
||||
promptLength: messages.prefix.length,
|
||||
suffixLength: messages.suffix.length,
|
||||
stream: false,
|
||||
maxTokens: messages.maxTokens
|
||||
});
|
||||
const mistral = new Mistral({ providerName, settingsOfProvider, includeInPayload })
|
||||
|
||||
fimComplete(
|
||||
mistral, {
|
||||
|
|
@ -508,7 +549,6 @@ const _sendMistralFIM = ({ messages: messages_, onFinalMessage, onError, setting
|
|||
stop: messages.stopTokens
|
||||
},
|
||||
)
|
||||
|
||||
.then(async response => {
|
||||
let content = response?.ok ? response.value.choices?.[0]?.message?.content : '';
|
||||
const fullText = typeof content === 'string' ? content :
|
||||
|
|
@ -581,7 +621,7 @@ export const sendLLMMessageToProviderImplementation = {
|
|||
list: null,
|
||||
},
|
||||
mistral: {
|
||||
sendChat: (params) => _sendOpenAICompatibleChat(params),
|
||||
sendChat: (params) => _sendMistralChat(params),
|
||||
sendFIM: (params) => _sendMistralFIM(params),
|
||||
list: null,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue