mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 01:01:11 +03:00
Feature/seq agents (#2798)
* update build functions * sequential agents * update langchain to 0.2, added sequential agent nodes * add marketplace templates * update howto wordings * Merge branch 'main' into feature/Seq-Agents # Conflicts: # pnpm-lock.yaml * update deprecated functions and add new sequential nodes * add marketplace templates * update marketplace templates, add structured output to llm node * add multi agents template * update llm node with bindmodels * update cypress version * update templates sticky note wordings * update tool node to include human in loop action * update structured outputs error from models * update cohere package to resolve google genai pipeThrough bug * update mistral package version, added message reconstruction before invoke seq agent * add HITL to agent * update state messages restructuring * update load and split methods for s3 directory
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { BaseCache } from '@langchain/core/caches'
|
||||
import { Cohere, CohereInput } from '@langchain/cohere'
|
||||
import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface'
|
||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||
import { Cohere, CohereInput } from './core'
|
||||
import { getModels, MODEL_TYPE } from '../../../src/modelLoader'
|
||||
|
||||
class Cohere_LLMs implements INode {
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
import { LLM, BaseLLMParams } from '@langchain/core/language_models/llms'
|
||||
|
||||
export interface CohereInput extends BaseLLMParams {
|
||||
/** Sampling temperature to use */
|
||||
temperature?: number
|
||||
|
||||
/**
|
||||
* Maximum number of tokens to generate in the completion.
|
||||
*/
|
||||
maxTokens?: number
|
||||
|
||||
/** Model to use */
|
||||
model?: string
|
||||
|
||||
apiKey?: string
|
||||
}
|
||||
|
||||
export class Cohere extends LLM implements CohereInput {
|
||||
temperature = 0
|
||||
|
||||
maxTokens = 250
|
||||
|
||||
model: string
|
||||
|
||||
apiKey: string
|
||||
|
||||
constructor(fields?: CohereInput) {
|
||||
super(fields ?? {})
|
||||
|
||||
const apiKey = fields?.apiKey ?? undefined
|
||||
|
||||
if (!apiKey) {
|
||||
throw new Error('Please set the COHERE_API_KEY environment variable or pass it to the constructor as the apiKey field.')
|
||||
}
|
||||
|
||||
this.apiKey = apiKey
|
||||
this.maxTokens = fields?.maxTokens ?? this.maxTokens
|
||||
this.temperature = fields?.temperature ?? this.temperature
|
||||
this.model = fields?.model ?? this.model
|
||||
}
|
||||
|
||||
_llmType() {
|
||||
return 'cohere'
|
||||
}
|
||||
|
||||
/** @ignore */
|
||||
async _call(prompt: string, options: this['ParsedCallOptions']): Promise<string> {
|
||||
const { cohere } = await Cohere.imports()
|
||||
|
||||
cohere.init(this.apiKey)
|
||||
|
||||
// Hit the `generate` endpoint on the `large` model
|
||||
const generateResponse = await this.caller.callWithOptions({ signal: options.signal }, cohere.generate.bind(cohere), {
|
||||
prompt,
|
||||
model: this.model,
|
||||
max_tokens: this.maxTokens,
|
||||
temperature: this.temperature,
|
||||
end_sequences: options.stop
|
||||
})
|
||||
try {
|
||||
return generateResponse.body.generations[0].text
|
||||
} catch {
|
||||
throw new Error('Could not parse response.')
|
||||
}
|
||||
}
|
||||
|
||||
/** @ignore */
|
||||
static async imports(): Promise<{
|
||||
cohere: typeof import('cohere-ai')
|
||||
}> {
|
||||
try {
|
||||
const { default: cohere } = await import('cohere-ai')
|
||||
return { cohere }
|
||||
} catch (e) {
|
||||
throw new Error('Please install cohere-ai as a dependency with, e.g. `pnpm install cohere-ai`')
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user