detailed logs
This commit is contained in:
@@ -56,16 +56,17 @@ async fn translate(
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
if !payload.stream {
|
||||
let data = res.json::<OpenAIResponse>().await.map_err(|e| e.to_string())?;
|
||||
return Ok(data.choices.get(0).and_then(|c| c.message.as_ref()).map(|m| m.content.clone()).unwrap_or_default());
|
||||
let text = res.text().await.map_err(|e| e.to_string())?;
|
||||
return Ok(text);
|
||||
}
|
||||
|
||||
let mut stream = res.bytes_stream();
|
||||
let mut full_response = String::new();
|
||||
let mut raw_stream_log = String::new();
|
||||
|
||||
while let Some(item) = stream.next().await {
|
||||
let chunk = item.map_err(|e| e.to_string())?;
|
||||
let text = String::from_utf8_lossy(&chunk);
|
||||
raw_stream_log.push_str(&text);
|
||||
|
||||
for line in text.lines() {
|
||||
let line = line.trim();
|
||||
@@ -77,7 +78,6 @@ async fn translate(
|
||||
if let Some(choice) = json.choices.get(0) {
|
||||
if let Some(delta) = &choice.delta {
|
||||
if let Some(content) = &delta.content {
|
||||
full_response.push_str(content);
|
||||
app.emit("translation-chunk", content).map_err(|e| e.to_string())?;
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ async fn translate(
|
||||
}
|
||||
}
|
||||
|
||||
Ok(full_response)
|
||||
Ok(raw_stream_log)
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
|
||||
Reference in New Issue
Block a user