microsoft / genaiscript

Automatable GenAI Scripting
https://microsoft.github.io/genaiscript/
MIT License
2k stars 113 forks source link

CSV.parse() fails with `buf.slice is not a function` #894

Closed wasdee closed 10 hours ago

wasdee commented 2 days ago

ExhibitorClean1.csv

error log

$ genaiscript run perplexity_test_2.genai.mts 
(node:32472) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
genaiscript: perplexity_test_2.genai.mts
trace: /home/ben/Devs/notes/Acitivities/Bauma China 2024/Company/.genaiscript/runs/perplexity_test_2/2024-11-24T02-07-09-666Z.trace.md
buf.slice is not a function
TypeError: buf.slice is not a function
    at Object.parse (/home/ben/.local/share/mise/installs/npm-genaiscript/1.78.3/lib/node_modules/genaiscript/built/genaiscript.cjs:56367:38)
    at parse2 (/home/ben/.local/share/mise/installs/npm-genaiscript/1.78.3/lib/node_modules/genaiscript/built/genaiscript.cjs:56786:23)
    at Object.CSVParse [as parse] (/home/ben/.local/share/mise/installs/npm-genaiscript/1.78.3/lib/node_modules/genaiscript/built/genaiscript.cjs:58153:10)
    at file:///home/ben/Devs/notes/Acitivities/Bauma%20China%202024/Company/perplexity_test_2.genai.mts?tsx-namespace=1732414029941:1:98
genaiscript: error
  trace: /home/ben/Devs/notes/Acitivities/Bauma China 2024/Company/.genaiscript/runs/perplexity_test_2/2024-11-24T02-07-09-666Z.trace.md
buf.slice is not a function

reproducible

script({
    model: "small",
    // model: "perplexity:llama-3.1-sonar-small-128k-online",
    // model: "perplexity:llama-3.1-sonar-large-128k-online",
    // model: "perplexity:llama-3.1-sonar-huge-128k-online",
})

const csv = await workspace.readText("ExhibitorClean1.csv")
const rows = CSV.parse(csv)

console.log(rows)
pelikhan commented 1 day ago

It probably failed to read the file. Try console.log(csv) to see what it read.

workspace.readText(...) takes a relative path to the workspace so that might be the issue

wasdee commented 19 hours ago

File is normal. Generated by pandas, python. Tested read by others already

Console.log the file show expected filename and its contents

Path was relative from the start.

pelikhan commented 11 hours ago

I havd't noticed the attached file! Thanks!

pelikhan commented 10 hours ago

To correct this issue, pass "csv.content" to the parse function. I'll make the APIs more resilient to this kind of mistakes in the next release. Thank you for reporting!

script({
    model: "small",
    // model: "perplexity:llama-3.1-sonar-small-128k-online",
    // model: "perplexity:llama-3.1-sonar-large-128k-online",
    // model: "perplexity:llama-3.1-sonar-huge-128k-online",
})

const csv = await workspace.readText("ExhibitorClean1.csv")
const rows = CSV.parse(csv.content) // use .content here
console.log(rows)
pelikhan commented 10 hours ago

fixed in 1.78.3