Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 26 additions & 0 deletions packages/components/credentials/GigaChat.credential.ts
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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a typo in the description. "GigaChatApi" should be "GigaChat API" for better readability and consistency.

Suggested change
this.description = 'You can get the Credentials token from GigaChatApi in Developer Console'
this.description = 'You can get the Credentials token from GigaChat API 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 packages/components/nodes/chatmodels/ChatGigaChat/ChatGigaChat.ts
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”**'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There appears to be a formatting error in the description string, which ends with basis”**. This should be corrected.

Suggested change
description: 'access for sole proprietors and legal entities on a pay-as-you-go basis”**'
description: 'access for sole proprietors and legal entities on a pay-as-you-go basis'
}
],
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 || '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The baseUrl is retrieved using String(nodeData.inputs?.baseUrl || ''). If a user clears this field in the UI, it could become an empty string, leading to runtime errors as an empty URL is invalid. Since this field is not optional, it would be more robust to ensure a valid URL is always used, for instance by falling back to the default value if the input is falsy.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The baseUrl field is not optional. It is required. And it has an initial value.


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 }
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 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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading