feat: Add OpenAI provider support for AI assistance#1960
Open
vinzee wants to merge 9 commits intohyperdxio:mainfrom
Open
feat: Add OpenAI provider support for AI assistance#1960vinzee wants to merge 9 commits intohyperdxio:mainfrom
vinzee wants to merge 9 commits intohyperdxio:mainfrom
Conversation
|
@vinzee is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: cea33b8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
PR Review
Otherwise the implementation is clean, tests are comprehensive, error messages are helpful, and the pattern follows existing conventions in the codebase. |
c9115f5 to
6506b05
Compare
Enables using OpenAI-compatible endpoints (OpenAI, Azure OpenAI, OpenRouter, LiteLLM proxies) as an alternative to Anthropic for AI-powered query assistance. Adds support for custom headers (X-Client-Id, X-Username) and request body customization via AI_EXTRA_BODY for proxy/gateway compatibility. Enhances error logging with detailed API call diagnostics. Also upgrades sql-formatter to 15.7.0 to address breaking API changes.
- Require `AI_MODEL_NAME` explicitly for the OpenAI provider instead of falling back to an Anthropic model ID (`claude-sonnet-4-5-20250929`) which would fail against actual OpenAI endpoints - Add error handling around `JSON.parse(AI_EXTRA_BODY)` so invalid JSON throws a descriptive config error instead of an unhandled exception - Move `AI_CLIENT_ID`, `AI_USERNAME`, and `AI_EXTRA_BODY` into the config module for consistency with other AI env vars - Truncate `responseBody` in error logs to 500 chars to avoid leaking sensitive data from provider error responses
- Remove accidentally committed package-lock.json (37k lines) and add it to .gitignore -- this is a Yarn 4.5.1 workspace project - Log a warning when AI_EXTRA_BODY custom fetch cannot parse the request body as JSON, instead of silently forwarding it unmodified
This commit introduces a new test file to thoroughly validate the `getAIModel` function. The tests cover various scenarios including provider routing, API key handling, base URL configuration, model name selection, custom headers for OpenAI, and the `AI_EXTRA_BODY` functionality. This ensures robust and predictable behavior for AI model instantiation based on environment variables.
abbc4df to
95c3723
Compare
Replaced `AI_CLIENT_ID` and `AI_USERNAME` environment variables with a single `AI_REQUEST_HEADERS` variable. This new variable accepts a JSON string, allowing users to define arbitrary custom headers for AI provider requests. This change enhances the extensibility of AI provider integrations. Additionally, improved error handling for AI API call failures by providing more concise error messages and removing excessive logging of truncated response bodies.
a2f2d01 to
cea33b8
Compare
Member
|
@vinzee PR LGTM! Nice work! There is some linting issues, otherwise this is good to go :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add OpenAI-compatible provider support for AI-powered chart assistance, enabling use of any OpenAI Chat Completions-compatible endpoint (Azure OpenAI, OpenRouter, LiteLLM proxies) as an alternative to Anthropic.
Key changes:
getOpenAIModel()incontrollers/ai.tsusing@ai-sdk/openaiAI_CLIENT_ID/AI_USERNAMEenv varsAI_EXTRA_BODYenv var (JSON),useful for proxy/gateway compatibility (e.g. LiteLLM passthrough mode)
body, URL) to aid debugging provider issues
sql-formatter's breaking rename ofreservedPhrasestoreservedKeywordPhrasesin theTokenizerOptionsinterfaceScreenshots or video
How to test locally or on Vercel
AI_PROVIDER=openai,AI_API_KEY=<key>,AI_BASE_URL=<endpoint>,AI_MODEL_NAME=<model>AI_CLIENT_ID,AI_USERNAMEfor custom headersAI_EXTRA_BODY='{"passthrough":true}'for extra body fieldsReferences