-
-
Notifications
You must be signed in to change notification settings - Fork 24.5k
feat: add ChatInception chat model node #6506
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
Open
yanismiraoui
wants to merge
2
commits into
FlowiseAI:main
Choose a base branch
from
yanismiraoui:feat/inception-chat-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+220
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
26 changes: 26 additions & 0 deletions
26
packages/components/credentials/InceptionApi.credential.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,26 @@ | ||
| import { INodeParams, INodeCredential } from '../src/Interface' | ||
|
|
||
| class InceptionApi implements INodeCredential { | ||
| label: string | ||
| name: string | ||
| version: number | ||
| description: string | ||
| inputs: INodeParams[] | ||
|
|
||
| constructor() { | ||
| this.label = 'Inception API' | ||
| this.name = 'inceptionApi' | ||
| this.version = 1.0 | ||
| this.description = 'Get your API key from the Inception Platform dashboard' | ||
| this.inputs = [ | ||
| { | ||
| label: 'Inception API Key', | ||
| name: 'inceptionApiKey', | ||
| type: 'password', | ||
| description: 'Get your API key from https://platform.inceptionlabs.ai/' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| module.exports = { credClass: InceptionApi } |
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
173 changes: 173 additions & 0 deletions
173
packages/components/nodes/chatmodels/ChatInception/ChatInception.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,173 @@ | ||
| import { ChatOpenAI, ChatOpenAIFields } from '@langchain/openai' | ||
| import { BaseCache } from '@langchain/core/caches' | ||
| import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface' | ||
| import { getBaseClasses, getCredentialData, getCredentialParam, parseJsonBody } from '../../../src/utils' | ||
| import { getModels, MODEL_TYPE } from '../../../src/modelLoader' | ||
|
|
||
| const DEFAULT_BASE_URL = 'https://api.inceptionlabs.ai/v1' | ||
|
|
||
| class ChatInception_ChatModels implements INode { | ||
| label: string | ||
| name: string | ||
| version: number | ||
| type: string | ||
| icon: string | ||
| category: string | ||
| description: string | ||
| baseClasses: string[] | ||
| credential: INodeParams | ||
| inputs: INodeParams[] | ||
|
|
||
| constructor() { | ||
| this.label = 'ChatInception' | ||
| this.name = 'chatInception' | ||
| this.version = 1.0 | ||
| this.type = 'ChatInception' | ||
| this.icon = 'inception.svg' | ||
| this.category = 'Chat Models' | ||
| this.description = 'Wrapper around Inception Mercury diffusion LLMs (OpenAI-compatible API)' | ||
| this.baseClasses = [this.type, ...getBaseClasses(ChatOpenAI)] | ||
| this.credential = { | ||
| label: 'Connect Credential', | ||
| name: 'credential', | ||
| type: 'credential', | ||
| credentialNames: ['inceptionApi'] | ||
| } | ||
| this.inputs = [ | ||
| { | ||
| label: 'Cache', | ||
| name: 'cache', | ||
| type: 'BaseCache', | ||
| optional: true | ||
| }, | ||
| { | ||
| label: 'Model Name', | ||
| name: 'modelName', | ||
| type: 'asyncOptions', | ||
| loadMethod: 'listModels', | ||
| default: 'mercury-2' | ||
| }, | ||
| { | ||
| label: 'Temperature', | ||
| name: 'temperature', | ||
| type: 'number', | ||
| step: 0.1, | ||
| default: 0.75, | ||
| optional: true | ||
| }, | ||
| { | ||
| label: 'Reasoning Effort', | ||
| name: 'reasoningEffort', | ||
| type: 'options', | ||
| description: 'Controls how much the model thinks before answering. Only applicable to reasoning models such as mercury-2.', | ||
| options: [ | ||
| { label: 'Instant', name: 'instant' }, | ||
| { label: 'Low', name: 'low' }, | ||
| { label: 'Medium', name: 'medium' }, | ||
| { label: 'High', name: 'high' } | ||
| ], | ||
| optional: true, | ||
| additionalParams: true | ||
| }, | ||
| { | ||
| label: 'Streaming', | ||
| name: 'streaming', | ||
| type: 'boolean', | ||
| default: true, | ||
| optional: true, | ||
| additionalParams: true | ||
| }, | ||
| { | ||
| label: 'Max Tokens', | ||
| name: 'maxTokens', | ||
| type: 'number', | ||
| step: 1, | ||
| optional: true, | ||
| additionalParams: true | ||
| }, | ||
| { | ||
| label: 'Timeout', | ||
| name: 'timeout', | ||
| type: 'number', | ||
| step: 1, | ||
| optional: true, | ||
| additionalParams: true | ||
| }, | ||
| { | ||
| label: 'Base Path', | ||
| name: 'basepath', | ||
| type: 'string', | ||
| optional: true, | ||
| default: DEFAULT_BASE_URL, | ||
| description: 'Override the default base URL for the API, e.g., "https://api.inceptionlabs.ai/v1"', | ||
| additionalParams: true | ||
| }, | ||
| { | ||
| label: 'Base Options', | ||
| name: 'baseOptions', | ||
| type: 'json', | ||
| optional: true, | ||
| description: 'Default headers to include with every request to the API.', | ||
| additionalParams: true | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| loadMethods = { | ||
| async listModels(_: INodeData, __?: ICommonObject): Promise<INodeOptionsValue[]> { | ||
| return await getModels(MODEL_TYPE.CHAT, 'chatInception') | ||
| } | ||
| } | ||
|
|
||
| async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> { | ||
| const temperature = nodeData.inputs?.temperature as string | ||
| const modelName = nodeData.inputs?.modelName as string | ||
| const maxTokens = nodeData.inputs?.maxTokens as string | ||
| const timeout = nodeData.inputs?.timeout as string | ||
| const streaming = nodeData.inputs?.streaming as boolean | ||
| const reasoningEffort = nodeData.inputs?.reasoningEffort as string | ||
| const basePath = nodeData.inputs?.basepath as string | ||
| const baseOptions = nodeData.inputs?.baseOptions | ||
| const cache = nodeData.inputs?.cache as BaseCache | ||
|
|
||
| const credentialData = await getCredentialData(nodeData.credential ?? '', options) | ||
| const inceptionApiKey = getCredentialParam('inceptionApiKey', credentialData, nodeData) | ||
|
|
||
| const obj: ChatOpenAIFields = { | ||
| model: modelName, | ||
| apiKey: inceptionApiKey, | ||
| openAIApiKey: inceptionApiKey, | ||
| streaming: streaming ?? true | ||
| } | ||
|
|
||
| if (temperature != null && temperature !== '') obj.temperature = parseFloat(temperature) | ||
| if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10) | ||
| if (timeout) obj.timeout = parseInt(timeout, 10) | ||
| if (cache) obj.cache = cache | ||
| // Inception accepts "instant" in addition to the standard OpenAI reasoning efforts, | ||
| // so pass it through modelKwargs to bypass the stricter ChatOpenAI typing. | ||
| if (reasoningEffort) obj.modelKwargs = { reasoning_effort: reasoningEffort } | ||
|
|
||
| let parsedBaseOptions: any | undefined = undefined | ||
|
|
||
| if (baseOptions) { | ||
| try { | ||
| parsedBaseOptions = typeof baseOptions === 'object' ? baseOptions : parseJsonBody(baseOptions) | ||
| } catch (exception) { | ||
| throw new Error("Invalid JSON in the ChatInception's BaseOptions: " + exception) | ||
| } | ||
| } | ||
|
yanismiraoui marked this conversation as resolved.
|
||
|
|
||
| obj.configuration = { | ||
| baseURL: basePath || DEFAULT_BASE_URL, | ||
| defaultHeaders: { | ||
| ...(parsedBaseOptions || {}) | ||
| } | ||
| } | ||
|
|
||
| const model = new ChatOpenAI(obj) | ||
| return model | ||
| } | ||
| } | ||
|
|
||
| module.exports = { nodeClass: ChatInception_ChatModels } | ||
9 changes: 9 additions & 0 deletions
9
packages/components/nodes/chatmodels/ChatInception/inception.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.