fix: Fix google provider in app (#859)
This commit is contained in:
@@ -59,6 +59,7 @@ paste = "1.0"
|
|||||||
serde_yaml = "0.9.34"
|
serde_yaml = "0.9.34"
|
||||||
once_cell = "1.20.2"
|
once_cell = "1.20.2"
|
||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
|
rand = "0.8.5"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.5"
|
criterion = "0.5"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use anyhow::Result;
|
|||||||
use mcp_core::content::Content;
|
use mcp_core::content::Content;
|
||||||
use mcp_core::role::Role;
|
use mcp_core::role::Role;
|
||||||
use mcp_core::tool::{Tool, ToolCall};
|
use mcp_core::tool::{Tool, ToolCall};
|
||||||
|
use rand::{distributions::Alphanumeric, Rng};
|
||||||
use serde_json::{json, Map, Value};
|
use serde_json::{json, Map, Value};
|
||||||
|
|
||||||
/// Convert internal Message format to Google's API message specification
|
/// Convert internal Message format to Google's API message specification
|
||||||
@@ -198,14 +199,16 @@ pub fn response_to_message(response: Value) -> Result<Message> {
|
|||||||
.and_then(|content| content.get("parts"))
|
.and_then(|content| content.get("parts"))
|
||||||
.and_then(|parts| parts.as_array())
|
.and_then(|parts| parts.as_array())
|
||||||
.unwrap_or(&binding);
|
.unwrap_or(&binding);
|
||||||
|
|
||||||
for part in parts {
|
for part in parts {
|
||||||
if let Some(text) = part.get("text").and_then(|v| v.as_str()) {
|
if let Some(text) = part.get("text").and_then(|v| v.as_str()) {
|
||||||
content.push(MessageContent::text(text.to_string()));
|
content.push(MessageContent::text(text.to_string()));
|
||||||
} else if let Some(function_call) = part.get("functionCall") {
|
} else if let Some(function_call) = part.get("functionCall") {
|
||||||
let id = function_call["name"]
|
let id: String = rand::thread_rng()
|
||||||
.as_str()
|
.sample_iter(&Alphanumeric)
|
||||||
.unwrap_or_default()
|
.take(8)
|
||||||
.to_string();
|
.map(char::from)
|
||||||
|
.collect();
|
||||||
let name = function_call["name"]
|
let name = function_call["name"]
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
|||||||
@@ -89,8 +89,18 @@ export async function processCustomChatResponse({
|
|||||||
onTextPart(value) {
|
onTextPart(value) {
|
||||||
// If the last event wasn't text, or we don't have a current message, create a new one
|
// If the last event wasn't text, or we don't have a current message, create a new one
|
||||||
if (lastEventType !== 'text' || currentMessage == null) {
|
if (lastEventType !== 'text' || currentMessage == null) {
|
||||||
archiveCurrentMessage();
|
// Only archive if there are no tool invocations in 'call' state
|
||||||
currentMessage = createNewMessage();
|
const hasPendingToolCalls =
|
||||||
|
currentMessage?.toolInvocations?.some((invocation) => invocation.state === 'call') ??
|
||||||
|
false;
|
||||||
|
|
||||||
|
if (!hasPendingToolCalls) {
|
||||||
|
archiveCurrentMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!currentMessage) {
|
||||||
|
currentMessage = createNewMessage();
|
||||||
|
}
|
||||||
currentMessage.content = value;
|
currentMessage.content = value;
|
||||||
} else {
|
} else {
|
||||||
// Concatenate with the existing message
|
// Concatenate with the existing message
|
||||||
|
|||||||
Reference in New Issue
Block a user