forked from TBXark/ChatGPT-Telegram-Workers
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add independent configuration for xai
fix: fix non-fourm groups, no response when replying to bot /new commands alone. fix telegraph debug messages with no specific information. chore: add action every time you send a message. chore: emove some reduntant code
- Loading branch information
Showing
23 changed files
with
562 additions
and
22,737 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { AgentUserConfig } from '../config/env'; | ||
import type { ChatAgent, ChatStreamTextHandler, LLMChatParams, LLMChatRequestParams, ResponseMessage } from './types'; | ||
import { createXai } from '@ai-sdk/xai'; | ||
import { warpLLMParams } from '.'; | ||
import { requestChatCompletionsV2 } from './request'; | ||
|
||
export class XAI implements ChatAgent { | ||
readonly name = 'xai'; | ||
readonly modelKey = 'XAI_CHAT_MODEL'; | ||
|
||
readonly enable = (context: AgentUserConfig): boolean => { | ||
return !!(context.XAI_API_KEY); | ||
}; | ||
|
||
readonly model = (ctx: AgentUserConfig, params?: LLMChatRequestParams): string => { | ||
return Array.isArray(params?.content) ? ctx.XAI_VISION_MODEL : ctx.XAI_CHAT_MODEL; | ||
}; | ||
|
||
readonly request = async (params: LLMChatParams, context: AgentUserConfig, onStream: ChatStreamTextHandler | null): Promise<{ messages: ResponseMessage[]; content: string }> => { | ||
const provider = createXai({ | ||
baseURL: context.XAI_API_BASE, | ||
apiKey: context.XAI_API_KEY || undefined, | ||
}); | ||
const languageModelV1 = provider.languageModel(this.model(context), undefined); | ||
return requestChatCompletionsV2(await warpLLMParams({ | ||
model: languageModelV1, | ||
messages: params.messages, | ||
}, context), onStream); | ||
}; | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.