Skip to content

Commit 2cb2a6e

Browse files
authored
Merge branch 'FlowiseAI:main' into main
2 parents decc3ce + 9b3971d commit 2cb2a6e

File tree

22 files changed

+1710
-420
lines changed

22 files changed

+1710
-420
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { INodeParams, INodeCredential } from '../src/Interface'
2+
3+
class SambanovaApi implements INodeCredential {
4+
label: string
5+
name: string
6+
version: number
7+
inputs: INodeParams[]
8+
9+
constructor() {
10+
this.label = 'Sambanova API'
11+
this.name = 'sambanovaApi'
12+
this.version = 1.0
13+
this.inputs = [
14+
{
15+
label: 'Sambanova Api Key',
16+
name: 'sambanovaApiKey',
17+
type: 'password'
18+
}
19+
]
20+
}
21+
}
22+
23+
module.exports = { credClass: SambanovaApi }

packages/components/jest.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
roots: ['<rootDir>/nodes'],
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest'
7+
},
8+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
9+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
10+
verbose: true,
11+
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
12+
moduleNameMapper: {
13+
'^../../../src/(.*)$': '<rootDir>/src/$1'
14+
}
15+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { BaseCache } from '@langchain/core/caches'
2+
import { ChatOpenAI, ChatOpenAIFields } from '@langchain/openai'
3+
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
4+
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
5+
6+
class ChatSambanova_ChatModels implements INode {
7+
label: string
8+
name: string
9+
version: number
10+
type: string
11+
icon: string
12+
category: string
13+
description: string
14+
baseClasses: string[]
15+
credential: INodeParams
16+
inputs: INodeParams[]
17+
18+
constructor() {
19+
this.label = 'ChatSambanova'
20+
this.name = 'chatSambanova'
21+
this.version = 1.0
22+
this.type = 'ChatSambanova'
23+
this.icon = 'sambanova.png'
24+
this.category = 'Chat Models'
25+
this.description = 'Wrapper around Sambanova Chat Endpoints'
26+
this.baseClasses = [this.type, ...getBaseClasses(ChatOpenAI)]
27+
this.credential = {
28+
label: 'Connect Credential',
29+
name: 'credential',
30+
type: 'credential',
31+
credentialNames: ['sambanovaApi']
32+
}
33+
this.inputs = [
34+
{
35+
label: 'Cache',
36+
name: 'cache',
37+
type: 'BaseCache',
38+
optional: true
39+
},
40+
{
41+
label: 'Model',
42+
name: 'modelName',
43+
type: 'string',
44+
default: 'Meta-Llama-3.3-70B-Instruct',
45+
placeholder: 'Meta-Llama-3.3-70B-Instruct'
46+
},
47+
{
48+
label: 'Temperature',
49+
name: 'temperature',
50+
type: 'number',
51+
step: 0.1,
52+
default: 0.9,
53+
optional: true
54+
},
55+
{
56+
label: 'Streaming',
57+
name: 'streaming',
58+
type: 'boolean',
59+
default: true,
60+
optional: true
61+
},
62+
{
63+
label: 'BasePath',
64+
name: 'basepath',
65+
type: 'string',
66+
optional: true,
67+
default: 'htps://api.sambanova.ai/v1',
68+
additionalParams: true
69+
},
70+
{
71+
label: 'BaseOptions',
72+
name: 'baseOptions',
73+
type: 'json',
74+
optional: true,
75+
additionalParams: true
76+
}
77+
]
78+
}
79+
80+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
81+
const cache = nodeData.inputs?.cache as BaseCache
82+
const temperature = nodeData.inputs?.temperature as string
83+
const modelName = nodeData.inputs?.modelName as string
84+
const streaming = nodeData.inputs?.streaming as boolean
85+
const basePath = nodeData.inputs?.basepath as string
86+
const baseOptions = nodeData.inputs?.baseOptions
87+
88+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
89+
const sambanovaApiKey = getCredentialParam('sambanovaApiKey', credentialData, nodeData)
90+
91+
const obj: ChatOpenAIFields = {
92+
temperature: temperature ? parseFloat(temperature) : undefined,
93+
model: modelName,
94+
apiKey: sambanovaApiKey,
95+
openAIApiKey: sambanovaApiKey,
96+
streaming: streaming ?? true
97+
}
98+
99+
if (cache) obj.cache = cache
100+
101+
let parsedBaseOptions: any | undefined = undefined
102+
103+
if (baseOptions) {
104+
try {
105+
parsedBaseOptions = typeof baseOptions === 'object' ? baseOptions : JSON.parse(baseOptions)
106+
} catch (exception) {
107+
throw new Error("Invalid JSON in the ChatSambanova's BaseOptions: " + exception)
108+
}
109+
}
110+
111+
if (basePath || parsedBaseOptions) {
112+
obj.configuration = {
113+
baseURL: basePath,
114+
defaultHeaders: parsedBaseOptions
115+
}
116+
}
117+
118+
const model = new ChatOpenAI(obj)
119+
return model
120+
}
121+
}
122+
123+
module.exports = { nodeClass: ChatSambanova_ChatModels }
12.3 KB
Loading

packages/components/nodes/documentloaders/File/File.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ class File_DocumentLoaders implements INode {
136136

137137
let files: string[] = []
138138
const fileBlobs: { blob: Blob; ext: string }[] = []
139+
const processRaw = options.processRaw
139140

140141
//FILE-STORAGE::["CONTRIBUTING.md","LICENSE.md","README.md"]
141-
const totalFiles = getOverrideFileInputs(nodeData) || fileBase64
142+
const totalFiles = getOverrideFileInputs(nodeData, processRaw) || fileBase64
142143
if (totalFiles.startsWith('FILE-STORAGE::')) {
143144
const fileName = totalFiles.replace('FILE-STORAGE::', '')
144145
if (fileName.startsWith('[') && fileName.endsWith(']')) {
@@ -298,7 +299,7 @@ class File_DocumentLoaders implements INode {
298299
}
299300
}
300301

301-
const getOverrideFileInputs = (nodeData: INodeData) => {
302+
const getOverrideFileInputs = (nodeData: INodeData, processRaw: boolean) => {
302303
const txtFileBase64 = nodeData.inputs?.txtFile as string
303304
const pdfFileBase64 = nodeData.inputs?.pdfFile as string
304305
const jsonFileBase64 = nodeData.inputs?.jsonFile as string
@@ -347,6 +348,10 @@ const getOverrideFileInputs = (nodeData: INodeData) => {
347348
files.push(...removePrefix(powerpointFileBase64))
348349
}
349350

351+
if (processRaw) {
352+
return files.length ? JSON.stringify(files) : ''
353+
}
354+
350355
return files.length ? `FILE-STORAGE::${JSON.stringify(files)}` : ''
351356
}
352357

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { getBaseClasses, getCredentialData, getCredentialParam, ICommonObject, INode, INodeData, INodeParams } from '../../../src'
2+
import { OpenAI } from '@langchain/openai'
3+
import { BaseCache } from '@langchain/core/caches'
4+
5+
class Sambanova_LLMs implements INode {
6+
label: string
7+
name: string
8+
version: number
9+
type: string
10+
icon: string
11+
category: string
12+
description: string
13+
baseClasses: string[]
14+
credential: INodeParams
15+
inputs: INodeParams[]
16+
17+
constructor() {
18+
this.label = 'Sambanova'
19+
this.name = 'sambanova'
20+
this.version = 1.0
21+
this.type = 'Sambanova'
22+
this.icon = 'sambanova.png'
23+
this.category = 'LLMs'
24+
this.description = 'Wrapper around Sambanova API for large language models'
25+
this.baseClasses = [this.type, ...getBaseClasses(OpenAI)]
26+
this.credential = {
27+
label: 'Connect Credential',
28+
name: 'credential',
29+
type: 'credential',
30+
credentialNames: ['sambanovaApi']
31+
}
32+
this.inputs = [
33+
{
34+
label: 'Cache',
35+
name: 'cache',
36+
type: 'BaseCache',
37+
optional: true
38+
},
39+
{
40+
label: 'Model Name',
41+
name: 'modelName',
42+
type: 'string',
43+
default: 'Meta-Llama-3.3-70B-Instruct',
44+
description: 'For more details see https://docs.sambanova.ai/cloud/docs/get-started/supported-models',
45+
optional: true
46+
}
47+
]
48+
}
49+
50+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
51+
const cache = nodeData.inputs?.cache as BaseCache
52+
const modelName = nodeData.inputs?.modelName as string
53+
54+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
55+
const sambanovaKey = getCredentialParam('sambanovaApiKey', credentialData, nodeData)
56+
57+
const obj: any = {
58+
model: modelName,
59+
configuration: {
60+
baseURL: 'https://api.sambanova.ai/v1',
61+
apiKey: sambanovaKey
62+
}
63+
}
64+
if (cache) obj.cache = cache
65+
66+
const sambanova = new OpenAI(obj)
67+
return sambanova
68+
}
69+
}
70+
71+
module.exports = { nodeClass: Sambanova_LLMs }
12.3 KB
Loading

0 commit comments

Comments
 (0)