ColinEberhardt / langchain-mini

🦜️🔗 This is a very simple re-implementation of LangChain, in ~100 lines of code
MIT License
248 stars 36 forks source link

Error- Cannot read properties of undefined (reading '0') #1

Open brinrbc opened 1 year ago

brinrbc commented 1 year ago

Hi! Thank you very much for your work. Please tell me which way to look. When I start, I get this error, I see the problem, but I can't figure out what to do.

How can I help? Who is Neil Armstrong?
file:///User/GitHub/langchain-mini/index.mjs:59
    .then((res) => res.choices[0].text)
                              ^

TypeError: Cannot read properties of undefined (reading '0')
    at file:///User/GitHub/langchain-mini/index.mjs:59:31
    at process.process Ticks And Rejection (node:internal/process/task_queues:95:5)
    at asynccomplete Prompt (file:///User/GitHub/langchain-mini/index.mjs:43:3)
    at async answer Question (file:///User/GitHub/langchain-mini/index.mjs:77:22)
    at async file:///User/GitHub/langchain-mini/index.mjs:109:18

Node.js v18.15.0

The line index.mjs:59 says .then((res) => res.choices[0].text)

MikeRalphson commented 1 year ago

Do you have a SERPAPI_API_KEY defined in your .env file?

ColinEberhardt commented 1 year ago

Hi @brinrbc - thanks for raising this issue. This project is intended for educational purposes, to help you learn how to create 'chain of reasoning' applications with LLM. It isn't designed to be production ready. As a result, the code lacks any error checking :-)

This is your opportunity to learn! Clearly the OpenAI API has not returned the expected result. I'd recommend adding a console.log or breakpoint at that line of code to find out what it returned instead. It will likely be an error message (perhaps a lack of API as @MikeRalphson pointed out), that you can then debug.

brinrbc commented 1 year ago

Do you have a SERPAPI_API_KEY defined in your .env file?

if we are talking about this Api key 2996*...3f96df from this address https://serpapi.com/manage-api-key , then yes, it is.