From 83a5b915e94d06a677c136d0c2c57e42698c2359 Mon Sep 17 00:00:00 2001 From: Michael Yuan Date: Wed, 2 Oct 2024 14:35:57 -0500 Subject: [PATCH 1/3] Update release.yml Fix the file name in release CI --- .github/workflows/release.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 909875f4..f75260df 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -68,9 +68,9 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | cd dist/ - gh release upload ${{ github.event.inputs.release_tags }} moxin_*.deb --clobber - gh release upload ${{ github.event.inputs.release_tags }} moxin_*.tar.gz --clobber - gh release upload ${{ github.event.inputs.release_tags }} moxin_*.AppImage --clobber + gh release upload ${{ github.event.inputs.release_tags }} moly_*.deb --clobber + gh release upload ${{ github.event.inputs.release_tags }} moly_*.tar.gz --clobber + gh release upload ${{ github.event.inputs.release_tags }} moly_*.AppImage --clobber build_macos: name: MacOS @@ -109,7 +109,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | cd dist/ - gh release upload ${{ github.event.inputs.release_tags }} Moxin_*.dmg --clobber + gh release upload ${{ github.event.inputs.release_tags }} Moly_*.dmg --clobber build_windows: name: Windows From 571d09e8d1d970345a91d9d45dd02ada26646b1c Mon Sep 17 00:00:00 2001 From: Michael Yuan Date: Wed, 2 Oct 2024 15:04:34 -0500 Subject: [PATCH 2/3] Update release.yml Use a personal access token to upload release --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f75260df..31c9bc16 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,7 +65,7 @@ jobs: - name: Upload Dist env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.MOLY_RELEASE }} run: | cd dist/ gh release upload ${{ github.event.inputs.release_tags }} moly_*.deb --clobber @@ -106,7 +106,7 @@ jobs: - name: Upload Dist env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.MOLY_RELEASE }} run: | cd dist/ gh release upload ${{ github.event.inputs.release_tags }} Moly_*.dmg --clobber @@ -155,7 +155,7 @@ jobs: ls dist/ - name: Upload Dist env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.MOLY_RELEASE }} run: | cd dist/ $file=Get-ChildItem -Filter *.exe From 21e500643f17fabe1186b06423273e5b8d39eb42 Mon Sep 17 00:00:00 2001 From: AlexZhang Date: Mon, 30 Dec 2024 23:24:06 +0800 Subject: [PATCH 3/3] Fix the response text parsing and encoding issue when the moly and mofa agents communicate locally. --- moly-mofa/src/lib.rs | 97 +++++++++++++++++++++++++++++++----- moly-protocol/src/open_ai.rs | 2 +- src/data/chats/chat.rs | 5 +- src/data/store.rs | 1 - 4 files changed, 88 insertions(+), 17 deletions(-) diff --git a/moly-mofa/src/lib.rs b/moly-mofa/src/lib.rs index 2926cfd7..c5d4437b 100644 --- a/moly-mofa/src/lib.rs +++ b/moly-mofa/src/lib.rs @@ -4,6 +4,7 @@ use moly_protocol::open_ai::{ use serde::{Deserialize, Deserializer, Serialize}; use std::sync::mpsc::{self, channel, Sender}; use tokio::task::JoinHandle; +use serde_json::Value; #[derive(Debug, Serialize, Deserialize)] pub struct MofaResponseReasoner { @@ -104,6 +105,13 @@ pub enum MofaAgentCommand { FetchAgentsFromServer(Sender), } +#[derive(Debug, Serialize, Deserialize)] +struct MofaContent { + step_name: String, + node_results: String, + dataflow_status: bool, +} + #[derive(Clone, Debug)] pub struct MofaClient { command_sender: Sender, @@ -144,9 +152,9 @@ impl MofaClient { } /// Handles the communication between the MofaClient and the MoFa server. - /// + /// /// This function runs in a separate thread and processes commands received through the command channel. - /// + /// /// The loop continues until the command channel is closed or an unrecoverable error occurs. fn process_agent_commands(command_receiver: mpsc::Receiver, address: String) { let rt = tokio::runtime::Runtime::new().unwrap(); @@ -166,23 +174,86 @@ impl MofaClient { content: task, }], }; - let client = reqwest::Client::new(); + + // If access to OpenAI or Claude is restricted in certain regions, a VPN is typically used, + // so communication with the local MoFA service here must bypass the proxy. + let client = reqwest::Client::builder() + .no_proxy() + .build() + .expect("Failed to build client"); let req = client .post(format!("{}/v1/chat/completions", &address)) + .header("Content-Type", "application/json") .json(&data); current_request = Some(rt.spawn(async move { - let resp = req.send().await.expect("Failed to send request"); - - let resp: Result = resp.json().await; - match resp { - Ok(resp) => { - let _ = tx.send(ChatResponse::ChatFinalResponseData(resp.clone())); - } - Err(e) => { - eprintln!("{e}"); + match req.send().await { + Ok(response) => { + if response.status().is_success() { + match response.text().await { + Ok(text) => { + match serde_json::from_str::(&text) { + Ok(value) => { + if let Some(content) = value + .get("choices") + .and_then(|choices| choices.get(0)) + .and_then(|choice| choice.get("message")) + .and_then(|message| message.get("content")) + .and_then(|content| content.as_str()) + { + // parsing inner json + match serde_json::from_str::(content) { + Ok(mofa_content) => { + let response_data = ChatResponseData { + id: value.get("id").and_then(|id| id.as_str()).unwrap_or("").to_string(), + choices: vec![ChoiceData { + finish_reason: StopReason::Stop, + index: 0, + message: MessageData { + content: mofa_content.node_results, + role: Role::Assistant, + }, + logprobs: None, + }], + created: value.get("created") + .and_then(|c| c.as_i64()) + .unwrap_or(0), + model: value.get("model").and_then(|m| m.as_str()).unwrap_or("").to_string(), + system_fingerprint: "".to_string(), + usage: UsageData { + completion_tokens: 0, + prompt_tokens: 0, + total_tokens: 0, + }, + object: value.get("object").and_then(|o| o.as_str()).unwrap_or("").to_string(), + }; + + let _ = tx.send(ChatResponse::ChatFinalResponseData(response_data)); + } + Err(e) => { + eprintln!("Failed to parse content JSON: {}", e); + eprintln!("Content: {}", content); + } + } + } + } + Err(e) => { + eprintln!("Failed to parse response JSON: {}", e); + eprintln!("Response: {}", text); + } + } + } + Err(e) => eprintln!("Failed to get response text: {}", e), + } + } else { + eprintln!("HTTP error: {}", response.status()); + if let Ok(error_text) = response.text().await { + eprintln!("Error details: {}", error_text); + } + } } + Err(e) => eprintln!("Request failed: {}", e), } })); } @@ -232,7 +303,7 @@ impl MofaClient { // For testing purposes pub fn new_fake() -> Self { let (command_sender, command_receiver) = channel(); - + std::thread::spawn(move || { loop { match command_receiver.recv().unwrap() { diff --git a/moly-protocol/src/open_ai.rs b/moly-protocol/src/open_ai.rs index cad63d11..15fb55aa 100644 --- a/moly-protocol/src/open_ai.rs +++ b/moly-protocol/src/open_ai.rs @@ -107,7 +107,7 @@ pub struct UsageData { pub struct ChatResponseData { pub id: String, pub choices: Vec, - pub created: u32, + pub created: i64, pub model: ModelID, #[serde(default)] pub system_fingerprint: String, diff --git a/src/data/chats/chat.rs b/src/data/chats/chat.rs index 0891246a..74ea8601 100644 --- a/src/data/chats/chat.rs +++ b/src/data/chats/chat.rs @@ -428,11 +428,12 @@ impl Chat { std::thread::spawn(move || '_loop: loop { match rx.recv() { Ok(moly_mofa::ChatResponse::ChatFinalResponseData(data)) => { - let node_results = serde_json::from_str::(&data.choices[0].message.content).unwrap(); + // The original JSON data of node_results has been parsed and can be used directly. + let node_results = data.choices[0].clone().message.content; Cx::post_action(ChatEntityAction { chat_id, kind: ChatEntityActionKind::MofaAgentResult( - node_results.node_results + node_results ), }); diff --git a/src/data/store.rs b/src/data/store.rs index 158c2dad..30677705 100644 --- a/src/data/store.rs +++ b/src/data/store.rs @@ -11,7 +11,6 @@ use anyhow::Result; use chrono::{DateTime, Utc}; use makepad_widgets::{Action, ActionDefaultRef, DefaultNone}; use moly_backend::Backend; - use moly_mofa::MofaServerResponse; use moly_protocol::data::{Author, DownloadedFile, File, FileID, Model, ModelID, PendingDownload}; use std::rc::Rc;