-
Notifications
You must be signed in to change notification settings - Fork 353
feat: extending AI support for multi-providers #1590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add ANTHROPIC_BASE_URL and ANTHROPIC_DEPLOYMENT_NAME environment variables - Update Anthropic client configuration to support both direct API and Azure endpoints - Maintain backward compatibility with existing direct Anthropic API setup - Use deployment name when Azure endpoint is configured, otherwise default model Fixes hyperdxio#1588
|
|
@gyancr7 is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
packages/api/src/routers/api/ai.ts
Outdated
| // const model = anthropic('claude-3-5-haiku-latest'); | ||
| const model = anthropic('claude-sonnet-4-5-20250929'); | ||
| // Use Azure deployment name if configured, otherwise use default model | ||
| const modelName = config.ANTHROPIC_DEPLOYMENT_NAME || 'claude-sonnet-4-5-20250929'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change this to AI_MODEL_NAME? Want to try and keep model name configuration generic (so we can add providers in the future)
packages/api/src/routers/api/ai.ts
Outdated
|
|
||
| const anthropic = createAnthropic({ | ||
| // Support both direct Anthropic API and Azure AI endpoints | ||
| const anthropicConfig: any = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we type this configuration? Something like this:
type AnthropicConfig = NonNullable<Parameters<typeof createAnthropic>[0]>;
const payload: AnthropicConfig = {
apiKey: config.ANTHROPIC_API_KEY,
};
packages/api/src/routers/api/ai.ts
Outdated
| anthropicConfig.baseURL = config.ANTHROPIC_BASE_URL; | ||
| } | ||
|
|
||
| const anthropic = createAnthropic(anthropicConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to do this, but if you are open to it, I would love to make this easier for others to extend since we've had a few issues about supporting other providers.
What I was thinking is we create a new file and function called getAIModel in api/src/controllers/ai.ts This function helps abstract some of this code so we can reuse this and add AI to other spots.
import { anthropic } from '@ai-sdk/anthropic'
import type { LanguageModel } from 'ai'
export function getAIModel(): LanguageModel {
const modelName = config.AI_MODEL_NAME
if (!config.ANTHROPIC_API_KEY) {
throw new Error('No ANTHROPIC_API_KEY defined');
}
/// your logic here
return model;
}
Then, down the road, we can enhance this function to do something like config.AI_PROVIDER and if it's set to openai or something else we have all the logic in one spot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes complete sense, I would be happy to contribute for this.
…safety - Create getAIModel() function in controllers/ai.ts with proper TypeScript types - Add provider-agnostic config: AI_PROVIDER, AI_API_KEY, AI_MODEL_NAME - Support future providers (OpenAI, Azure OpenAI, Google) via architecture - Maintain backward compatibility with ANTHROPIC_API_KEY Addresses PR hyperdxio#1590 feedback from brandon-pereira Fixes hyperdxio#1588
|
@brandon-pereira I have tried addressing the review comments in this commit 6a9c24f |
Overview
Adds support for Azure AI Anthropic API endpoints alongside the existing direct Anthropic API, with an extensible architecture that simplifies future integration of additional AI providers (OpenAI, Azure OpenAI, Google Gemini, etc.).
Problem
HyperDX currently only supports Anthropic's direct API for AI-powered query assistance. Organizations using Azure AI services cannot integrate Anthropic models through Azure's infrastructure.
Solution
1. Core Refactoring
New
controllers/ai.ts:getAIModel()function for all AI configurationUpdated
config.ts:Simplified
routers/api/ai.ts:const model = getAIModel()2. Configuration
New Environment Variables (Recommended)
Legacy Variables (Still Supported)
Fixes #1588