-
Notifications
You must be signed in to change notification settings - Fork 29k
Add Straico Chat Model Node #15881
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
Closed
Closed
Add Straico Chat Model Node #15881
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b1b432f
Add files via upload
nlp-deutschland-de 27e157e
Merge branch 'n8n-io:master' into master
nlp-deutschland-de 50df0db
Add files via upload
nlp-deutschland-de 2258050
Update AgentV1.node.ts
nlp-deutschland-de 7f7f72a
Update AgentV2.node.ts
nlp-deutschland-de dc673e0
Update package.json
nlp-deutschland-de 5b23bb8
Update LmChatStraico.node.ts
nlp-deutschland-de 209fa97
Update LmChatStraico.node.ts
nlp-deutschland-de 3008b7a
Update packages/@n8n/nodes-langchain/nodes/llms/LmChatStraico/LmChatS…
nlp-deutschland-de 81ef02d
Update packages/@n8n/nodes-langchain/nodes/llms/LmChatStraico/LmChatS…
nlp-deutschland-de File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
packages/@n8n/nodes-langchain/credentials/StraicoApi.credentials.ts
This file contains hidden or 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,47 @@ | ||
import type { | ||
IAuthenticateGeneric, | ||
ICredentialTestRequest, | ||
ICredentialType, | ||
INodeProperties, | ||
} from 'n8n-workflow'; | ||
|
||
export class StraicoApi implements ICredentialType { | ||
name = 'straicoApi'; | ||
|
||
displayName = 'Straico API'; | ||
|
||
documentationUrl = 'https://documenter.getpostman.com/view/5900072/2s9YyzddrR'; | ||
|
||
properties: INodeProperties[] = [ | ||
{ | ||
displayName: 'API Key', | ||
name: 'apiKey', | ||
type: 'string', | ||
typeOptions: { password: true }, | ||
required: true, | ||
default: '', | ||
}, | ||
{ | ||
displayName: 'Base URL', | ||
name: 'url', | ||
type: 'hidden', | ||
default: 'https://api.straico.com/v0', | ||
}, | ||
]; | ||
|
||
authenticate: IAuthenticateGeneric = { | ||
type: 'generic', | ||
properties: { | ||
headers: { | ||
Authorization: '={{ "Bearer " + $credentials.apiKey }}', | ||
}, | ||
}, | ||
}; | ||
|
||
test: ICredentialTestRequest = { | ||
request: { | ||
baseURL: '={{ $credentials.url }}', | ||
url: '/models', | ||
}, | ||
}; | ||
} |
This file contains hidden or 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 hidden or 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
199 changes: 199 additions & 0 deletions
199
packages/@n8n/nodes-langchain/nodes/llms/LmChatStraico/LmChatStraico.node.ts
This file contains hidden or 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,199 @@ | ||
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */ | ||
import { | ||
NodeConnectionTypes, | ||
type INodeType, | ||
type INodeTypeDescription, | ||
type ISupplyDataFunctions, | ||
type SupplyData, | ||
} from 'n8n-workflow'; | ||
import { getHttpProxyAgent } from '@utils/httpProxyAgent'; | ||
import { getConnectionHintNoticeField } from '@utils/sharedFields'; | ||
import { openAiFailedAttemptHandler } from '../../vendors/OpenAi/helpers/error-handling'; | ||
import { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler'; | ||
import { N8nLlmTracing } from '../N8nLlmTracing'; | ||
import { StraicoChatModel } from './StraicoChatModel'; | ||
|
||
interface OpenAICompatibleCredential { | ||
apiKey: string; | ||
url: string; | ||
} | ||
|
||
export class LmChatStraico implements INodeType { | ||
description: INodeTypeDescription = { | ||
displayName: 'Straico Chat Model', | ||
name: 'lmChatStraico', | ||
icon: { light: 'file:straico.svg', dark: 'file:straico.svg' }, | ||
group: ['transform'], | ||
version: [1], | ||
description: 'Expose Straico chat-completion models for AI chains and the AI-Agent', | ||
defaults: { name: 'Straico Chat Model' }, | ||
codex: { | ||
categories: ['AI'], | ||
subcategories: { | ||
AI: ['Language Models', 'Root Nodes'], | ||
'Language Models': ['Chat Models (Recommended)'], | ||
}, | ||
resources: { | ||
primaryDocumentation: [ | ||
{ | ||
url: 'https://github.com/nlp-deutschland-de/n8n-docs/blob/main/docs/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmChatStraico.md', | ||
}, | ||
], | ||
}, | ||
}, | ||
inputs: [], | ||
outputs: [NodeConnectionTypes.AiLanguageModel], | ||
outputNames: ['Model'], | ||
credentials: [ | ||
{ | ||
name: 'straicoApi', | ||
required: true, | ||
}, | ||
], | ||
requestDefaults: { | ||
ignoreHttpStatusErrors: true, | ||
baseURL: '={{ $credentials?.url }}', | ||
}, | ||
properties: [ | ||
getConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiAgent]), | ||
{ | ||
displayName: 'Model', | ||
name: 'model', | ||
type: 'options', | ||
required: true, | ||
default: 'anthropic/claude-3.5-sonnet', | ||
description: 'Choose the Straico model to generate the completion. <a href="https://documenter.getpostman.com/view/5900072/2s9YyzddrR">Learn more</a>.', | ||
typeOptions: { | ||
loadOptions: { | ||
routing: { | ||
request: { | ||
method: 'GET', | ||
url: '/models', | ||
}, | ||
output: { | ||
postReceive: [ | ||
{ | ||
type: 'rootProperty', | ||
properties: { | ||
property: 'data', | ||
}, | ||
}, | ||
{ | ||
type: 'setKeyValue', | ||
properties: { | ||
name: '={{$responseItem.model}}', | ||
value: '={{$responseItem.model}}', | ||
}, | ||
}, | ||
{ | ||
type: 'sort', | ||
properties: { | ||
key: 'name', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
routing: { | ||
send: { type: 'body', property: 'model' }, | ||
}, | ||
}, | ||
{ | ||
displayName: 'Options', | ||
name: 'options', | ||
placeholder: 'Add Option', | ||
type: 'collection', | ||
default: {}, | ||
options: [ | ||
{ | ||
displayName: 'Temperature', | ||
name: 'temperature', | ||
type: 'number', | ||
default: 1, | ||
typeOptions: { minValue: 0, maxValue: 2 }, | ||
description: 'Controls randomness of the model output.', | ||
}, | ||
{ | ||
displayName: 'Top P', | ||
name: 'top_p', | ||
type: 'number', | ||
default: 1, | ||
typeOptions: { minValue: 0, maxValue: 1 }, | ||
description: 'Controls diversity via nucleus sampling.', | ||
}, | ||
{ | ||
displayName: 'Max Tokens', | ||
name: 'max_tokens', | ||
type: 'number', | ||
default: 1024, | ||
description: 'Maximum number of tokens to generate.', | ||
}, | ||
{ | ||
displayName: 'Presence Penalty', | ||
name: 'presence_penalty', | ||
type: 'number', | ||
default: 0, | ||
typeOptions: { minValue: -2, maxValue: 2 }, | ||
description: 'Penalizes tokens based on their presence in the text.', | ||
}, | ||
{ | ||
displayName: 'Frequency Penalty', | ||
name: 'frequency_penalty', | ||
type: 'number', | ||
default: 0, | ||
typeOptions: { minValue: -2, maxValue: 2 }, | ||
description: 'Penalizes tokens based on their frequency in the text.', | ||
}, | ||
{ | ||
displayName: 'Timeout (ms)', | ||
name: 'timeout', | ||
type: 'number', | ||
default: 60000, | ||
description: 'Maximum amount of time a request is allowed to take in milliseconds.', | ||
}, | ||
{ | ||
displayName: 'Max Retries', | ||
name: 'maxRetries', | ||
type: 'number', | ||
default: 2, | ||
description: 'Maximum number of retries to attempt.', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
async supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> { | ||
const credentials = await this.getCredentials<OpenAICompatibleCredential>('straicoApi'); | ||
console.log('Credentials:', { apiKey: '***', url: credentials.url }); | ||
|
||
const modelName = this.getNodeParameter('model', itemIndex) as string; | ||
console.log('Selected Model Name:', modelName); // Log the selected model | ||
|
||
const rawOptions = this.getNodeParameter('options', itemIndex, {}) as Record<string, any>; | ||
|
||
const options = { | ||
temperature: rawOptions.temperature, | ||
topP: rawOptions.top_p, | ||
maxTokens: rawOptions.max_tokens, | ||
nlp-deutschland-de marked this conversation as resolved.
Show resolved
Hide resolved
|
||
presencePenalty: rawOptions.presence_penalty, | ||
frequencyPenalty: rawOptions.frequency_penalty, | ||
timeout: rawOptions.timeout ?? 60000, | ||
maxRetries: rawOptions.maxRetries ?? 2, | ||
}; | ||
console.log('Options:', options); | ||
|
||
const model = new StraicoChatModel({ | ||
apiKey: credentials.apiKey, | ||
baseURL: credentials.url || 'https://api.straico.com/v0', | ||
modelName, // Use the selected model from the dropdown | ||
...options, | ||
callbacks: [new N8nLlmTracing(this)], | ||
onFailedAttempt: makeN8nLlmFailedAttemptHandler(this, openAiFailedAttemptHandler), | ||
}); | ||
|
||
return { response: model }; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.