microsoft/genaiscript

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

Closed this issue · 5 comments

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)

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

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.

I havd't noticed the attached file! Thanks!

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)

fixed in 1.78.3