Skip to content

Commit 4b9268d

Browse files
committed
fix: Correct error handling and improve file operations
- Save Gemini error responses as JSON for better debugging. - Use `mv -f` to overwrite existing files when renaming. - Use `not $clean` to check the clean flag and process text accordingly.
1 parent 3a4b36f commit 4b9268d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ai_tools.nu

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,7 @@ export def google_ai [
18461846
try {
18471847
return $answer.candidates.content.parts.0.text.0
18481848
} catch {
1849-
$answer | save -f gemini_error.jsom
1849+
$answer | to json | save -f gemini_error.json
18501850
return-error "something went wrong with the api! error saved in gemini_error.json"
18511851
}
18521852
} else if ($model =~ "bison") {
@@ -2312,7 +2312,7 @@ export def "ai analyze_paper" [
23122312
--ollama(-o) #use ollama instead of gemini
23132313
--ollama_model(-m):string #ollama model to use
23142314
--output(-o):string #output filename without extension
2315-
--no_clean(-N) #do not clean text
2315+
--clean(-c) #clean text
23162316
--verbose(-v) #show gemini attempts
23172317
--notify(-n) #send notification when finished
23182318
] {
@@ -2338,15 +2338,15 @@ export def "ai analyze_paper" [
23382338
print (echo-g "converting pdf to text...")
23392339
pdftotext $file
23402340
} else {
2341-
mv $file ($name + ".txt")
2341+
mv -f $file ($name + ".txt")
23422342
}
23432343

23442344
let raw_data = open ($name + ".txt")
23452345

23462346
let output = if ($output | is-empty) {$name + ".md"} else {$output + ".md"}
23472347

23482348
print (echo-g "cleaning text...")
2349-
let data = if $no_clean {$raw_data} else {ai clean-text $raw_data -g $gpt4 -o $ollama -m $ollama_model}
2349+
let data = if not $clean {$raw_data} else {ai clean-text $raw_data -g $gpt4 -o $ollama -m $ollama_model}
23502350
$data | save -f ($name + ".txt")
23512351

23522352
print (echo-g "analyzing paper...")

0 commit comments

Comments
 (0)