Skip to content

add document check node, update variable parsing in llm completion node #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "0.20.1"
"version": "0.21.0"
}
4 changes: 2 additions & 2 deletions packages/@pufflig/ps-chains/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pufflig/ps-chains",
"version": "0.20.1",
"version": "0.21.0",
"license": "MIT",
"main": "./dist/ps-chains.umd.js",
"module": "./dist/ps-chains.es.js",
Expand All @@ -16,7 +16,7 @@
"test": "jest"
},
"devDependencies": {
"@pufflig/ps-types": "^0.20.1",
"@pufflig/ps-types": "^0.21.0",
"@types/react-dom": "^18.2.7",
"immer": "^10.0.2",
"prop-types": "^15.8.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/@pufflig/ps-models/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@pufflig/ps-models",
"private": false,
"version": "0.20.1",
"version": "0.21.0",
"description": "Configuration of models used in Prompt Studio",
"files": [
"dist"
Expand All @@ -16,7 +16,7 @@
"author": "Pufflig AB",
"license": "MIT",
"devDependencies": {
"@pufflig/ps-types": "^0.20.1",
"@pufflig/ps-types": "^0.21.0",
"typescript": "^5.1.6",
"vite": "^4.3.9",
"vite-plugin-dts": "^2.3.0"
Expand Down
6 changes: 3 additions & 3 deletions packages/@pufflig/ps-nodes-config/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@pufflig/ps-nodes-config",
"private": false,
"version": "0.20.1",
"version": "0.21.0",
"description": "Configuration files for nodes used in prompt studio.",
"files": [
"dist"
Expand All @@ -16,10 +16,10 @@
"author": "Pufflig AB",
"license": "MIT",
"dependencies": {
"@pufflig/ps-models": "^0.20.1"
"@pufflig/ps-models": "^0.21.0"
},
"devDependencies": {
"@pufflig/ps-types": "^0.20.1",
"@pufflig/ps-types": "^0.21.0",
"@types/jest": "^29.5.1",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const llmCompletionNodeType = "adapter/llm_completion" as const;

export const llmCompletionConfig: NodeConfig = {
name: "Instruction",
description: "Generate a completion using an LLM.",
description: "Generate a completion using an LLM",
status: "experimental",
tags: ["adapter", "text"],
globals: [],
Expand All @@ -26,19 +26,12 @@ export const llmCompletionConfig: NodeConfig = {
{
id: "completion",
name: "Completion",
description: "Text generated by the LLM.",
description: "Text generated by the LLM",
type: "text",
defaultValue: "",
},
],
inputs: [
{
id: "prompt",
name: "Prompt",
description: "The prompt to send to the LLM.",
type: "text",
defaultValue: "",
},
{
id: "model",
name: "Model",
Expand All @@ -50,5 +43,12 @@ export const llmCompletionConfig: NodeConfig = {
parameters: {},
},
},
{
id: "prompt",
name: "Prompt",
description: "The prompt to send to the LLM",
type: "text",
defaultValue: "",
},
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { chat_models, completion_models, default_completion_model } from "@pufflig/ps-models";
import { NodeConfig } from "@pufflig/ps-types";

export const documentCheckNodeType = "modifier/document_check" as const;

export const documentCheck: NodeConfig = {
name: "Document Check",
description: "Run a checklist or extract information from a document.",
tags: ["modifier", "document", "text"],
status: "stable",
execution: {
inputs: [
{
id: "exec:input",
},
],
outputs: [
{
id: "exec:output",
name: "Completed",
},
],
},
outputs: [
{
id: "list",
name: "List",
description: "A list, checklist or other information about the document",
type: "text",
defaultValue: "",
},
],
inputs: [
{
id: "model",
name: "Model",
description: "The model to use",
type: "model",
definition: { ...completion_models, ...chat_models },
defaultValue: {
modelId: default_completion_model,
parameters: {},
},
},
{
id: "prompt",
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`,
},
{
id: "table",
name: "Table",
description: "The list, table or checklist to parse the document with.",
type: "text",
defaultValue: "",
},
{
id: "document",
name: "Document",
description: "Document to be processed",
type: "text",
defaultValue: "",
},
],
};
3 changes: 3 additions & 0 deletions packages/@pufflig/ps-nodes-config/src/modifiers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { addMessage, addMessageNodeType } from "./add_message/add_message";
import { addText, addTextNodeType } from "./add_text/add_text";
import { documentCheck, documentCheckNodeType } from "./document_check/document_check";
import { parseDocument, parseDocumentNodeType } from "./parse_document/parse_document";
import { splitText, splitTextNodeType } from "./split_text/split_text";
import { templateChat, templateChatNodeType } from "./template/template_chat";
Expand All @@ -12,6 +13,7 @@ export const modifierNodes = {
[splitTextNodeType]: splitText,
[templateChatNodeType]: templateChat,
[templateTextNodeType]: templateText,
[documentCheckNodeType]: documentCheck,
};

export const modifierNodeTypes = {
Expand All @@ -21,4 +23,5 @@ export const modifierNodeTypes = {
splitTextNodeType,
templateChatNodeType,
templateTextNodeType,
documentCheckNodeType,
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const parseDocument: NodeConfig = {
name: "Parse Document",
description: "Run a prompt over a document",
tags: ["modifier", "document", "text"],
status: "experimental",
status: "deprecated",
execution: {
inputs: [
{
Expand Down
10 changes: 5 additions & 5 deletions packages/@pufflig/ps-nodes/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@pufflig/ps-nodes",
"private": false,
"version": "0.20.1",
"version": "0.21.0",
"description": "Collection of nodes used in Prompt Studio",
"files": [
"dist"
Expand All @@ -17,7 +17,7 @@
"author": "Pufflig AB",
"license": "MIT",
"devDependencies": {
"@pufflig/ps-types": "^0.20.1",
"@pufflig/ps-types": "^0.21.0",
"@types/jest": "^29.5.1",
"@types/lodash": "^4.14.196",
"@types/mustache": "^4.2.2",
Expand All @@ -33,9 +33,9 @@
},
"dependencies": {
"@dqbd/tiktoken": "^1.0.7",
"@pufflig/ps-models": "^0.20.1",
"@pufflig/ps-nodes-config": "^0.20.1",
"@pufflig/ps-sdk": "^0.20.1",
"@pufflig/ps-models": "^0.21.0",
"@pufflig/ps-nodes-config": "^0.21.0",
"@pufflig/ps-sdk": "^0.21.0",
"axios": "^1.5.0",
"langchain": "^0.0.160",
"lodash": "^4.17.21",
Expand Down
42 changes: 21 additions & 21 deletions packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ test("getInputDefinition - no variables", () => {
});
expect(variables).toMatchInlineSnapshot(`
[
{
"defaultValue": "summarize {{longText}}",
"description": "The prompt to send to the LLM.",
"id": "prompt",
"name": "Prompt",
"type": "text",
},
{
"defaultValue": {
"modelId": "gpt-3.5-turbo-instruct",
Expand Down Expand Up @@ -403,6 +396,13 @@ test("getInputDefinition - no variables", () => {
"name": "Model",
"type": "model",
},
{
"defaultValue": "summarize {{longText}}",
"description": "The prompt to send to the LLM",
"id": "prompt",
"name": "Prompt",
"type": "text",
},
{
"defaultValue": "",
"description": "",
Expand All @@ -425,13 +425,6 @@ test("getInputDefinition - if you pass a template and a variable, take value of
});
expect(variables).toMatchInlineSnapshot(`
[
{
"defaultValue": "summarize {{longText}}",
"description": "The prompt to send to the LLM.",
"id": "prompt",
"name": "Prompt",
"type": "text",
},
{
"defaultValue": {
"modelId": "gpt-3.5-turbo-instruct",
Expand Down Expand Up @@ -766,6 +759,13 @@ test("getInputDefinition - if you pass a template and a variable, take value of
"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": "",
Expand All @@ -788,13 +788,6 @@ test("getInputDefinition - ignores non existing variables", () => {
});
expect(variables).toMatchInlineSnapshot(`
[
{
"defaultValue": "summarize {{longText}}",
"description": "The prompt to send to the LLM.",
"id": "prompt",
"name": "Prompt",
"type": "text",
},
{
"defaultValue": {
"modelId": "gpt-3.5-turbo-instruct",
Expand Down Expand Up @@ -1129,6 +1122,13 @@ test("getInputDefinition - ignores non existing variables", () => {
"name": "Model",
"type": "model",
},
{
"defaultValue": "summarize {{longText}}",
"description": "The prompt to send to the LLM",
"id": "prompt",
"name": "Prompt",
"type": "text",
},
{
"defaultValue": "",
"description": "",
Expand Down
7 changes: 5 additions & 2 deletions packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createCompletion } from "@pufflig/ps-sdk";
import { Execute, GetInputDefinition, ModelValue, Node, Param } from "@pufflig/ps-types";
import { getPromptStudioKey } from "../../utils/getPromptStudioKey";
import { extractVariables } from "../../utils/extractVariables";
import Mustache from "mustache";

export interface LLMCompletionInput {
prompt: string;
Expand All @@ -15,14 +16,16 @@ export interface LLMCompletionOutput {
}

export const execute: Execute<LLMCompletionInput, LLMCompletionOutput> = async (input, options = {}) => {
const { prompt, model } = input;
const { prompt, model, ...variables } = input;
const { modelId, parameters } = model;
const { globals } = options;

const renderedTemplate = Mustache.render(prompt, variables);

const result = await createCompletion({
apiKey: getPromptStudioKey(globals || {}),
modelId,
prompt,
prompt: renderedTemplate,
parameters,
config: globals,
options: {
Expand Down
Loading