Skip to content

Commit

Permalink
fix: fix wrong domain name for xai
Browse files Browse the repository at this point in the history
  • Loading branch information
adolphnov committed Nov 21, 2024
1 parent 4246d49 commit d8b5822
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createAnthropic } from '@ai-sdk/anthropic';
import { createCohere } from '@ai-sdk/cohere';
import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { createOpenAI } from '@ai-sdk/openai';
import { createXai } from '@ai-sdk/xai';
import { type AgentUserConfig, ENV } from '../config/env';
import { log } from '../log/logger';
import { isCfWorker } from '../telegram/utils/utils';
Expand All @@ -13,12 +14,12 @@ import { Anthropic } from './anthropic';
import { AzureChatAI, AzureImageAI } from './azure';
import { Cohere } from './cohere';
import { Google } from './google';

import { Mistral } from './mistralai';
import { Dalle, OpenAI, Transcription } from './openai';
import { OpenAILike, OpenAILikeImage } from './openailike';
import { Vertex } from './vertex';
import { WorkersChat, WorkersImage } from './workersai';
import { XAI } from './xai';

export const CHAT_AGENTS: ChatAgent[] = [
new Anthropic(),
Expand All @@ -30,6 +31,7 @@ export const CHAT_AGENTS: ChatAgent[] = [
new WorkersChat(),
new OpenAILike(),
new Vertex(),
new XAI(),
];

export function loadChatLLM(context: AgentUserConfig): ChatAgent | null {
Expand Down Expand Up @@ -213,6 +215,11 @@ export async function createLlmModel(model: string, context: AgentUserConfig) {
],
useSearchGrounding: context.VERTEX_SEARCH_GROUNDING,
});
case 'xai':
return createXai({
baseURL: context.XAI_API_BASE,
apiKey: context.XAI_API_KEY || undefined,
}).languageModel(model_id, undefined);
default:
return createOpenAI({
name: 'olike',
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class XAIConfig {
// XAI api key
XAI_API_KEY: string | null = null;
// XAI api base
XAI_API_BASE = 'https://api.xai.com/v1';
XAI_API_BASE = 'https://api.x.ai/v1';
// XAI api model
XAI_CHAT_MODEL = 'grok-beta';
XAI_VISION_MODEL = 'grok-vision-beta';
Expand Down
5 changes: 4 additions & 1 deletion src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
OpenAILikeConfig,
VertexConfig,
WorkersConfig,
XAIConfig,
} from './config';
import { ConfigMerger } from './merger';

Expand All @@ -31,7 +32,8 @@ export type AgentUserConfig = Record<string, any> &
AnthropicConfig &
OpenAILikeConfig &
ExtraUserConfig &
VertexConfig;
VertexConfig &
XAIConfig;

function createAgentUserConfig(): AgentUserConfig {
return Object.assign(
Expand All @@ -49,6 +51,7 @@ function createAgentUserConfig(): AgentUserConfig {
new OpenAILikeConfig(),
new ExtraUserConfig(),
new VertexConfig(),
new XAIConfig(),
);
}

Expand Down

0 comments on commit d8b5822

Please sign in to comment.