mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-30 16:26:59 +02:00
feat(core): Add xAI Grok provider support for chat hub (no-changelog) (#22084)
This commit is contained in:
parent
72cdca23d6
commit
fde05ce697
|
|
@ -18,6 +18,7 @@ export const chatHubLLMProviderSchema = z.enum([
|
|||
'azureOpenAi',
|
||||
'ollama',
|
||||
'awsBedrock',
|
||||
'xAiGrok',
|
||||
'groq',
|
||||
'openRouter',
|
||||
'deepSeek',
|
||||
|
|
@ -47,6 +48,7 @@ export const PROVIDER_CREDENTIAL_TYPE_MAP: Record<
|
|||
ollama: 'ollamaApi',
|
||||
azureOpenAi: 'azureOpenAiApi',
|
||||
awsBedrock: 'aws',
|
||||
xAiGrok: 'xAiApi',
|
||||
groq: 'groqApi',
|
||||
openRouter: 'openRouterApi',
|
||||
deepSeek: 'deepSeekApi',
|
||||
|
|
@ -89,6 +91,11 @@ const awsBedrockModelSchema = z.object({
|
|||
model: z.string(),
|
||||
});
|
||||
|
||||
const xAiGrokModelSchema = z.object({
|
||||
provider: z.literal('xAiGrok'),
|
||||
model: z.string(),
|
||||
});
|
||||
|
||||
const groqModelSchema = z.object({
|
||||
provider: z.literal('groq'),
|
||||
model: z.string(),
|
||||
|
|
@ -131,6 +138,7 @@ export const chatHubConversationModelSchema = z.discriminatedUnion('provider', [
|
|||
azureOpenAIModelSchema,
|
||||
ollamaModelSchema,
|
||||
awsBedrockModelSchema,
|
||||
xAiGrokModelSchema,
|
||||
groqModelSchema,
|
||||
openRouterModelSchema,
|
||||
deepSeekModelSchema,
|
||||
|
|
@ -146,6 +154,7 @@ export type ChatHubGoogleModel = z.infer<typeof googleModelSchema>;
|
|||
export type ChatHubAzureOpenAIModel = z.infer<typeof azureOpenAIModelSchema>;
|
||||
export type ChatHubOllamaModel = z.infer<typeof ollamaModelSchema>;
|
||||
export type ChatHubAwsBedrockModel = z.infer<typeof awsBedrockModelSchema>;
|
||||
export type ChatHubXAiGrokModel = z.infer<typeof xAiGrokModelSchema>;
|
||||
export type ChatHubGroqModel = z.infer<typeof groqModelSchema>;
|
||||
export type ChatHubOpenRouterModel = z.infer<typeof openRouterModelSchema>;
|
||||
export type ChatHubDeepSeekModel = z.infer<typeof deepSeekModelSchema>;
|
||||
|
|
@ -158,6 +167,7 @@ export type ChatHubBaseLLMModel =
|
|||
| ChatHubAzureOpenAIModel
|
||||
| ChatHubOllamaModel
|
||||
| ChatHubAwsBedrockModel
|
||||
| ChatHubXAiGrokModel
|
||||
| ChatHubGroqModel
|
||||
| ChatHubOpenRouterModel
|
||||
| ChatHubDeepSeekModel
|
||||
|
|
@ -205,6 +215,7 @@ export const emptyChatModelsResponse: ChatModelsResponse = {
|
|||
azureOpenAi: { models: [] },
|
||||
ollama: { models: [] },
|
||||
awsBedrock: { models: [] },
|
||||
xAiGrok: { models: [] },
|
||||
groq: { models: [] },
|
||||
openRouter: { models: [] },
|
||||
deepSeek: { models: [] },
|
||||
|
|
|
|||
|
|
@ -512,6 +512,15 @@ export class ChatHubWorkflowService {
|
|||
},
|
||||
};
|
||||
}
|
||||
case 'xAiGrok': {
|
||||
return {
|
||||
...common,
|
||||
parameters: {
|
||||
model,
|
||||
options: {},
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'groq': {
|
||||
return {
|
||||
...common,
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ export const PROVIDER_NODE_TYPE_MAP: Record<ChatHubLLMProvider, INodeTypeNameVer
|
|||
name: '@n8n/n8n-nodes-langchain.lmChatAwsBedrock',
|
||||
version: 1.1,
|
||||
},
|
||||
xAiGrok: {
|
||||
name: '@n8n/n8n-nodes-langchain.lmChatXAiGrok',
|
||||
version: 1,
|
||||
},
|
||||
groq: {
|
||||
name: '@n8n/n8n-nodes-langchain.lmChatGroq',
|
||||
version: 1,
|
||||
|
|
|
|||
|
|
@ -166,6 +166,8 @@ export class ChatHubService {
|
|||
return await this.fetchAzureOpenAiModels(credentials, additionalData);
|
||||
case 'awsBedrock':
|
||||
return await this.fetchAwsBedrockModels(credentials, additionalData);
|
||||
case 'xAiGrok':
|
||||
return await this.fetchXAiGrokModels(credentials, additionalData);
|
||||
case 'groq':
|
||||
return await this.fetchGroqModels(credentials, additionalData);
|
||||
case 'openRouter':
|
||||
|
|
@ -769,6 +771,62 @@ export class ChatHubService {
|
|||
};
|
||||
}
|
||||
|
||||
private async fetchXAiGrokModels(
|
||||
credentials: INodeCredentials,
|
||||
additionalData: IWorkflowExecuteAdditionalData,
|
||||
): Promise<ChatModelsResponse['xAiGrok']> {
|
||||
const results = await this.nodeParametersService.getOptionsViaLoadOptions(
|
||||
{
|
||||
routing: {
|
||||
request: {
|
||||
method: 'GET',
|
||||
url: '/models',
|
||||
},
|
||||
output: {
|
||||
postReceive: [
|
||||
{
|
||||
type: 'rootProperty',
|
||||
properties: {
|
||||
property: 'data',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'setKeyValue',
|
||||
properties: {
|
||||
name: '={{$responseItem.id}}',
|
||||
value: '={{$responseItem.id}}',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'sort',
|
||||
properties: {
|
||||
key: 'name',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
additionalData,
|
||||
PROVIDER_NODE_TYPE_MAP.xAiGrok,
|
||||
{},
|
||||
credentials,
|
||||
);
|
||||
|
||||
return {
|
||||
models: results.map((result) => ({
|
||||
name: result.name,
|
||||
description: result.description ?? null,
|
||||
model: {
|
||||
provider: 'xAiGrok',
|
||||
model: String(result.value),
|
||||
},
|
||||
createdAt: null,
|
||||
updatedAt: null,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
private async fetchAgentWorkflowsAsModels(user: User): Promise<ChatModelsResponse['n8n']> {
|
||||
const nodeTypes = [CHAT_TRIGGER_NODE_TYPE];
|
||||
const workflows = await this.workflowService.getWorkflowsWithNodesIncluded(
|
||||
|
|
|
|||
|
|
@ -140,6 +140,7 @@ export const maxContextWindowTokens: Record<ChatHubLLMProvider, Record<string, n
|
|||
azureOpenAi: {},
|
||||
ollama: {},
|
||||
awsBedrock: {},
|
||||
xAiGrok: {},
|
||||
groq: {},
|
||||
openRouter: {},
|
||||
deepSeek: {},
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ export const providerDisplayNames: Record<ChatHubProvider, string> = {
|
|||
azureOpenAi: 'Azure OpenAI',
|
||||
ollama: 'Ollama',
|
||||
awsBedrock: 'AWS Bedrock',
|
||||
xAiGrok: 'xAI Grok',
|
||||
groq: 'Groq',
|
||||
openRouter: 'OpenRouter',
|
||||
deepSeek: 'DeepSeek',
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user