feat: Add Alibaba API credential and ChatAlibabaTongyi node (#3360)
* feat: Add Alibaba API credential and ChatAlibabaTongyi node * lint fix * Add chatAlibabaTongyi model to models.json and chat models --------- Co-authored-by: Henry Heng <henryheng@flowiseai.com>
This commit is contained in:
parent
1d193b4dbc
commit
d1adc4fb1c
|
|
@ -0,0 +1,23 @@
|
|||
import { INodeParams, INodeCredential } from '../src/Interface'
|
||||
|
||||
class AlibabaApi implements INodeCredential {
|
||||
label: string
|
||||
name: string
|
||||
version: number
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Alibaba API'
|
||||
this.name = 'AlibabaApi'
|
||||
this.version = 1.0
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Alibaba Api Key',
|
||||
name: 'alibabaApiKey',
|
||||
type: 'password'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { credClass: AlibabaApi }
|
||||
|
|
@ -411,6 +411,15 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "chatAlibabaTongyi",
|
||||
"models": [
|
||||
{
|
||||
"label": "qwen-plus",
|
||||
"name": "qwen-plus"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "chatGoogleVertexAI",
|
||||
"models": [
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
import { BaseCache } from '@langchain/core/caches'
|
||||
import { ChatAlibabaTongyi } from '@langchain/community/chat_models/alibaba_tongyi'
|
||||
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||
import { BaseChatModelParams } from '@langchain/core/language_models/chat_models'
|
||||
|
||||
class ChatAlibabaTongyi_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 = 'ChatAlibabaTongyi'
|
||||
this.name = 'chatAlibabaTongyi'
|
||||
this.version = 1.0
|
||||
this.type = 'ChatAlibabaTongyi'
|
||||
this.icon = 'alibaba-svgrepo-com.svg'
|
||||
this.category = 'Chat Models'
|
||||
this.description = 'Wrapper around Alibaba Tongyi Chat Endpoints'
|
||||
this.baseClasses = [this.type, ...getBaseClasses(ChatAlibabaTongyi)]
|
||||
this.credential = {
|
||||
label: 'Connect Credential',
|
||||
name: 'credential',
|
||||
type: 'credential',
|
||||
credentialNames: ['AlibabaApi']
|
||||
}
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Cache',
|
||||
name: 'cache',
|
||||
type: 'BaseCache',
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Model',
|
||||
name: 'modelName',
|
||||
type: 'string',
|
||||
placeholder: 'qwen-plus'
|
||||
},
|
||||
{
|
||||
label: 'Temperature',
|
||||
name: 'temperature',
|
||||
type: 'number',
|
||||
step: 0.1,
|
||||
default: 0.9,
|
||||
optional: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const cache = nodeData.inputs?.cache as BaseCache
|
||||
const temperature = nodeData.inputs?.temperature as string
|
||||
const modelName = nodeData.inputs?.modelName as string
|
||||
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const alibabaApiKey = getCredentialParam('alibabaApiKey', credentialData, nodeData)
|
||||
|
||||
const obj: Partial<ChatAlibabaTongyi> & BaseChatModelParams = {
|
||||
streaming: true,
|
||||
alibabaApiKey,
|
||||
model: modelName,
|
||||
temperature: temperature ? parseFloat(temperature) : undefined
|
||||
}
|
||||
if (cache) obj.cache = cache
|
||||
|
||||
const model = new ChatAlibabaTongyi(obj)
|
||||
return model
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: ChatAlibabaTongyi_ChatModels }
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<svg width="800px" height="800px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="none">
|
||||
<g fill="#ED6B1E">
|
||||
<path d="M10.676 7.373H5.338v1.2h5.338v-1.2z"/>
|
||||
<path d="M13.338 3H9.81l.852 1.213L13.244 5c.48.147.786.6.773 1.067v3.866c0 .48-.307.92-.772 1.067l-2.57.787L9.81 13h3.528C14.815 13 16 11.8 16 10.333V5.667C16.013 4.2 14.815 3 13.338 3zM2.662 3H6.19l-.852 1.213L2.768 5c-.478.147-.785.6-.771 1.067v3.866c0 .48.306.92.772 1.067l2.569.787L6.19 13H2.662A2.672 2.672 0 010 10.333V5.667A2.672 2.672 0 012.662 3z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 666 B |
|
|
@ -1192,6 +1192,7 @@ export const isFlowValidForStream = (reactFlowNodes: IReactFlowNode[], endingNod
|
|||
'awsChatBedrock',
|
||||
'chatMistralAI',
|
||||
'chatMistral_LlamaIndex',
|
||||
'chatAlibabaTongyi',
|
||||
'groqChat',
|
||||
'chatGroq_LlamaIndex',
|
||||
'chatCohere',
|
||||
|
|
|
|||
Loading…
Reference in New Issue