Skip to content

Using Chat Completions#17

Open
alicecarra wants to merge 2 commits intoyanxiaodi:mainfrom
alicecarra:using-chat-completions
Open

Using Chat Completions#17
alicecarra wants to merge 2 commits intoyanxiaodi:mainfrom
alicecarra:using-chat-completions

Conversation

@alicecarra
Copy link
Copy Markdown

Resolve error described in #16

@alicecarra
Copy link
Copy Markdown
Author

Needs better null handling

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the OpenAI integration to use the Chat Completions endpoint, addressing Issue #16 where chat models were being sent to the legacy /v1/completions endpoint and returning a 404.

Changes:

  • Switch OpenAI requests from completions.create to chat.completions.create and update response parsing accordingly.
  • Bump the extension version and upgrade the openai npm dependency.
  • Update package-lock.json to reflect dependency graph changes from the openai upgrade.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/openai-service.ts Migrates revision/translation calls to chat.completions and reads output from choices[0].message.content.
package.json Bumps extension version to 0.0.7 and upgrades openai to ^4.70.0.
package-lock.json Updates locked openai version and transitive dependency set after upgrade.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/openai-service.ts
Comment on lines +46 to +47
let result = response.choices[0].message.content;
return result ?? "null response lol";
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response.choices[0].message.content can be null/undefined (and choices[0] can be missing). Returning the literal fallback string "null response lol" will insert user-visible garbage and is unprofessional. Please add a proper guard (e.g., check choices.length and message.content) and either return undefined per the interface or throw a descriptive error/message when the API returns no content.

Copilot uses AI. Check for mistakes.
Comment thread src/openai-service.ts
Comment on lines +71 to +73
let result = response.choices[0].message.content;
// FIX ME: Not the best null handling...
return result ?? "null response lol";
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving a TODO-style comment (// FIX ME: Not the best null handling...) alongside the placeholder fallback string makes this behavior knowingly incorrect. Please implement proper empty-response handling here as well (guard missing choices/content and return undefined or surface a clear error to the user), and remove the TODO/placeholder text.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants