-
-
Notifications
You must be signed in to change notification settings - Fork 23.1k
feat: Add GigaChat #5484
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
NarekChang
wants to merge
3
commits into
FlowiseAI:main
Choose a base branch
from
NarekChang:feature/implementation-gigachat
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.
Open
feat: Add GigaChat #5484
Changes from 2 commits
Commits
Show all changes
3 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
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 { INodeCredential, INodeParams } from "../src/Interface" | ||
|
|
||
| class GigaChatApi implements INodeCredential { | ||
| label: string | ||
| name: string | ||
| version: number | ||
| description: string | ||
| inputs: INodeParams[] | ||
|
|
||
| constructor() { | ||
| this.label = 'GigaChat API' | ||
| this.name = 'gigaChatApi' | ||
| this.version = 1.0 | ||
| this.description = 'You can get the Credentials token from GigaChatApi in Developer Console' | ||
| this.inputs = [ | ||
| { | ||
| label: 'Access Token', | ||
| name: 'accessToken', | ||
| type: 'password', | ||
| placeholder: '<GIGACHAT_CREDENTIALS>' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| module.exports = { credClass: GigaChatApi } | ||
162 changes: 162 additions & 0 deletions
162
packages/components/nodes/chatmodels/ChatGigaChat/ChatGigaChat.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,162 @@ | ||
| import { GigaChat as GigaChatLangchain } from 'langchain-gigachat' | ||
| import { FlowiseGigaChat } from './FlowiseChatGigaChat' | ||
|
|
||
| import { httpsAgent } from '../../../utilities/https-agent.util' | ||
| import { getBaseClasses, getCredentialData } from '../../../src/utils' | ||
| import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' | ||
|
|
||
| class ChatGigaChat 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 = 'ChatGigaChat' | ||
| this.name = 'chatgigachat' | ||
| this.version = 2.0 | ||
| this.type = 'ChatGigaChat' | ||
| this.icon = 'GigaChat.svg' | ||
| this.category = 'Chat Models' | ||
| this.description = 'Wrapper around GigaChat large language models that use the Chat endpoint' | ||
| this.baseClasses = [this.type, ...getBaseClasses(GigaChatLangchain)] | ||
| this.credential = { | ||
| label: 'Credential', | ||
| name: 'credential', | ||
| type: 'credential', | ||
| credentialNames: ['gigaChatApi'] | ||
| } | ||
| this.inputs = [ | ||
| { | ||
| label: 'Model Name', | ||
| name: 'modelName', | ||
| type: 'options', | ||
| options: [ | ||
| { | ||
| label: 'GigaChat v2', | ||
| name: 'GigaChat-2', | ||
| description: 'The most advanced model' | ||
| }, | ||
| { | ||
| label: 'GigaChat Pro v2', | ||
| name: 'GigaChat-2-Pro', | ||
| description: 'The most advanced model Pro' | ||
| }, | ||
| { | ||
| label: 'GigaChat Max v2', | ||
| name: 'GigaChat-2-Max', | ||
| description: 'The most advanced model Max' | ||
| }, | ||
| { | ||
| label: 'GigaChat Max', | ||
| name: 'GigaChat-Max', | ||
| description: 'An advanced model for complex tasks that require a high level of creativity and quality of work' | ||
| }, | ||
| { | ||
| label: 'GigaChat Pro', | ||
| name: 'GigaChat-Pro', | ||
| description: | ||
| 'the model follows complex instructions more effectively and can handle more sophisticated tasks: the quality of summarization, rewriting and editing texts, and answering various questions has improved significantly' | ||
| }, | ||
| { | ||
| label: 'GigaChat Plus', | ||
| name: 'GigaChat-Plus', | ||
| description: | ||
| 'Ideally suited for tasks that require sending a large amount of information in a single request.' | ||
| }, | ||
| { | ||
| label: 'GigaChat', | ||
| name: 'GigaChat', | ||
| description: | ||
| 'Suitable for solving simpler tasks that require maximum processing speed. At the same time, the cost of using the model is lower because it requires fewer computational resources.' | ||
| } | ||
| ], | ||
| default: 'GigaChat-2-Pro' | ||
| }, | ||
| { | ||
| label: 'Scope', | ||
| name: 'scope', | ||
| type: 'options', | ||
| description: 'a required field in the request body that specifies which API version the request is being made to', | ||
| options: [ | ||
| { | ||
| label: 'GIGACHAT_API_PERS', | ||
| name: 'GIGACHAT_API_PERS', | ||
| description: 'access for individuals' | ||
| }, | ||
| { | ||
| label: 'GIGACHAT_API_B2B', | ||
| name: 'GIGACHAT_API_B2B', | ||
| description: 'access for sole proprietors and legal entities through paid packages' | ||
| }, | ||
| { | ||
| label: 'GIGACHAT_API_CORP', | ||
| name: 'GIGACHAT_API_CORP', | ||
| description: 'access for sole proprietors and legal entities on a pay-as-you-go basis”**' | ||
NarekChang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| ], | ||
| default: 'GIGACHAT_API_PERS' | ||
| }, | ||
| { | ||
| label: 'Base URL', | ||
| name: 'baseUrl', | ||
| type: 'string', | ||
| default: 'https://gigachat.devices.sberbank.ru/api/v1/', | ||
| description: 'API URL', | ||
| optional: false | ||
| }, | ||
| { | ||
| label: 'Temperature', | ||
| name: 'temperature', | ||
| type: 'number', | ||
| step: 0.1, | ||
| default: 1, | ||
| optional: true | ||
| }, | ||
| { | ||
| label: 'Timeout', | ||
| name: 'timeout', | ||
| type: 'number', | ||
| step: 1, | ||
| default: 60000, | ||
| optional: true | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> { | ||
| const temperature = Number(nodeData.inputs?.temperature || 1) | ||
| const scope = String(nodeData.inputs?.scope || 'GIGACHAT_API_PERS') | ||
| const modelName = nodeData.inputs?.modelName as string | ||
| const timeout = Number(nodeData.inputs?.timeout || 60000) | ||
| const baseUrl = String(nodeData.inputs?.baseUrl || '') | ||
NarekChang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const credentialData = await getCredentialData(nodeData.credential ?? '', options) | ||
| const credentials = credentialData?.accessToken | ||
|
|
||
| const params: any = { | ||
| credentials, | ||
| model: modelName, | ||
| scope, | ||
| httpsAgent, | ||
| profanityCheck: false, | ||
| timeout, | ||
| verbose: false, | ||
| streaming: true, | ||
| temperature, | ||
| baseUrl | ||
| } | ||
|
|
||
| const model = new FlowiseGigaChat(params.model, params) | ||
|
|
||
| return model | ||
| } | ||
| } | ||
|
|
||
| module.exports = { nodeClass: ChatGigaChat } | ||
31 changes: 31 additions & 0 deletions
31
packages/components/nodes/chatmodels/ChatGigaChat/FlowiseChatGigaChat.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,31 @@ | ||
| import { ChatOpenAIFields } from '@langchain/openai' | ||
| import { GigaChat as LangchainGigaChat } from 'langchain-gigachat' | ||
|
|
||
| import { IMultiModalOption, IVisionChatModal } from '../../../src' | ||
|
|
||
| export class FlowiseGigaChat extends LangchainGigaChat implements IVisionChatModal { | ||
| configuredModel: string | ||
| configuredMaxToken?: number | ||
| multiModalOption: IMultiModalOption | ||
| id: string | ||
|
|
||
| constructor(id: string, fields?: ChatOpenAIFields) { | ||
| super(fields) | ||
| this.id = id | ||
| this.configuredModel = fields?.modelName ?? '' | ||
| this.configuredMaxToken = fields?.maxTokens | ||
| } | ||
|
|
||
| revertToOriginalModel(): void { | ||
| this.model = this.configuredModel | ||
| this.maxTokens = this.configuredMaxToken | ||
| } | ||
|
|
||
| setMultiModalOption(multiModalOption: IMultiModalOption): void { | ||
| this.multiModalOption = multiModalOption | ||
| } | ||
|
|
||
| setVisionModel(): void { | ||
| // pass | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
packages/components/nodes/chatmodels/ChatGigaChat/GigaChat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions
39
packages/components/nodes/embeddings/GigaChatEmbedding/GigaChat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.