PicoCreator / smol-dev-js

Smol personal AI, for smol incremental tasks in a JS project
MIT License
322 stars 52 forks source link

`spec2code` command results in `getChatCompletion` error #4

Open peerasak-u opened 1 year ago

peerasak-u commented 1 year ago

When running the $ smol-dev-js spec2code command, I encountered a fetch error, causing the command to fail. Here's the error message I received:

❯ smol-dev-js spec2code
🐣 [ai]: Based on the provided feedback, I will regenerate all code files that have corresponding spec defined. Here's the updated plan:

1. Update `wage-cal.js` file:
   - Ensure the `wageCalculator` and `timeToMinutes` functions are implemented according to the spec.

2. Update `index.html` file:
   - Ensure the UI elements are created as described in the spec, including input fields for start and end dates, punch time table, and total wage input field.
   - Apply TailwindCSS for styling.

3. Update `main.js` file:
   - Implement the `addPunchTimeRecord` and `calculateTotalWage` functions accordin to the spec.

After updating the code files, I will provide the updated files for you to review.
βœ” [you]: Proceed with the plan? … yes
🐣 [ai]: Working on the plan ...
🐣 [ai]: Studying 0 dependencies (in parallel)
🐣 [ai]: Performing any required modules install / file moves / deletion
🐣 [ai]: Studying 0 dependencies (awaiting in parallel)
🐣 [ai]: Preparing summaries for smol-er sub-operations ...
## Unable to handle prompt for ...
{"model":"gpt-4","temperature":0,"max_tokens":6721,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"messages":[{"role":"user","content":"You are an AI developer assitant who is trying to write a program that will generate code for the user based on their intent\n\nThe following are some details of the project ...\n\nProject short description :\n```\nDaily Wage Calculator\n```\n\n\n\n\n\nspecification file list, in the `specs` folder :\n```\nNOTES.md\n```\n\nsource code file list, in the `src` folder :\n```\n\n```\n\nList of actions you the AI dev can do for the user (you are not allowed to do anything else):\n- Move files or folders\n- Delete files or folders\n- Generate/Edit a code/spec file, with the given instructions\n- Update code/spec from spec/code\n\nYou are not able to do the following (ask the user to do it instead):\n- run and test the code\n- compile or commit changes\n\n(You do not need to let the user know about the above list, as they are for your own use)\n\nNote: that AI notes provided are internal only, for your own use. Parts of it maybe outdated\n\n\n\n'AI notes' for the overall project :\n```\nutf-8\n```\nNote: The following spec files content/notes maybe outdated\n\nTop level spec file content (README.md) :\n```\n# A daily wage calculator\n\nA web app that calculates the daily wage of a worker based on the punch in and punch out time. use tailwindcss for styling.\n\n## Files\n\n### wage-cal.js   \n\nA JS file that contains the logic for calculating the daily wage. contains following functions:\n- wageCalculator: takes the punch in and punch out time and returns the daily wage. (input should be array of punch time records and the punch time record should contain 3 periods key \"morning\", \"afternoon\", \"evening\" and each period should contain \"puch in\" and \"punch put\" in \"hh:mm\" format)\n- timeToMinutes: takes the time in hh:mm format and returns the time in minutes.\n\n### index.html  \n\nHTML file that contains the UI. contains following elements:\n- date start: input field for start date\n- date end: input field for end date\n- punch time table: table that contains the columns:\n  - date: display date of the punch time record\n  - morning in: input field for morning punch in time \n  - morning out: input field for morning punch out time\n  - afternoon in: input field for afternoon punch in time\n  - afternoon out: input field for afternoon punch out time\n  - evening in: input field for evening punch in time\n  - evening out: input field for evening punch out time\n  - total: minutes worked in the day\n- total wage: input field that shows the total wage from start date to end date\n\n### main.js   \n\nA JS file that contains the logic for the UI. contains following functions:\n- addPunchTimeRecord: adds a new punch time record to the punch time table\n- calculateTotalWage: calculates the total wage from start date to end date and shows it in the total wage input field\n```\n\nTop level spec file notes (NOTES.md) :\n```\nall punch time that input to this web is timezone `UTC+7`\n```\n\nThe following is the current plan you the AI developer has drafted, after several rounds of user feedback :\n```\nBased on the provided feedback, I will regenerate all code files that have corresponding spec defined. Here's the updated plan:\n\n1. Update `wage-cal.js` file:\n   - Ensure the `wageCalculator` and `timeToMinutes` functions are implemented according to the spec.\n   \n2. Update `index.html` file:\n   - Ensure the UI elements are created as described in the spec, including input fields for start and end dates, punch time table, and total wage input field.\n   - Apply TailwindCSS for styling.\n\n3. Update `main.js` file:\n   - Implement the `addPunchTimeRecord` and `calculateTotalWage` functions according to the spec.\n\nAfter updating the code files, I will provide the updated files for you to review.\n```\n\nThe following is the user prompt history for the current plan (in json array) :\n```\n[\"Regenerate all code files which has the corresponding spec defined (ensure all files are updated)\"]\n```\n\nThe files we have decided to generate are: [\"wage-cal.js\",\"index.html\",\"main.js\"]\n\nThe following is some details of local dependencies which you can use ...\n\n\nNow that we have a list of files, we need to understand what dependencies they share\nPlease name and briefly describe what is shared between the files we are generating, including exported variables, data schemas, class names, or id names of every DOM elements that javascript functions will use, message names, and function names\nFor ID names, make sure its clear its an ID using a # prefix (similar to css style selectors)\nExclusively focus on the names of the shared dependencies, and do not add any other explanation"}]}
## Recieved error ...
TypeError: fetch failed
Error: Missing valid openai response, please check warn logs for more details
    at getChatCompletion (/opt/homebrew/lib/node_modules/smol-dev-js/node_modules/ai-bridge/src/openai/getChatCompletion.js:290:8)
    at async Object.promiseGenerator (/opt/homebrew/lib/node_modules/smol-dev-js/node_modules/ai-bridge/src/AiBridge.js:249:11)

I have investigated the issue by attempting to use the same message request with getChatCompletion from ai-bridge, but I still receive the same error as before. However, when I tried using createChatCompletion from the openai library, it worked without any issues. Based on this, I believe that the problem is occurring specifically with ai-bridge.