mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-17 20:00:58 +00:00
Fix the Mistral uncompatibility with the usage of OpenAI
This commit is contained in:
@ -549,16 +549,19 @@ async fn run_conversation<C: async_openai::config::Config>(
|
|||||||
global_tool_calls: &mut HashMap<u32, Call>,
|
global_tool_calls: &mut HashMap<u32, Call>,
|
||||||
function_support: FunctionSupport,
|
function_support: FunctionSupport,
|
||||||
) -> Result<ControlFlow<Option<FinishReason>, ()>, SendError<Event>> {
|
) -> Result<ControlFlow<Option<FinishReason>, ()>, SendError<Event>> {
|
||||||
|
use DbChatCompletionSource::*;
|
||||||
|
|
||||||
let mut finish_reason = None;
|
let mut finish_reason = None;
|
||||||
chat_completion.stream_options = Some(ChatCompletionStreamOptions { include_usage: true });
|
chat_completion.stream_options = match source {
|
||||||
|
OpenAi | AzureOpenAi => Some(ChatCompletionStreamOptions { include_usage: true }),
|
||||||
|
Mistral | VLlm => None,
|
||||||
|
};
|
||||||
|
|
||||||
// safety: unwrap: can only happens if `stream` was set to `false`
|
// safety: unwrap: can only happens if `stream` was set to `false`
|
||||||
let mut response = client.chat().create_stream(chat_completion.clone()).await.unwrap();
|
let mut response = client.chat().create_stream(chat_completion.clone()).await.unwrap();
|
||||||
while let Some(result) = response.next().await {
|
while let Some(result) = response.next().await {
|
||||||
match result {
|
match result {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
let choice = match resp.choices.get(0) {
|
|
||||||
Some(choice) => choice,
|
|
||||||
None => {
|
|
||||||
if let Some(usage) = resp.usage.as_ref() {
|
if let Some(usage) = resp.usage.as_ref() {
|
||||||
for (r#type, value) in &[
|
for (r#type, value) in &[
|
||||||
("prompt", usage.prompt_tokens),
|
("prompt", usage.prompt_tokens),
|
||||||
@ -566,16 +569,13 @@ async fn run_conversation<C: async_openai::config::Config>(
|
|||||||
("total", usage.total_tokens),
|
("total", usage.total_tokens),
|
||||||
] {
|
] {
|
||||||
MEILISEARCH_CHAT_TOKENS_USAGE
|
MEILISEARCH_CHAT_TOKENS_USAGE
|
||||||
.with_label_values(&[
|
.with_label_values(&[workspace_uid, &chat_completion.model, r#type])
|
||||||
workspace_uid,
|
|
||||||
&chat_completion.model,
|
|
||||||
r#type,
|
|
||||||
])
|
|
||||||
.inc_by(*value as u64);
|
.inc_by(*value as u64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
let choice = match resp.choices.first() {
|
||||||
}
|
Some(choice) => choice,
|
||||||
|
None => break,
|
||||||
};
|
};
|
||||||
finish_reason = choice.finish_reason;
|
finish_reason = choice.finish_reason;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user