mistral proxy support
This commit is contained in:
parent
060bc60794
commit
42aa7fd316
|
@ -707,8 +707,8 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr data-source="openai,claude">
|
<hr data-source="openai,claude,mistralai">
|
||||||
<div class="range-block" data-source="openai,claude">
|
<div class="range-block" data-source="openai,claude,mistralai">
|
||||||
<div class="range-block-title justifyLeft" data-i18n="OpenAI Reverse Proxy">
|
<div class="range-block-title justifyLeft" data-i18n="OpenAI Reverse Proxy">
|
||||||
OpenAI / Claude Reverse Proxy
|
OpenAI / Claude Reverse Proxy
|
||||||
</div>
|
</div>
|
||||||
|
@ -735,7 +735,7 @@
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="range-block" data-source="openai,claude">
|
<div class="range-block" data-source="openai,claude,mistralai">
|
||||||
<div class="range-block-title justifyLeft" data-i18n="Proxy Password">
|
<div class="range-block-title justifyLeft" data-i18n="Proxy Password">
|
||||||
Proxy Password
|
Proxy Password
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1562,8 +1562,8 @@ async function sendOpenAIRequest(type, messages, signal) {
|
||||||
delete generate_data.stop;
|
delete generate_data.stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proxy is only supported for Claude and OpenAI
|
// Proxy is only supported for Claude, OpenAI and Mistral
|
||||||
if (oai_settings.reverse_proxy && [chat_completion_sources.CLAUDE, chat_completion_sources.OPENAI].includes(oai_settings.chat_completion_source)) {
|
if (oai_settings.reverse_proxy && [chat_completion_sources.CLAUDE, chat_completion_sources.OPENAI, chat_completion_sources.MISTRALAI].includes(oai_settings.chat_completion_source)) {
|
||||||
validateReverseProxy();
|
validateReverseProxy();
|
||||||
generate_data['reverse_proxy'] = oai_settings.reverse_proxy;
|
generate_data['reverse_proxy'] = oai_settings.reverse_proxy;
|
||||||
generate_data['proxy_password'] = oai_settings.proxy_password;
|
generate_data['proxy_password'] = oai_settings.proxy_password;
|
||||||
|
|
|
@ -12,7 +12,7 @@ const { getTokenizerModel, getSentencepiceTokenizer, getTiktokenTokenizer, sente
|
||||||
|
|
||||||
const API_OPENAI = 'https://api.openai.com/v1';
|
const API_OPENAI = 'https://api.openai.com/v1';
|
||||||
const API_CLAUDE = 'https://api.anthropic.com/v1';
|
const API_CLAUDE = 'https://api.anthropic.com/v1';
|
||||||
|
const API_MISTRAL = 'https://api.mistral.ai/v1';
|
||||||
/**
|
/**
|
||||||
* Sends a request to Claude API.
|
* Sends a request to Claude API.
|
||||||
* @param {express.Request} request Express request
|
* @param {express.Request} request Express request
|
||||||
|
@ -431,7 +431,8 @@ async function sendAI21Request(request, response) {
|
||||||
* @param {express.Response} response Express response
|
* @param {express.Response} response Express response
|
||||||
*/
|
*/
|
||||||
async function sendMistralAIRequest(request, response) {
|
async function sendMistralAIRequest(request, response) {
|
||||||
const apiKey = readSecret(SECRET_KEYS.MISTRALAI);
|
const apiUrl = new URL(request.body.reverse_proxy || API_MISTRAL).toString();
|
||||||
|
const apiKey = request.body.reverse_proxy ? request.body.proxy_password : readSecret(SECRET_KEYS.MISTRALAI);
|
||||||
|
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
console.log('MistralAI API key is missing.');
|
console.log('MistralAI API key is missing.');
|
||||||
|
@ -495,7 +496,7 @@ async function sendMistralAIRequest(request, response) {
|
||||||
|
|
||||||
console.log('MisralAI request:', requestBody);
|
console.log('MisralAI request:', requestBody);
|
||||||
|
|
||||||
const generateResponse = await fetch('https://api.mistral.ai/v1/chat/completions', config);
|
const generateResponse = await fetch(apiUrl + '/chat/completions', config);
|
||||||
if (request.body.stream) {
|
if (request.body.stream) {
|
||||||
forwardFetchResponse(generateResponse, response);
|
forwardFetchResponse(generateResponse, response);
|
||||||
} else {
|
} else {
|
||||||
|
@ -538,8 +539,8 @@ router.post('/status', jsonParser, async function (request, response_getstatus_o
|
||||||
// OpenRouter needs to pass the referer: https://openrouter.ai/docs
|
// OpenRouter needs to pass the referer: https://openrouter.ai/docs
|
||||||
headers = { 'HTTP-Referer': request.headers.referer };
|
headers = { 'HTTP-Referer': request.headers.referer };
|
||||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.MISTRALAI) {
|
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.MISTRALAI) {
|
||||||
api_url = 'https://api.mistral.ai/v1';
|
api_url = new URL(request.body.reverse_proxy || API_MISTRAL).toString();
|
||||||
api_key_openai = readSecret(SECRET_KEYS.MISTRALAI);
|
api_key_openai = request.body.reverse_proxy ? request.body.proxy_password : readSecret(SECRET_KEYS.MISTRALAI);
|
||||||
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.CUSTOM) {
|
} else if (request.body.chat_completion_source === CHAT_COMPLETION_SOURCES.CUSTOM) {
|
||||||
api_url = request.body.custom_url;
|
api_url = request.body.custom_url;
|
||||||
api_key_openai = readSecret(SECRET_KEYS.CUSTOM);
|
api_key_openai = readSecret(SECRET_KEYS.CUSTOM);
|
||||||
|
|
Loading…
Reference in New Issue