feat(core): Add Cohere provider support for chat hub (no-changelog) (#22068)

This commit is contained in:
Jaakko Husso 2025-11-20 17:00:08 +02:00 committed by GitHub
parent 2681c7033e
commit da5c8ff3c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 85 additions and 0 deletions

View File

@ -18,6 +18,7 @@ export const chatHubLLMProviderSchema = z.enum([
'azureOpenAi',
'ollama',
'awsBedrock',
'cohere',
'mistralCloud',
]);
export type ChatHubLLMProvider = z.infer<typeof chatHubLLMProviderSchema>;
@ -43,6 +44,7 @@ export const PROVIDER_CREDENTIAL_TYPE_MAP: Record<
ollama: 'ollamaApi',
azureOpenAi: 'azureOpenAiApi',
awsBedrock: 'aws',
cohere: 'cohereApi',
mistralCloud: 'mistralCloudApi',
};
@ -81,6 +83,11 @@ const awsBedrockModelSchema = z.object({
model: z.string(),
});
const cohereModelSchema = z.object({
provider: z.literal('cohere'),
model: z.string(),
});
const mistralCloudModelSchema = z.object({
provider: z.literal('mistralCloud'),
model: z.string(),
@ -103,6 +110,7 @@ export const chatHubConversationModelSchema = z.discriminatedUnion('provider', [
azureOpenAIModelSchema,
ollamaModelSchema,
awsBedrockModelSchema,
cohereModelSchema,
mistralCloudModelSchema,
n8nModelSchema,
chatAgentSchema,
@ -114,6 +122,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 ChatHubCohereModel = z.infer<typeof cohereModelSchema>;
export type ChatHubMistralCloudModel = z.infer<typeof mistralCloudModelSchema>;
export type ChatHubBaseLLMModel =
| ChatHubOpenAIModel
@ -122,6 +131,7 @@ export type ChatHubBaseLLMModel =
| ChatHubAzureOpenAIModel
| ChatHubOllamaModel
| ChatHubAwsBedrockModel
| ChatHubCohereModel
| ChatHubMistralCloudModel;
export type ChatHubN8nModel = z.infer<typeof n8nModelSchema>;
@ -165,6 +175,7 @@ export const emptyChatModelsResponse: ChatModelsResponse = {
azureOpenAi: { models: [] },
ollama: { models: [] },
awsBedrock: { models: [] },
cohere: { models: [] },
mistralCloud: { models: [] },
n8n: { models: [] },
// eslint-disable-next-line @typescript-eslint/naming-convention

View File

@ -510,6 +510,15 @@ export class ChatHubWorkflowService {
},
};
}
case 'cohere': {
return {
...common,
parameters: {
model,
options: {},
},
};
}
case 'mistralCloud': {
return {
...common,

View File

@ -36,6 +36,10 @@ export const PROVIDER_NODE_TYPE_MAP: Record<ChatHubLLMProvider, INodeTypeNameVer
name: '@n8n/n8n-nodes-langchain.lmChatAwsBedrock',
version: 1.1,
},
cohere: {
name: '@n8n/n8n-nodes-langchain.lmChatCohere',
version: 1,
},
mistralCloud: {
name: '@n8n/n8n-nodes-langchain.lmChatMistralCloud',
version: 1,

View File

@ -164,6 +164,8 @@ export class ChatHubService {
return await this.fetchAzureOpenAiModels(credentials, additionalData);
case 'awsBedrock':
return await this.fetchAwsBedrockModels(credentials, additionalData);
case 'cohere':
return await this.fetchCohereModels(credentials, additionalData);
case 'mistralCloud':
return await this.fetchMistralCloudModels(credentials, additionalData);
case 'n8n':
@ -534,6 +536,63 @@ export class ChatHubService {
};
}
private async fetchCohereModels(
credentials: INodeCredentials,
additionalData: IWorkflowExecuteAdditionalData,
): Promise<ChatModelsResponse['cohere']> {
const results = await this.nodeParametersService.getOptionsViaLoadOptions(
{
routing: {
request: {
method: 'GET',
url: '/v1/models?page_size=100&endpoint=chat',
},
output: {
postReceive: [
{
type: 'rootProperty',
properties: {
property: 'models',
},
},
{
type: 'setKeyValue',
properties: {
name: '={{$responseItem.name}}',
value: '={{$responseItem.name}}',
description: '={{$responseItem.description}}',
},
},
{
type: 'sort',
properties: {
key: 'name',
},
},
],
},
},
},
additionalData,
PROVIDER_NODE_TYPE_MAP.cohere,
{},
credentials,
);
return {
models: results.map((result) => ({
name: result.name,
description: result.description ?? null,
model: {
provider: 'cohere',
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(

View File

@ -140,6 +140,7 @@ export const maxContextWindowTokens: Record<ChatHubLLMProvider, Record<string, n
azureOpenAi: {},
ollama: {},
awsBedrock: {},
cohere: {},
mistralCloud: {},
};

View File

@ -14,6 +14,7 @@ export const providerDisplayNames: Record<ChatHubProvider, string> = {
azureOpenAi: 'Azure OpenAI',
ollama: 'Ollama',
awsBedrock: 'AWS Bedrock',
cohere: 'Cohere',
mistralCloud: 'Mistral Cloud',
n8n: 'n8n',
'custom-agent': 'Custom Agent',