From e3ca7e8b4433bea43376035b9417fe233fe5f6f0 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 25 Oct 2024 17:52:08 +0800 Subject: [PATCH 1/5] hotfix for statusText is non ISO-8859-1 #5717 --- src-tauri/src/stream.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/stream.rs b/src-tauri/src/stream.rs index d2c0726b0b4..d31dd67c3dc 100644 --- a/src-tauri/src/stream.rs +++ b/src-tauri/src/stream.rs @@ -119,11 +119,20 @@ pub async fn stream_fetch( } } Err(err) => { - println!("Error response: {:?}", err.source().expect("REASON").to_string()); + let error: String = err.source().expect("REASON").to_string(); + println!("Error response: {:?}", error); + tauri::async_runtime::spawn( async move { + if let Err(e) = window.emit(event_name, ChunkPayload{ request_id, chunk: error.into() }) { + println!("Failed to emit chunk payload: {:?}", e); + } + if let Err(e) = window.emit(event_name, EndPayload{ request_id, status: 0 }) { + println!("Failed to emit end payload: {:?}", e); + } + }); StreamResponse { request_id, status: 599, - status_text: err.source().expect("REASON").to_string(), + status_text: "Error".to_string(), headers: HashMap::new(), } } From 2c745590101b5201c677243f151616cb7023186e Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 25 Oct 2024 18:02:51 +0800 Subject: [PATCH 2/5] hitfix --- app/utils/stream.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/utils/stream.ts b/app/utils/stream.ts index 2eda768f36f..78263459552 100644 --- a/app/utils/stream.ts +++ b/app/utils/stream.ts @@ -100,7 +100,8 @@ export function fetch(url: string, options?: RequestInit): Promise { }) .catch((e) => { console.error("stream error", e); - throw e; + // throw e; + return new Response("", { status: 599 }); }); } return window.fetch(url, options); From 90ced9287626492898f2eb9bfd3b079171faf6ea Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 25 Oct 2024 18:05:29 +0800 Subject: [PATCH 3/5] update --- src-tauri/src/stream.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/stream.rs b/src-tauri/src/stream.rs index d31dd67c3dc..8320db3e48a 100644 --- a/src-tauri/src/stream.rs +++ b/src-tauri/src/stream.rs @@ -119,7 +119,9 @@ pub async fn stream_fetch( } } Err(err) => { - let error: String = err.source().expect("REASON").to_string(); + let error: String = err.source() + .map(|e| e.to_string()) + .unwrap_or_else(|| "Unknown error occurred".to_string()); println!("Error response: {:?}", error); tauri::async_runtime::spawn( async move { if let Err(e) = window.emit(event_name, ChunkPayload{ request_id, chunk: error.into() }) { From f89872b833d27c48b33281e60157640037e17a99 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 25 Oct 2024 18:12:09 +0800 Subject: [PATCH 4/5] hotfix for gemini invald argument #5715 --- app/client/platforms/google.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index 7265a500b97..14fecb8f289 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -192,7 +192,9 @@ export class GeminiProApi implements LLMApi { requestPayload, getHeaders(), // @ts-ignore - [{ functionDeclarations: tools.map((tool) => tool.function) }], + tools.length > 0 + ? [{ functionDeclarations: tools.map((tool) => tool.function) }] + : [], funcs, controller, // parseSSE From f0b3e10a6caf55bf91325183b5ad84de2a05db04 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 25 Oct 2024 18:19:22 +0800 Subject: [PATCH 5/5] hotfix for gemini invald argument #5715 --- app/client/platforms/google.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index 14fecb8f289..a4b594ddfed 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -193,7 +193,8 @@ export class GeminiProApi implements LLMApi { getHeaders(), // @ts-ignore tools.length > 0 - ? [{ functionDeclarations: tools.map((tool) => tool.function) }] + ? // @ts-ignore + [{ functionDeclarations: tools.map((tool) => tool.function) }] : [], funcs, controller,