Merge pull request #576 from FlowiseAI/feature/Replicate
Feature/Add ReplicateLLM
This commit is contained in:
commit
6e42e10be4
|
|
@ -0,0 +1,118 @@
|
|||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { getBaseClasses } from '../../../src/utils'
|
||||
import { Replicate, ReplicateInput } from 'langchain/llms/replicate'
|
||||
|
||||
class Replicate_LLMs implements INode {
|
||||
label: string
|
||||
name: string
|
||||
type: string
|
||||
icon: string
|
||||
category: string
|
||||
description: string
|
||||
baseClasses: string[]
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Replicate'
|
||||
this.name = 'replicate'
|
||||
this.type = 'Replicate'
|
||||
this.icon = 'replicate.svg'
|
||||
this.category = 'LLMs'
|
||||
this.description = 'Use Replicate to run open source models on cloud'
|
||||
this.baseClasses = [this.type, 'BaseChatModel', ...getBaseClasses(Replicate)]
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Replicate Api Key',
|
||||
name: 'replicateApiKey',
|
||||
type: 'password'
|
||||
},
|
||||
{
|
||||
label: 'Model',
|
||||
name: 'model',
|
||||
type: 'string',
|
||||
placeholder: 'a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5',
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Temperature',
|
||||
name: 'temperature',
|
||||
type: 'number',
|
||||
description:
|
||||
'Adjusts randomness of outputs, greater than 1 is random and 0 is deterministic, 0.75 is a good starting value.',
|
||||
default: 0.7,
|
||||
optional: true
|
||||
},
|
||||
{
|
||||
label: 'Max Tokens',
|
||||
name: 'maxTokens',
|
||||
type: 'number',
|
||||
description: 'Maximum number of tokens to generate. A word is generally 2-3 tokens',
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
},
|
||||
{
|
||||
label: 'Top Probability',
|
||||
name: 'topP',
|
||||
type: 'number',
|
||||
description:
|
||||
'When decoding text, samples from the top p percentage of most likely tokens; lower to ignore less likely tokens',
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
},
|
||||
{
|
||||
label: 'Repetition Penalty',
|
||||
name: 'repetitionPenalty',
|
||||
type: 'number',
|
||||
description:
|
||||
'Penalty for repeated words in generated text; 1 is no penalty, values greater than 1 discourage repetition, less than 1 encourage it. (minimum: 0.01; maximum: 5)',
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
},
|
||||
{
|
||||
label: 'Additional Inputs',
|
||||
name: 'additionalInputs',
|
||||
type: 'json',
|
||||
description:
|
||||
'Each model has different parameters, refer to the specific model accepted inputs. For example: <a target="_blank" href="https://replicate.com/a16z-infra/llama13b-v2-chat/api#inputs">llama13b-v2</a>',
|
||||
additionalParams: true,
|
||||
optional: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const modelName = nodeData.inputs?.model as string
|
||||
const apiKey = nodeData.inputs?.replicateApiKey as string
|
||||
const temperature = nodeData.inputs?.temperature as string
|
||||
const maxTokens = nodeData.inputs?.maxTokens as string
|
||||
const topP = nodeData.inputs?.topP as string
|
||||
const repetitionPenalty = nodeData.inputs?.repetitionPenalty as string
|
||||
const additionalInputs = nodeData.inputs?.additionalInputs as string
|
||||
|
||||
const version = modelName.split(':').pop()
|
||||
const name = modelName.split(':')[0].split('/').pop()
|
||||
const org = modelName.split(':')[0].split('/')[0]
|
||||
|
||||
const obj: ReplicateInput = {
|
||||
model: `${org}/${name}:${version}`,
|
||||
apiKey
|
||||
}
|
||||
|
||||
let inputs: any = {}
|
||||
if (maxTokens) inputs.max_length = parseInt(maxTokens, 10)
|
||||
if (temperature) inputs.temperature = parseFloat(temperature)
|
||||
if (topP) inputs.top_p = parseFloat(topP)
|
||||
if (repetitionPenalty) inputs.repetition_penalty = parseFloat(repetitionPenalty)
|
||||
if (additionalInputs) {
|
||||
const parsedInputs =
|
||||
typeof additionalInputs === 'object' ? additionalInputs : additionalInputs ? JSON.parse(additionalInputs) : {}
|
||||
inputs = { ...inputs, ...parsedInputs }
|
||||
}
|
||||
if (Object.keys(inputs).length) obj.input = inputs
|
||||
|
||||
const model = new Replicate(obj)
|
||||
return model
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: Replicate_LLMs }
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" class="logo" xml:space="preserve">
|
||||
<g>
|
||||
<polygon points="1000,427.6 1000,540.6 603.4,540.6 603.4,1000 477,1000 477,427.6 "></polygon>
|
||||
<polygon points="1000,213.8 1000,327 364.8,327 364.8,1000 238.4,1000 238.4,213.8 "></polygon>
|
||||
<polygon points="1000,0 1000,113.2 126.4,113.2 126.4,1000 0,1000 0,0 "></polygon>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 476 B |
|
|
@ -37,7 +37,7 @@
|
|||
"form-data": "^4.0.0",
|
||||
"graphql": "^16.6.0",
|
||||
"html-to-text": "^9.0.5",
|
||||
"langchain": "^0.0.104",
|
||||
"langchain": "^0.0.112",
|
||||
"linkifyjs": "^4.1.1",
|
||||
"mammoth": "^1.5.1",
|
||||
"moment": "^2.29.3",
|
||||
|
|
@ -48,6 +48,7 @@
|
|||
"playwright": "^1.35.0",
|
||||
"puppeteer": "^20.7.1",
|
||||
"redis": "^4.6.7",
|
||||
"replicate": "^0.12.3",
|
||||
"srt-parser-2": "^1.2.3",
|
||||
"vm2": "^3.9.19",
|
||||
"weaviate-ts-client": "^1.1.0",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,273 @@
|
|||
{
|
||||
"description": "Use Replicate API that runs Llama 13b v2 model with LLMChain",
|
||||
"nodes": [
|
||||
{
|
||||
"width": 300,
|
||||
"height": 405,
|
||||
"id": "llmChain_1",
|
||||
"position": {
|
||||
"x": 967.581544453458,
|
||||
"y": 320.56761595884564
|
||||
},
|
||||
"type": "customNode",
|
||||
"data": {
|
||||
"id": "llmChain_1",
|
||||
"label": "LLM Chain",
|
||||
"name": "llmChain",
|
||||
"type": "LLMChain",
|
||||
"baseClasses": ["LLMChain", "BaseChain", "BaseLangChain"],
|
||||
"category": "Chains",
|
||||
"description": "Chain to run queries against LLMs",
|
||||
"inputParams": [
|
||||
{
|
||||
"label": "Chain Name",
|
||||
"name": "chainName",
|
||||
"type": "string",
|
||||
"placeholder": "Name Your Chain",
|
||||
"optional": true,
|
||||
"id": "llmChain_1-input-chainName-string"
|
||||
}
|
||||
],
|
||||
"inputAnchors": [
|
||||
{
|
||||
"label": "Language Model",
|
||||
"name": "model",
|
||||
"type": "BaseLanguageModel",
|
||||
"id": "llmChain_1-input-model-BaseLanguageModel"
|
||||
},
|
||||
{
|
||||
"label": "Prompt",
|
||||
"name": "prompt",
|
||||
"type": "BasePromptTemplate",
|
||||
"id": "llmChain_1-input-prompt-BasePromptTemplate"
|
||||
}
|
||||
],
|
||||
"inputs": {
|
||||
"model": "{{replicate_0.data.instance}}",
|
||||
"prompt": "{{promptTemplate_0.data.instance}}",
|
||||
"chainName": ""
|
||||
},
|
||||
"outputAnchors": [
|
||||
{
|
||||
"name": "output",
|
||||
"label": "Output",
|
||||
"type": "options",
|
||||
"options": [
|
||||
{
|
||||
"id": "llmChain_1-output-llmChain-LLMChain|BaseChain|BaseLangChain",
|
||||
"name": "llmChain",
|
||||
"label": "LLM Chain",
|
||||
"type": "LLMChain | BaseChain | BaseLangChain"
|
||||
},
|
||||
{
|
||||
"id": "llmChain_1-output-outputPrediction-string|json",
|
||||
"name": "outputPrediction",
|
||||
"label": "Output Prediction",
|
||||
"type": "string | json"
|
||||
}
|
||||
],
|
||||
"default": "llmChain"
|
||||
}
|
||||
],
|
||||
"outputs": {
|
||||
"output": "llmChain"
|
||||
},
|
||||
"selected": false
|
||||
},
|
||||
"positionAbsolute": {
|
||||
"x": 967.581544453458,
|
||||
"y": 320.56761595884564
|
||||
},
|
||||
"selected": false,
|
||||
"dragging": false
|
||||
},
|
||||
{
|
||||
"width": 300,
|
||||
"height": 475,
|
||||
"id": "promptTemplate_0",
|
||||
"position": {
|
||||
"x": 269.2203229225663,
|
||||
"y": 129.02909641085535
|
||||
},
|
||||
"type": "customNode",
|
||||
"data": {
|
||||
"id": "promptTemplate_0",
|
||||
"label": "Prompt Template",
|
||||
"name": "promptTemplate",
|
||||
"type": "PromptTemplate",
|
||||
"baseClasses": ["PromptTemplate", "BaseStringPromptTemplate", "BasePromptTemplate"],
|
||||
"category": "Prompts",
|
||||
"description": "Schema to represent a basic prompt for an LLM",
|
||||
"inputParams": [
|
||||
{
|
||||
"label": "Template",
|
||||
"name": "template",
|
||||
"type": "string",
|
||||
"rows": 4,
|
||||
"placeholder": "What is a good name for a company that makes {product}?",
|
||||
"id": "promptTemplate_0-input-template-string"
|
||||
},
|
||||
{
|
||||
"label": "Format Prompt Values",
|
||||
"name": "promptValues",
|
||||
"type": "json",
|
||||
"optional": true,
|
||||
"acceptVariable": true,
|
||||
"list": true,
|
||||
"id": "promptTemplate_0-input-promptValues-json"
|
||||
}
|
||||
],
|
||||
"inputAnchors": [],
|
||||
"inputs": {
|
||||
"template": "Assistant: You are a helpful assistant. You do not respond as 'User' or pretend to be 'User'. You only respond once as Assistant.\nUser: {query}\nAssistant:",
|
||||
"promptValues": "{\"query\":\"{{question}}\"}"
|
||||
},
|
||||
"outputAnchors": [
|
||||
{
|
||||
"id": "promptTemplate_0-output-promptTemplate-PromptTemplate|BaseStringPromptTemplate|BasePromptTemplate",
|
||||
"name": "promptTemplate",
|
||||
"label": "PromptTemplate",
|
||||
"type": "PromptTemplate | BaseStringPromptTemplate | BasePromptTemplate"
|
||||
}
|
||||
],
|
||||
"outputs": {},
|
||||
"selected": false
|
||||
},
|
||||
"selected": false,
|
||||
"positionAbsolute": {
|
||||
"x": 269.2203229225663,
|
||||
"y": 129.02909641085535
|
||||
},
|
||||
"dragging": false
|
||||
},
|
||||
{
|
||||
"width": 300,
|
||||
"height": 527,
|
||||
"id": "replicate_0",
|
||||
"position": {
|
||||
"x": 607.4915400488668,
|
||||
"y": -60.643337207007804
|
||||
},
|
||||
"type": "customNode",
|
||||
"data": {
|
||||
"id": "replicate_0",
|
||||
"label": "Replicate",
|
||||
"name": "replicate",
|
||||
"type": "Replicate",
|
||||
"baseClasses": ["Replicate", "LLM", "BaseLLM", "BaseLanguageModel"],
|
||||
"category": "LLMs",
|
||||
"description": "Use Replicate to run open source models on cloud",
|
||||
"inputParams": [
|
||||
{
|
||||
"label": "Replicate Api Key",
|
||||
"name": "replicateApiKey",
|
||||
"type": "password",
|
||||
"id": "replicate_0-input-replicateApiKey-password"
|
||||
},
|
||||
{
|
||||
"label": "Model",
|
||||
"name": "model",
|
||||
"type": "string",
|
||||
"placeholder": "a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5",
|
||||
"optional": true,
|
||||
"id": "replicate_0-input-model-string"
|
||||
},
|
||||
{
|
||||
"label": "Temperature",
|
||||
"name": "temperature",
|
||||
"type": "number",
|
||||
"description": "Adjusts randomness of outputs, greater than 1 is random and 0 is deterministic, 0.75 is a good starting value.",
|
||||
"default": 0.7,
|
||||
"optional": true,
|
||||
"id": "replicate_0-input-temperature-number"
|
||||
},
|
||||
{
|
||||
"label": "Max Tokens",
|
||||
"name": "maxTokens",
|
||||
"type": "number",
|
||||
"description": "Maximum number of tokens to generate. A word is generally 2-3 tokens",
|
||||
"optional": true,
|
||||
"additionalParams": true,
|
||||
"id": "replicate_0-input-maxTokens-number"
|
||||
},
|
||||
{
|
||||
"label": "Top Probability",
|
||||
"name": "topP",
|
||||
"type": "number",
|
||||
"description": "When decoding text, samples from the top p percentage of most likely tokens; lower to ignore less likely tokens",
|
||||
"optional": true,
|
||||
"additionalParams": true,
|
||||
"id": "replicate_0-input-topP-number"
|
||||
},
|
||||
{
|
||||
"label": "Repetition Penalty",
|
||||
"name": "repetitionPenalty",
|
||||
"type": "number",
|
||||
"description": "Penalty for repeated words in generated text; 1 is no penalty, values greater than 1 discourage repetition, less than 1 encourage it. (minimum: 0.01; maximum: 5)",
|
||||
"optional": true,
|
||||
"additionalParams": true,
|
||||
"id": "replicate_0-input-repetitionPenalty-number"
|
||||
},
|
||||
{
|
||||
"label": "Additional Inputs",
|
||||
"name": "additionalInputs",
|
||||
"type": "json",
|
||||
"description": "Each model has different parameters, refer to the specific model accepted inputs. For example: <a target=\"_blank\" href=\"https://replicate.com/a16z-infra/llama13b-v2-chat/api#inputs\">llama13b-v2</a>",
|
||||
"additionalParams": true,
|
||||
"optional": true,
|
||||
"id": "replicate_0-input-additionalInputs-json"
|
||||
}
|
||||
],
|
||||
"inputAnchors": [],
|
||||
"inputs": {
|
||||
"model": "a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5",
|
||||
"temperature": 0.7,
|
||||
"maxTokens": "",
|
||||
"topP": "",
|
||||
"repetitionPenalty": "",
|
||||
"additionalInputs": ""
|
||||
},
|
||||
"outputAnchors": [
|
||||
{
|
||||
"id": "replicate_0-output-replicate-Replicate|LLM|BaseLLM|BaseLanguageModel",
|
||||
"name": "replicate",
|
||||
"label": "Replicate",
|
||||
"type": "Replicate | LLM | BaseLLM | BaseLanguageModel"
|
||||
}
|
||||
],
|
||||
"outputs": {},
|
||||
"selected": false
|
||||
},
|
||||
"selected": false,
|
||||
"positionAbsolute": {
|
||||
"x": 607.4915400488668,
|
||||
"y": -60.643337207007804
|
||||
},
|
||||
"dragging": false
|
||||
}
|
||||
],
|
||||
"edges": [
|
||||
{
|
||||
"source": "promptTemplate_0",
|
||||
"sourceHandle": "promptTemplate_0-output-promptTemplate-PromptTemplate|BaseStringPromptTemplate|BasePromptTemplate",
|
||||
"target": "llmChain_1",
|
||||
"targetHandle": "llmChain_1-input-prompt-BasePromptTemplate",
|
||||
"type": "buttonedge",
|
||||
"id": "promptTemplate_0-promptTemplate_0-output-promptTemplate-PromptTemplate|BaseStringPromptTemplate|BasePromptTemplate-llmChain_1-llmChain_1-input-prompt-BasePromptTemplate",
|
||||
"data": {
|
||||
"label": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"source": "replicate_0",
|
||||
"sourceHandle": "replicate_0-output-replicate-Replicate|LLM|BaseLLM|BaseLanguageModel",
|
||||
"target": "llmChain_1",
|
||||
"targetHandle": "llmChain_1-input-model-BaseLanguageModel",
|
||||
"type": "buttonedge",
|
||||
"id": "replicate_0-replicate_0-output-replicate-Replicate|LLM|BaseLLM|BaseLanguageModel-llmChain_1-llmChain_1-input-model-BaseLanguageModel",
|
||||
"data": {
|
||||
"label": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue