diff --git a/lerna.json b/lerna.json index 0a5879d..776aa18 100644 --- a/lerna.json +++ b/lerna.json @@ -1,4 +1,4 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "0.21.0" + "version": "0.21.3" } diff --git a/packages/@pufflig/ps-chains/package.json b/packages/@pufflig/ps-chains/package.json index fe6078c..eb91317 100644 --- a/packages/@pufflig/ps-chains/package.json +++ b/packages/@pufflig/ps-chains/package.json @@ -1,6 +1,6 @@ { "name": "@pufflig/ps-chains", - "version": "0.21.0", + "version": "0.21.1", "license": "MIT", "main": "./dist/ps-chains.umd.js", "module": "./dist/ps-chains.es.js", @@ -16,7 +16,7 @@ "test": "jest" }, "devDependencies": { - "@pufflig/ps-types": "^0.21.0", + "@pufflig/ps-types": "^0.21.1", "@types/react-dom": "^18.2.7", "immer": "^10.0.2", "prop-types": "^15.8.1", diff --git a/packages/@pufflig/ps-models/package.json b/packages/@pufflig/ps-models/package.json index d8495a7..82651e3 100644 --- a/packages/@pufflig/ps-models/package.json +++ b/packages/@pufflig/ps-models/package.json @@ -1,7 +1,7 @@ { "name": "@pufflig/ps-models", "private": false, - "version": "0.21.0", + "version": "0.21.1", "description": "Configuration of models used in Prompt Studio", "files": [ "dist" @@ -16,7 +16,7 @@ "author": "Pufflig AB", "license": "MIT", "devDependencies": { - "@pufflig/ps-types": "^0.21.0", + "@pufflig/ps-types": "^0.21.1", "typescript": "^5.1.6", "vite": "^4.3.9", "vite-plugin-dts": "^2.3.0" diff --git a/packages/@pufflig/ps-nodes-config/package.json b/packages/@pufflig/ps-nodes-config/package.json index 3301491..5382c7f 100644 --- a/packages/@pufflig/ps-nodes-config/package.json +++ b/packages/@pufflig/ps-nodes-config/package.json @@ -1,7 +1,7 @@ { "name": "@pufflig/ps-nodes-config", "private": false, - "version": "0.21.0", + "version": "0.21.3", "description": "Configuration files for nodes used in prompt studio.", "files": [ "dist" @@ -16,10 +16,10 @@ "author": "Pufflig AB", "license": "MIT", "dependencies": { - "@pufflig/ps-models": "^0.21.0" + "@pufflig/ps-models": "^0.21.1" }, "devDependencies": { - "@pufflig/ps-types": "^0.21.0", + "@pufflig/ps-types": "^0.21.1", "@types/jest": "^29.5.1", "jest": "^29.5.0", "ts-jest": "^29.1.0", diff --git a/packages/@pufflig/ps-nodes-config/src/modifiers/document_check/document_check.ts b/packages/@pufflig/ps-nodes-config/src/modifiers/document_check/document_check.ts index a19a5bb..f5bec27 100644 --- a/packages/@pufflig/ps-nodes-config/src/modifiers/document_check/document_check.ts +++ b/packages/@pufflig/ps-nodes-config/src/modifiers/document_check/document_check.ts @@ -23,8 +23,8 @@ export const documentCheck: NodeConfig = { }, outputs: [ { - id: "list", - name: "List", + id: "result", + name: "Result", description: "A list, checklist or other information about the document", type: "text", defaultValue: "", @@ -47,7 +47,7 @@ export const documentCheck: NodeConfig = { name: "Prompt", description: "Prompt to check the document with", type: "text", - defaultValue: `Extract information in the document below and insert them in the csv table, don't overwrite existing values and keep things empty if you cannot find information in the document:\n\nTABLE EXAMPLE:\ncharacters, age\nmickey mouse, 10\ndonald duck, -\n\nTABLE:\n[[table]]\n\nDOCUMENT:\n[[document]]\n\nTABLE:\n`, + defaultValue: `Extract information in the document below and insert them in the csv table, don't overwrite existing values and keep things empty if you cannot find information in the document:\n\nTABLE EXAMPLE:\ncharacters, age\nmickey mouse, 10\ndonald duck, -\n\nTABLE:\n{{table}}\n\nDOCUMENT:\n{{document}}\n\nTABLE:\n`, }, { id: "table", diff --git a/packages/@pufflig/ps-nodes/package.json b/packages/@pufflig/ps-nodes/package.json index 364fea7..b52833d 100644 --- a/packages/@pufflig/ps-nodes/package.json +++ b/packages/@pufflig/ps-nodes/package.json @@ -1,7 +1,7 @@ { "name": "@pufflig/ps-nodes", "private": false, - "version": "0.21.0", + "version": "0.21.3", "description": "Collection of nodes used in Prompt Studio", "files": [ "dist" @@ -17,7 +17,7 @@ "author": "Pufflig AB", "license": "MIT", "devDependencies": { - "@pufflig/ps-types": "^0.21.0", + "@pufflig/ps-types": "^0.21.1", "@types/jest": "^29.5.1", "@types/lodash": "^4.14.196", "@types/mustache": "^4.2.2", @@ -33,9 +33,9 @@ }, "dependencies": { "@dqbd/tiktoken": "^1.0.7", - "@pufflig/ps-models": "^0.21.0", - "@pufflig/ps-nodes-config": "^0.21.0", - "@pufflig/ps-sdk": "^0.21.0", + "@pufflig/ps-models": "^0.21.1", + "@pufflig/ps-nodes-config": "^0.21.3", + "@pufflig/ps-sdk": "^0.21.1", "axios": "^1.5.0", "langchain": "^0.0.160", "lodash": "^4.17.21", diff --git a/packages/@pufflig/ps-nodes/src/adapters/llm/__snapshots__/llm_completion.test.ts.snap b/packages/@pufflig/ps-nodes/src/adapters/llm/__snapshots__/llm_completion.test.ts.snap new file mode 100644 index 0000000..b8fa3d5 --- /dev/null +++ b/packages/@pufflig/ps-nodes/src/adapters/llm/__snapshots__/llm_completion.test.ts.snap @@ -0,0 +1,1060 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`getInputDefinition - if you pass a template and a variable, take value of the variable 1`] = ` +[ + { + "defaultValue": { + "modelId": "test", + "parameters": {}, + }, + "definition": { + "anthropic/claude-2": { + "contextLength": 8192, + "description": "Claude: superior performance on tasks that require complex reasoning", + "modelId": "anthropic/claude-2", + "parameters": [ + { + "defaultValue": 1, + "description": "Amount of randomness injected into the response.", + "id": "temperature", + "max": 1, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0.7, + "description": "In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. You should either alter temperature or top_p, but not both.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 5, + "description": "Only sample from the top K options for each subsequent token.", + "id": "top_k", + "max": 100, + "min": 0, + "name": "Top K", + "step": 1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + "babbage-002": { + "contextLength": 16384, + "description": "Replacement for the GPT-3 ada and babbage base models.", + "modelId": "babbage-002", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 16384, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "davinci-002": { + "contextLength": 16384, + "description": "Replacement for the GPT-3 curie and davinci base models.", + "modelId": "davinci-002", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 16384, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt-3.5-turbo-instruct": { + "contextLength": 4096, + "description": "Similar capabilities as text-davinci-003 but compatible with legacy Completions endpoint and not Chat Completions.", + "modelId": "gpt-3.5-turbo-instruct", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 4096, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt2": { + "contextLength": 512, + "description": "", + "modelId": "gpt2", + "parameters": [ + { + "defaultValue": 10, + "description": "The temperature of the sampling operation. 1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.", + "id": "temperature", + "max": 100, + "min": 0, + "name": "Temperature", + "step": 1, + "type": "number", + }, + { + "defaultValue": 10, + "description": "The amount of new tokens to be generated, this does not include the input length it is a estimate of the size of generated text you want. Each new tokens slows down the request, so look for balance between response times and length of text generated.", + "id": "max_new_tokens", + "max": 250, + "min": 0, + "name": "Max New Tokens", + "step": 1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Access tokens programmatically authenticate your identity to the Hugging Face Hub.", + "id": "hf/access_token", + "name": "User Access Tokens", + }, + ], + "streaming": false, + }, + "gryphe/mythomax-l2-13b": { + "contextLength": 4096, + "description": "An improved, potentially even perfected variant of MythoMix.", + "modelId": "gryphe/mythomax-l2-13b", + "parameters": [ + { + "defaultValue": 0.4, + "description": "", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + "meta-llama/llama-2-13b-chat": { + "contextLength": 4096, + "description": "Meta: Llama v2 13B Chat (beta)", + "modelId": "meta-llama/llama-2-13b-chat", + "parameters": [ + { + "defaultValue": 0.4, + "description": "", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + }, + "description": "The model to use", + "id": "model", + "name": "Model", + "type": "model", + }, + { + "defaultValue": "summarize {{longText}}", + "description": "The prompt to send to the LLM", + "id": "prompt", + "name": "Prompt", + "type": "text", + }, + { + "defaultValue": "some long text", + "description": "", + "id": "longText", + "name": "longText", + "type": "text", + }, +] +`; + +exports[`getInputDefinition - ignores non existing variables 1`] = ` +[ + { + "defaultValue": { + "modelId": "test", + "parameters": {}, + }, + "definition": { + "anthropic/claude-2": { + "contextLength": 8192, + "description": "Claude: superior performance on tasks that require complex reasoning", + "modelId": "anthropic/claude-2", + "parameters": [ + { + "defaultValue": 1, + "description": "Amount of randomness injected into the response.", + "id": "temperature", + "max": 1, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0.7, + "description": "In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. You should either alter temperature or top_p, but not both.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 5, + "description": "Only sample from the top K options for each subsequent token.", + "id": "top_k", + "max": 100, + "min": 0, + "name": "Top K", + "step": 1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + "babbage-002": { + "contextLength": 16384, + "description": "Replacement for the GPT-3 ada and babbage base models.", + "modelId": "babbage-002", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 16384, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "davinci-002": { + "contextLength": 16384, + "description": "Replacement for the GPT-3 curie and davinci base models.", + "modelId": "davinci-002", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 16384, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt-3.5-turbo-instruct": { + "contextLength": 4096, + "description": "Similar capabilities as text-davinci-003 but compatible with legacy Completions endpoint and not Chat Completions.", + "modelId": "gpt-3.5-turbo-instruct", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 4096, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt2": { + "contextLength": 512, + "description": "", + "modelId": "gpt2", + "parameters": [ + { + "defaultValue": 10, + "description": "The temperature of the sampling operation. 1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.", + "id": "temperature", + "max": 100, + "min": 0, + "name": "Temperature", + "step": 1, + "type": "number", + }, + { + "defaultValue": 10, + "description": "The amount of new tokens to be generated, this does not include the input length it is a estimate of the size of generated text you want. Each new tokens slows down the request, so look for balance between response times and length of text generated.", + "id": "max_new_tokens", + "max": 250, + "min": 0, + "name": "Max New Tokens", + "step": 1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Access tokens programmatically authenticate your identity to the Hugging Face Hub.", + "id": "hf/access_token", + "name": "User Access Tokens", + }, + ], + "streaming": false, + }, + "gryphe/mythomax-l2-13b": { + "contextLength": 4096, + "description": "An improved, potentially even perfected variant of MythoMix.", + "modelId": "gryphe/mythomax-l2-13b", + "parameters": [ + { + "defaultValue": 0.4, + "description": "", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + "meta-llama/llama-2-13b-chat": { + "contextLength": 4096, + "description": "Meta: Llama v2 13B Chat (beta)", + "modelId": "meta-llama/llama-2-13b-chat", + "parameters": [ + { + "defaultValue": 0.4, + "description": "", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + }, + "description": "The model to use", + "id": "model", + "name": "Model", + "type": "model", + }, + { + "defaultValue": "summarize {{longText}}", + "description": "The prompt to send to the LLM", + "id": "prompt", + "name": "Prompt", + "type": "text", + }, + { + "defaultValue": "", + "description": "", + "id": "longText", + "name": "longText", + "type": "text", + }, +] +`; + +exports[`getInputDefinition - no variables 1`] = ` +[ + { + "defaultValue": { + "modelId": "test", + "parameters": {}, + }, + "definition": { + "anthropic/claude-2": { + "contextLength": 8192, + "description": "Claude: superior performance on tasks that require complex reasoning", + "modelId": "anthropic/claude-2", + "parameters": [ + { + "defaultValue": 1, + "description": "Amount of randomness injected into the response.", + "id": "temperature", + "max": 1, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0.7, + "description": "In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. You should either alter temperature or top_p, but not both.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 5, + "description": "Only sample from the top K options for each subsequent token.", + "id": "top_k", + "max": 100, + "min": 0, + "name": "Top K", + "step": 1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + "babbage-002": { + "contextLength": 16384, + "description": "Replacement for the GPT-3 ada and babbage base models.", + "modelId": "babbage-002", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 16384, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "davinci-002": { + "contextLength": 16384, + "description": "Replacement for the GPT-3 curie and davinci base models.", + "modelId": "davinci-002", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 16384, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt-3.5-turbo-instruct": { + "contextLength": 4096, + "description": "Similar capabilities as text-davinci-003 but compatible with legacy Completions endpoint and not Chat Completions.", + "modelId": "gpt-3.5-turbo-instruct", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 4096, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt2": { + "contextLength": 512, + "description": "", + "modelId": "gpt2", + "parameters": [ + { + "defaultValue": 10, + "description": "The temperature of the sampling operation. 1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.", + "id": "temperature", + "max": 100, + "min": 0, + "name": "Temperature", + "step": 1, + "type": "number", + }, + { + "defaultValue": 10, + "description": "The amount of new tokens to be generated, this does not include the input length it is a estimate of the size of generated text you want. Each new tokens slows down the request, so look for balance between response times and length of text generated.", + "id": "max_new_tokens", + "max": 250, + "min": 0, + "name": "Max New Tokens", + "step": 1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Access tokens programmatically authenticate your identity to the Hugging Face Hub.", + "id": "hf/access_token", + "name": "User Access Tokens", + }, + ], + "streaming": false, + }, + "gryphe/mythomax-l2-13b": { + "contextLength": 4096, + "description": "An improved, potentially even perfected variant of MythoMix.", + "modelId": "gryphe/mythomax-l2-13b", + "parameters": [ + { + "defaultValue": 0.4, + "description": "", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + "meta-llama/llama-2-13b-chat": { + "contextLength": 4096, + "description": "Meta: Llama v2 13B Chat (beta)", + "modelId": "meta-llama/llama-2-13b-chat", + "parameters": [ + { + "defaultValue": 0.4, + "description": "", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + }, + "description": "The model to use", + "id": "model", + "name": "Model", + "type": "model", + }, + { + "defaultValue": "summarize {{longText}}", + "description": "The prompt to send to the LLM", + "id": "prompt", + "name": "Prompt", + "type": "text", + }, + { + "defaultValue": "", + "description": "", + "id": "longText", + "name": "longText", + "type": "text", + }, +] +`; diff --git a/packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.test.ts b/packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.test.ts index 3d49e93..6d772df 100644 --- a/packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.test.ts +++ b/packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.test.ts @@ -60,358 +60,7 @@ test("getInputDefinition - no variables", () => { parameters: {}, }, }); - expect(variables).toMatchInlineSnapshot(` -[ - { - "defaultValue": { - "modelId": "gpt-3.5-turbo-instruct", - "parameters": {}, - }, - "definition": { - "anthropic/claude-2": { - "contextLength": 8192, - "description": "Claude: superior performance on tasks that require complex reasoning", - "modelId": "anthropic/claude-2", - "parameters": [ - { - "defaultValue": 1, - "description": "Amount of randomness injected into the response.", - "id": "temperature", - "max": 1, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0.7, - "description": "In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. You should either alter temperature or top_p, but not both.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 5, - "description": "Only sample from the top K options for each subsequent token.", - "id": "top_k", - "max": 100, - "min": 0, - "name": "Top K", - "step": 1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your Open Router API key", - "id": "open_router/api_key", - "name": "Open Router API Key", - }, - ], - }, - "babbage-002": { - "contextLength": 16384, - "description": "Replacement for the GPT-3 ada and babbage base models.", - "modelId": "babbage-002", - "parameters": [ - { - "defaultValue": 0.4, - "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 1024, - "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", - "id": "max_tokens", - "max": 16384, - "min": 1, - "name": "Max Tokens", - "step": 20, - "type": "number", - }, - { - "defaultValue": 1, - "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", - "id": "frequency_penalty", - "max": 2, - "min": -2, - "name": "Frequency penalty", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", - "id": "presence_penalty", - "max": 2, - "min": -2, - "name": "Presence penalty", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your OpenAI API key", - "id": "openai/api_key", - "name": "API Key", - }, - ], - "streaming": true, - }, - "davinci-002": { - "contextLength": 16384, - "description": "Replacement for the GPT-3 curie and davinci base models.", - "modelId": "davinci-002", - "parameters": [ - { - "defaultValue": 0.4, - "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 1024, - "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", - "id": "max_tokens", - "max": 16384, - "min": 1, - "name": "Max Tokens", - "step": 20, - "type": "number", - }, - { - "defaultValue": 1, - "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", - "id": "frequency_penalty", - "max": 2, - "min": -2, - "name": "Frequency penalty", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", - "id": "presence_penalty", - "max": 2, - "min": -2, - "name": "Presence penalty", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your OpenAI API key", - "id": "openai/api_key", - "name": "API Key", - }, - ], - "streaming": true, - }, - "gpt-3.5-turbo-instruct": { - "contextLength": 4096, - "description": "Similar capabilities as text-davinci-003 but compatible with legacy Completions endpoint and not Chat Completions.", - "modelId": "gpt-3.5-turbo-instruct", - "parameters": [ - { - "defaultValue": 0.4, - "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 1024, - "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", - "id": "max_tokens", - "max": 4096, - "min": 1, - "name": "Max Tokens", - "step": 20, - "type": "number", - }, - { - "defaultValue": 1, - "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", - "id": "frequency_penalty", - "max": 2, - "min": -2, - "name": "Frequency penalty", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", - "id": "presence_penalty", - "max": 2, - "min": -2, - "name": "Presence penalty", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your OpenAI API key", - "id": "openai/api_key", - "name": "API Key", - }, - ], - "streaming": true, - }, - "gpt2": { - "contextLength": 512, - "description": "", - "modelId": "gpt2", - "parameters": [ - { - "defaultValue": 10, - "description": "The temperature of the sampling operation. 1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.", - "id": "temperature", - "max": 100, - "min": 0, - "name": "Temperature", - "step": 1, - "type": "number", - }, - { - "defaultValue": 10, - "description": "The amount of new tokens to be generated, this does not include the input length it is a estimate of the size of generated text you want. Each new tokens slows down the request, so look for balance between response times and length of text generated.", - "id": "max_new_tokens", - "max": 250, - "min": 0, - "name": "Max New Tokens", - "step": 1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Access tokens programmatically authenticate your identity to the Hugging Face Hub.", - "id": "hf/access_token", - "name": "User Access Tokens", - }, - ], - "streaming": false, - }, - "gryphe/mythomax-l2-13b": { - "contextLength": 4096, - "description": "An improved, potentially even perfected variant of MythoMix.", - "modelId": "gryphe/mythomax-l2-13b", - "parameters": [ - { - "defaultValue": 0.4, - "description": "", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your Open Router API key", - "id": "open_router/api_key", - "name": "Open Router API Key", - }, - ], - }, - "meta-llama/llama-2-13b-chat": { - "contextLength": 4096, - "description": "Meta: Llama v2 13B Chat (beta)", - "modelId": "meta-llama/llama-2-13b-chat", - "parameters": [ - { - "defaultValue": 0.4, - "description": "", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your Open Router API key", - "id": "open_router/api_key", - "name": "Open Router API Key", - }, - ], - }, - }, - "description": "The model to use", - "id": "model", - "name": "Model", - "type": "model", - }, - { - "defaultValue": "summarize {{longText}}", - "description": "The prompt to send to the LLM", - "id": "prompt", - "name": "Prompt", - "type": "text", - }, - { - "defaultValue": "", - "description": "", - "id": "longText", - "name": "longText", - "type": "text", - }, -] -`); + expect(variables).toMatchSnapshot(); }); test("getInputDefinition - if you pass a template and a variable, take value of the variable", () => { @@ -423,358 +72,7 @@ test("getInputDefinition - if you pass a template and a variable, take value of }, longText: "some long text", }); - expect(variables).toMatchInlineSnapshot(` -[ - { - "defaultValue": { - "modelId": "gpt-3.5-turbo-instruct", - "parameters": {}, - }, - "definition": { - "anthropic/claude-2": { - "contextLength": 8192, - "description": "Claude: superior performance on tasks that require complex reasoning", - "modelId": "anthropic/claude-2", - "parameters": [ - { - "defaultValue": 1, - "description": "Amount of randomness injected into the response.", - "id": "temperature", - "max": 1, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0.7, - "description": "In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. You should either alter temperature or top_p, but not both.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 5, - "description": "Only sample from the top K options for each subsequent token.", - "id": "top_k", - "max": 100, - "min": 0, - "name": "Top K", - "step": 1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your Open Router API key", - "id": "open_router/api_key", - "name": "Open Router API Key", - }, - ], - }, - "babbage-002": { - "contextLength": 16384, - "description": "Replacement for the GPT-3 ada and babbage base models.", - "modelId": "babbage-002", - "parameters": [ - { - "defaultValue": 0.4, - "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 1024, - "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", - "id": "max_tokens", - "max": 16384, - "min": 1, - "name": "Max Tokens", - "step": 20, - "type": "number", - }, - { - "defaultValue": 1, - "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", - "id": "frequency_penalty", - "max": 2, - "min": -2, - "name": "Frequency penalty", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", - "id": "presence_penalty", - "max": 2, - "min": -2, - "name": "Presence penalty", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your OpenAI API key", - "id": "openai/api_key", - "name": "API Key", - }, - ], - "streaming": true, - }, - "davinci-002": { - "contextLength": 16384, - "description": "Replacement for the GPT-3 curie and davinci base models.", - "modelId": "davinci-002", - "parameters": [ - { - "defaultValue": 0.4, - "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 1024, - "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", - "id": "max_tokens", - "max": 16384, - "min": 1, - "name": "Max Tokens", - "step": 20, - "type": "number", - }, - { - "defaultValue": 1, - "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", - "id": "frequency_penalty", - "max": 2, - "min": -2, - "name": "Frequency penalty", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", - "id": "presence_penalty", - "max": 2, - "min": -2, - "name": "Presence penalty", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your OpenAI API key", - "id": "openai/api_key", - "name": "API Key", - }, - ], - "streaming": true, - }, - "gpt-3.5-turbo-instruct": { - "contextLength": 4096, - "description": "Similar capabilities as text-davinci-003 but compatible with legacy Completions endpoint and not Chat Completions.", - "modelId": "gpt-3.5-turbo-instruct", - "parameters": [ - { - "defaultValue": 0.4, - "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 1024, - "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", - "id": "max_tokens", - "max": 4096, - "min": 1, - "name": "Max Tokens", - "step": 20, - "type": "number", - }, - { - "defaultValue": 1, - "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", - "id": "frequency_penalty", - "max": 2, - "min": -2, - "name": "Frequency penalty", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", - "id": "presence_penalty", - "max": 2, - "min": -2, - "name": "Presence penalty", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your OpenAI API key", - "id": "openai/api_key", - "name": "API Key", - }, - ], - "streaming": true, - }, - "gpt2": { - "contextLength": 512, - "description": "", - "modelId": "gpt2", - "parameters": [ - { - "defaultValue": 10, - "description": "The temperature of the sampling operation. 1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.", - "id": "temperature", - "max": 100, - "min": 0, - "name": "Temperature", - "step": 1, - "type": "number", - }, - { - "defaultValue": 10, - "description": "The amount of new tokens to be generated, this does not include the input length it is a estimate of the size of generated text you want. Each new tokens slows down the request, so look for balance between response times and length of text generated.", - "id": "max_new_tokens", - "max": 250, - "min": 0, - "name": "Max New Tokens", - "step": 1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Access tokens programmatically authenticate your identity to the Hugging Face Hub.", - "id": "hf/access_token", - "name": "User Access Tokens", - }, - ], - "streaming": false, - }, - "gryphe/mythomax-l2-13b": { - "contextLength": 4096, - "description": "An improved, potentially even perfected variant of MythoMix.", - "modelId": "gryphe/mythomax-l2-13b", - "parameters": [ - { - "defaultValue": 0.4, - "description": "", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your Open Router API key", - "id": "open_router/api_key", - "name": "Open Router API Key", - }, - ], - }, - "meta-llama/llama-2-13b-chat": { - "contextLength": 4096, - "description": "Meta: Llama v2 13B Chat (beta)", - "modelId": "meta-llama/llama-2-13b-chat", - "parameters": [ - { - "defaultValue": 0.4, - "description": "", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your Open Router API key", - "id": "open_router/api_key", - "name": "Open Router API Key", - }, - ], - }, - }, - "description": "The model to use", - "id": "model", - "name": "Model", - "type": "model", - }, - { - "defaultValue": "summarize {{longText}}", - "description": "The prompt to send to the LLM", - "id": "prompt", - "name": "Prompt", - "type": "text", - }, - { - "defaultValue": "some long text", - "description": "", - "id": "longText", - "name": "longText", - "type": "text", - }, -] -`); + expect(variables).toMatchSnapshot(); }); test("getInputDefinition - ignores non existing variables", () => { @@ -786,356 +84,5 @@ test("getInputDefinition - ignores non existing variables", () => { }, otherVariable: "", }); - expect(variables).toMatchInlineSnapshot(` -[ - { - "defaultValue": { - "modelId": "gpt-3.5-turbo-instruct", - "parameters": {}, - }, - "definition": { - "anthropic/claude-2": { - "contextLength": 8192, - "description": "Claude: superior performance on tasks that require complex reasoning", - "modelId": "anthropic/claude-2", - "parameters": [ - { - "defaultValue": 1, - "description": "Amount of randomness injected into the response.", - "id": "temperature", - "max": 1, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0.7, - "description": "In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. You should either alter temperature or top_p, but not both.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 5, - "description": "Only sample from the top K options for each subsequent token.", - "id": "top_k", - "max": 100, - "min": 0, - "name": "Top K", - "step": 1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your Open Router API key", - "id": "open_router/api_key", - "name": "Open Router API Key", - }, - ], - }, - "babbage-002": { - "contextLength": 16384, - "description": "Replacement for the GPT-3 ada and babbage base models.", - "modelId": "babbage-002", - "parameters": [ - { - "defaultValue": 0.4, - "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 1024, - "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", - "id": "max_tokens", - "max": 16384, - "min": 1, - "name": "Max Tokens", - "step": 20, - "type": "number", - }, - { - "defaultValue": 1, - "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", - "id": "frequency_penalty", - "max": 2, - "min": -2, - "name": "Frequency penalty", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", - "id": "presence_penalty", - "max": 2, - "min": -2, - "name": "Presence penalty", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your OpenAI API key", - "id": "openai/api_key", - "name": "API Key", - }, - ], - "streaming": true, - }, - "davinci-002": { - "contextLength": 16384, - "description": "Replacement for the GPT-3 curie and davinci base models.", - "modelId": "davinci-002", - "parameters": [ - { - "defaultValue": 0.4, - "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 1024, - "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", - "id": "max_tokens", - "max": 16384, - "min": 1, - "name": "Max Tokens", - "step": 20, - "type": "number", - }, - { - "defaultValue": 1, - "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", - "id": "frequency_penalty", - "max": 2, - "min": -2, - "name": "Frequency penalty", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", - "id": "presence_penalty", - "max": 2, - "min": -2, - "name": "Presence penalty", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your OpenAI API key", - "id": "openai/api_key", - "name": "API Key", - }, - ], - "streaming": true, - }, - "gpt-3.5-turbo-instruct": { - "contextLength": 4096, - "description": "Similar capabilities as text-davinci-003 but compatible with legacy Completions endpoint and not Chat Completions.", - "modelId": "gpt-3.5-turbo-instruct", - "parameters": [ - { - "defaultValue": 0.4, - "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 1024, - "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", - "id": "max_tokens", - "max": 4096, - "min": 1, - "name": "Max Tokens", - "step": 20, - "type": "number", - }, - { - "defaultValue": 1, - "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", - "id": "top_p", - "max": 1, - "min": 0, - "name": "Top P", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", - "id": "frequency_penalty", - "max": 2, - "min": -2, - "name": "Frequency penalty", - "step": 0.1, - "type": "number", - }, - { - "defaultValue": 0, - "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", - "id": "presence_penalty", - "max": 2, - "min": -2, - "name": "Presence penalty", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your OpenAI API key", - "id": "openai/api_key", - "name": "API Key", - }, - ], - "streaming": true, - }, - "gpt2": { - "contextLength": 512, - "description": "", - "modelId": "gpt2", - "parameters": [ - { - "defaultValue": 10, - "description": "The temperature of the sampling operation. 1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.", - "id": "temperature", - "max": 100, - "min": 0, - "name": "Temperature", - "step": 1, - "type": "number", - }, - { - "defaultValue": 10, - "description": "The amount of new tokens to be generated, this does not include the input length it is a estimate of the size of generated text you want. Each new tokens slows down the request, so look for balance between response times and length of text generated.", - "id": "max_new_tokens", - "max": 250, - "min": 0, - "name": "Max New Tokens", - "step": 1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Access tokens programmatically authenticate your identity to the Hugging Face Hub.", - "id": "hf/access_token", - "name": "User Access Tokens", - }, - ], - "streaming": false, - }, - "gryphe/mythomax-l2-13b": { - "contextLength": 4096, - "description": "An improved, potentially even perfected variant of MythoMix.", - "modelId": "gryphe/mythomax-l2-13b", - "parameters": [ - { - "defaultValue": 0.4, - "description": "", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your Open Router API key", - "id": "open_router/api_key", - "name": "Open Router API Key", - }, - ], - }, - "meta-llama/llama-2-13b-chat": { - "contextLength": 4096, - "description": "Meta: Llama v2 13B Chat (beta)", - "modelId": "meta-llama/llama-2-13b-chat", - "parameters": [ - { - "defaultValue": 0.4, - "description": "", - "id": "temperature", - "max": 2, - "min": 0, - "name": "Temperature", - "step": 0.1, - "type": "number", - }, - ], - "settings": [ - { - "description": "Your Open Router API key", - "id": "open_router/api_key", - "name": "Open Router API Key", - }, - ], - }, - }, - "description": "The model to use", - "id": "model", - "name": "Model", - "type": "model", - }, - { - "defaultValue": "summarize {{longText}}", - "description": "The prompt to send to the LLM", - "id": "prompt", - "name": "Prompt", - "type": "text", - }, - { - "defaultValue": "", - "description": "", - "id": "longText", - "name": "longText", - "type": "text", - }, -] -`); + expect(variables).toMatchSnapshot(); }); diff --git a/packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.ts b/packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.ts index 9652ff4..d60564e 100644 --- a/packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.ts +++ b/packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.ts @@ -47,17 +47,19 @@ export const execute: Execute = async ( * @returns */ export const getInputDefinition: GetInputDefinition = (input) => { - const { prompt, ...rest } = input; + const { prompt, model, ...rest } = input; if (prompt === undefined) { return nodes[nodeTypes.llmCompletionNodeType].inputs; } + const defaults = { prompt, model }; + const definitionsWithDefaults = nodes[nodeTypes.llmCompletionNodeType].inputs.map((input) => { - if (input.id === "prompt") { + if (Object.keys(defaults).includes(input.id)) { return { ...input, - defaultValue: prompt, + defaultValue: defaults[input.id as keyof typeof defaults], } as Param; } return input; @@ -66,12 +68,16 @@ export const getInputDefinition: GetInputDefinition = (input const extractedVariables = extractVariables(prompt); if (extractedVariables) { - const extractedVariablesWithDefaults = extractedVariables.map((variable) => { - return { - ...variable, - defaultValue: rest[variable.id] || "", - } as Param; - }); + const extractedVariablesWithDefaults = extractedVariables + .filter((param) => { + return !Object.keys(defaults).includes(param.id); + }) + .map((variable) => { + return { + ...variable, + defaultValue: rest[variable.id] || "", + } as Param; + }); return [...definitionsWithDefaults, ...extractedVariablesWithDefaults]; } diff --git a/packages/@pufflig/ps-nodes/src/data/prompt/prompt.test.ts b/packages/@pufflig/ps-nodes/src/data/prompt/prompt.test.ts index 17d5947..5bb9744 100644 --- a/packages/@pufflig/ps-nodes/src/data/prompt/prompt.test.ts +++ b/packages/@pufflig/ps-nodes/src/data/prompt/prompt.test.ts @@ -6,7 +6,19 @@ test("execute - no variables", async () => { }); expect(variables).toMatchInlineSnapshot(` { - "prompt": "summarize ", + "prompt": "summarize {{longText}}", + } + `); +}); + +test("execute - empty variables", async () => { + const variables = await execute({ + template: `summarize {{longText}}`, + longText: "", + }); + expect(variables).toMatchInlineSnapshot(` + { + "prompt": "summarize {{longText}}", } `); }); diff --git a/packages/@pufflig/ps-nodes/src/data/prompt/prompt.ts b/packages/@pufflig/ps-nodes/src/data/prompt/prompt.ts index 403fd7c..444013c 100644 --- a/packages/@pufflig/ps-nodes/src/data/prompt/prompt.ts +++ b/packages/@pufflig/ps-nodes/src/data/prompt/prompt.ts @@ -14,7 +14,18 @@ export interface TemplateTextOutput { export const execute = async (input: TemplateTextInput) => { const { template, ...variables } = input; - const renderedTemplate = Mustache.render(template, variables); + + // keep template values for undefined variables + const extractedVariables = extractVariables(template) || []; + const variablesWithDefaults = extractedVariables.reduce((acc, param) => { + return { + ...acc, + [param.id]: + variables[param.id] === undefined || variables[param.id] === "" ? `{{${param.id}}}` : variables[param.id], + }; + }, {} as Record); + + const renderedTemplate = Mustache.render(template, variablesWithDefaults); return { prompt: renderedTemplate, }; diff --git a/packages/@pufflig/ps-nodes/src/modifiers/document_check/__snapshots__/document_check.test.ts.snap b/packages/@pufflig/ps-nodes/src/modifiers/document_check/__snapshots__/document_check.test.ts.snap new file mode 100644 index 0000000..ffa4060 --- /dev/null +++ b/packages/@pufflig/ps-nodes/src/modifiers/document_check/__snapshots__/document_check.test.ts.snap @@ -0,0 +1,628 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`documentCheck should extract variables correctly 1`] = ` +[ + { + "defaultValue": { + "modelId": "test_model", + "parameters": {}, + }, + "definition": { + "anthropic/claude-2": { + "contextLength": 8192, + "description": "Claude: superior performance on tasks that require complex reasoning", + "modelId": "anthropic/claude-2", + "parameters": [ + { + "defaultValue": 1, + "description": "Amount of randomness injected into the response.", + "id": "temperature", + "max": 1, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0.7, + "description": "In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p. You should either alter temperature or top_p, but not both.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 5, + "description": "Only sample from the top K options for each subsequent token.", + "id": "top_k", + "max": 100, + "min": 0, + "name": "Top K", + "step": 1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + "babbage-002": { + "contextLength": 16384, + "description": "Replacement for the GPT-3 ada and babbage base models.", + "modelId": "babbage-002", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 16384, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "davinci-002": { + "contextLength": 16384, + "description": "Replacement for the GPT-3 curie and davinci base models.", + "modelId": "davinci-002", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 16384, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt-3.5-turbo": { + "contextLength": 4096, + "description": "Most capable GPT-3.5 model and optimized for chat at 1/10th the cost of text-davinci-003.", + "modelId": "gpt-3.5-turbo", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 4096, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt-3.5-turbo-16k": { + "contextLength": 16385, + "description": "Same capabilities as the standard gpt-3.5-turbo model but with 4 times the context.", + "modelId": "gpt-3.5-turbo-16k", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 16385, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt-3.5-turbo-instruct": { + "contextLength": 4096, + "description": "Similar capabilities as text-davinci-003 but compatible with legacy Completions endpoint and not Chat Completions.", + "modelId": "gpt-3.5-turbo-instruct", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 4096, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt-4": { + "contextLength": 4096, + "description": "More capable than any GPT-3.5 model, able to do more complex tasks, and optimized for chat.", + "modelId": "gpt-4", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 4096, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt-4-32k": { + "contextLength": 32768, + "description": "Same capabilities as the standard gpt-4 mode but with 4x the context length. ", + "modelId": "gpt-4-32k", + "parameters": [ + { + "defaultValue": 0.4, + "description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 1024, + "description": "The maximum number of tokens to generate in the completion. The total length of input tokens and generated tokens is limited by the model's context length.", + "id": "max_tokens", + "max": 32768, + "min": 1, + "name": "Max Tokens", + "step": 20, + "type": "number", + }, + { + "defaultValue": 1, + "description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.", + "id": "top_p", + "max": 1, + "min": 0, + "name": "Top P", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.", + "id": "frequency_penalty", + "max": 2, + "min": -2, + "name": "Frequency penalty", + "step": 0.1, + "type": "number", + }, + { + "defaultValue": 0, + "description": "Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.", + "id": "presence_penalty", + "max": 2, + "min": -2, + "name": "Presence penalty", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your OpenAI API key", + "id": "openai/api_key", + "name": "API Key", + }, + ], + "streaming": true, + }, + "gpt2": { + "contextLength": 512, + "description": "", + "modelId": "gpt2", + "parameters": [ + { + "defaultValue": 10, + "description": "The temperature of the sampling operation. 1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.", + "id": "temperature", + "max": 100, + "min": 0, + "name": "Temperature", + "step": 1, + "type": "number", + }, + { + "defaultValue": 10, + "description": "The amount of new tokens to be generated, this does not include the input length it is a estimate of the size of generated text you want. Each new tokens slows down the request, so look for balance between response times and length of text generated.", + "id": "max_new_tokens", + "max": 250, + "min": 0, + "name": "Max New Tokens", + "step": 1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Access tokens programmatically authenticate your identity to the Hugging Face Hub.", + "id": "hf/access_token", + "name": "User Access Tokens", + }, + ], + "streaming": false, + }, + "gryphe/mythomax-l2-13b": { + "contextLength": 4096, + "description": "An improved, potentially even perfected variant of MythoMix.", + "modelId": "gryphe/mythomax-l2-13b", + "parameters": [ + { + "defaultValue": 0.4, + "description": "", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + "meta-llama/llama-2-13b-chat": { + "contextLength": 4096, + "description": "Meta: Llama v2 13B Chat (beta)", + "modelId": "meta-llama/llama-2-13b-chat", + "parameters": [ + { + "defaultValue": 0.4, + "description": "", + "id": "temperature", + "max": 2, + "min": 0, + "name": "Temperature", + "step": 0.1, + "type": "number", + }, + ], + "settings": [ + { + "description": "Your Open Router API key", + "id": "open_router/api_key", + "name": "Open Router API Key", + }, + ], + }, + }, + "description": "The model to use", + "id": "model", + "name": "Model", + "type": "model", + }, + { + "defaultValue": "Hello, {{myVariable}}!", + "description": "Prompt to check the document with", + "id": "prompt", + "name": "Prompt", + "type": "text", + }, + { + "defaultValue": "test_table", + "description": "The list, table or checklist to parse the document with.", + "id": "table", + "name": "Table", + "type": "text", + }, + { + "defaultValue": "This is a test document.", + "description": "Document to be processed", + "id": "document", + "name": "Document", + "type": "text", + }, + { + "defaultValue": "myValue", + "description": "", + "id": "myVariable", + "name": "myVariable", + "type": "text", + }, +] +`; diff --git a/packages/@pufflig/ps-nodes/src/modifiers/document_check/document_check.test.ts b/packages/@pufflig/ps-nodes/src/modifiers/document_check/document_check.test.ts index add9310..aeb34f2 100644 --- a/packages/@pufflig/ps-nodes/src/modifiers/document_check/document_check.test.ts +++ b/packages/@pufflig/ps-nodes/src/modifiers/document_check/document_check.test.ts @@ -1,4 +1,4 @@ -import { execute, LLMCompletionInput } from "./document_check"; +import { execute, getInputDefinition, LLMCompletionInput } from "./document_check"; import axios from "axios"; jest.mock("axios"); @@ -25,7 +25,7 @@ describe("documentCheck", () => { const output = await execute(input); - expect(output).toEqual({ completion: "This is a test completion." }); + expect(output).toEqual(expectedOutput); expect(axios.post).toHaveBeenCalledTimes(1); }); @@ -47,7 +47,7 @@ describe("documentCheck", () => { const output = await execute(input); - expect(output).toEqual({ completion: "This is a test completion." }); + expect(output).toEqual(expectedOutput); expect(axios.post).toHaveBeenCalledTimes(1); expect(axios.post).toHaveBeenCalledWith( expect.any(String), @@ -71,6 +71,21 @@ describe("documentCheck", () => { ); }); + it("should extract variables correctly", async () => { + const output = getInputDefinition({ + prompt: "Hello, {{myVariable}}!", + model: { + modelId: "test_model", + parameters: {}, + }, + document: "This is a test document.", + table: "test_table", + myVariable: "myValue", + }); + + expect(output).toMatchSnapshot(); + }); + it("should throw an error if the API call fails", async () => { const input: LLMCompletionInput = { prompt: "Hello, world!", diff --git a/packages/@pufflig/ps-nodes/src/modifiers/document_check/document_check.ts b/packages/@pufflig/ps-nodes/src/modifiers/document_check/document_check.ts index d303742..63b6c7e 100644 --- a/packages/@pufflig/ps-nodes/src/modifiers/document_check/document_check.ts +++ b/packages/@pufflig/ps-nodes/src/modifiers/document_check/document_check.ts @@ -14,7 +14,7 @@ export interface LLMCompletionInput { } export interface LLMCompletionOutput { - completion: string; + result: string; } export const execute: Execute = async (input, options = {}) => { @@ -22,7 +22,8 @@ export const execute: Execute = async ( const { modelId, parameters } = model; const { globals } = options; - const renderedPrompt = Mustache.render(prompt, variables); + // render the prompt without overwriting the document and table variables + const renderedPrompt = Mustache.render(prompt, { ...variables, document: "{{document}}", table: "{{table}}" }); const { result } = await refineCompletion({ apiKey: getPromptStudioKey(globals || {}), @@ -39,7 +40,7 @@ export const execute: Execute = async ( }); return { - completion: result || "", + result: result || "", }; }; @@ -51,19 +52,22 @@ export const execute: Execute = async ( * @returns */ export const getInputDefinition: GetInputDefinition = (input) => { - const { prompt, ...rest } = input; + const { prompt, document, model, table, ...rest } = input; if (prompt === undefined) { return nodes[nodeTypes.documentCheckNodeType].inputs; } + const defaults = { prompt, document, model, table }; + const definitionsWithDefaults = nodes[nodeTypes.documentCheckNodeType].inputs.map((input) => { - if (input.id === "prompt") { + if (Object.keys(defaults).includes(input.id)) { return { ...input, - defaultValue: prompt, + defaultValue: defaults[input.id as keyof typeof defaults], } as Param; } + return input; }); @@ -72,7 +76,7 @@ export const getInputDefinition: GetInputDefinition = (input if (extractedVariables) { const extractedVariablesWithDefaults = extractedVariables .filter((param) => { - return ["document", "table"].includes(param.id); + return !Object.keys(defaults).includes(param.id); }) .map((variable) => { return { diff --git a/packages/@pufflig/ps-sdk/package.json b/packages/@pufflig/ps-sdk/package.json index 0be1bef..43aa17a 100644 --- a/packages/@pufflig/ps-sdk/package.json +++ b/packages/@pufflig/ps-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@pufflig/ps-sdk", - "version": "0.21.0", + "version": "0.21.1", "license": "MIT", "main": "./dist/ps-sdk.umd.js", "module": "./dist/ps-sdk.es.js", @@ -21,7 +21,7 @@ "vite-plugin-dts": "^3.5.3" }, "dependencies": { - "@pufflig/ps-models": "^0.21.0", + "@pufflig/ps-models": "^0.21.1", "axios": "^1.5.0" }, "gitHead": "d637557b77c60c4aa75f6f65b038a6eb4e9d5dc4" diff --git a/packages/@pufflig/ps-types/package.json b/packages/@pufflig/ps-types/package.json index a1321f8..07bc0b9 100644 --- a/packages/@pufflig/ps-types/package.json +++ b/packages/@pufflig/ps-types/package.json @@ -1,6 +1,6 @@ { "name": "@pufflig/ps-types", - "version": "0.21.0", + "version": "0.21.1", "description": "Typescript definitions for Prompt Studio", "main": "src/index.ts", "author": "Pufflig AB",