Skip to content

Commit 282cb9e

Browse files
authored
Merge pull request #87 from pufflyai/86-add-document-check-node
add document check node, update variable parsing in llm completion node
2 parents ea8cd88 + 8d811dc commit 282cb9e

File tree

18 files changed

+313
-51
lines changed

18 files changed

+313
-51
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
3-
"version": "0.20.1"
3+
"version": "0.21.0"
44
}

packages/@pufflig/ps-chains/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pufflig/ps-chains",
3-
"version": "0.20.1",
3+
"version": "0.21.0",
44
"license": "MIT",
55
"main": "./dist/ps-chains.umd.js",
66
"module": "./dist/ps-chains.es.js",
@@ -16,7 +16,7 @@
1616
"test": "jest"
1717
},
1818
"devDependencies": {
19-
"@pufflig/ps-types": "^0.20.1",
19+
"@pufflig/ps-types": "^0.21.0",
2020
"@types/react-dom": "^18.2.7",
2121
"immer": "^10.0.2",
2222
"prop-types": "^15.8.1",

packages/@pufflig/ps-models/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pufflig/ps-models",
33
"private": false,
4-
"version": "0.20.1",
4+
"version": "0.21.0",
55
"description": "Configuration of models used in Prompt Studio",
66
"files": [
77
"dist"
@@ -16,7 +16,7 @@
1616
"author": "Pufflig AB",
1717
"license": "MIT",
1818
"devDependencies": {
19-
"@pufflig/ps-types": "^0.20.1",
19+
"@pufflig/ps-types": "^0.21.0",
2020
"typescript": "^5.1.6",
2121
"vite": "^4.3.9",
2222
"vite-plugin-dts": "^2.3.0"

packages/@pufflig/ps-nodes-config/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pufflig/ps-nodes-config",
33
"private": false,
4-
"version": "0.20.1",
4+
"version": "0.21.0",
55
"description": "Configuration files for nodes used in prompt studio.",
66
"files": [
77
"dist"
@@ -16,10 +16,10 @@
1616
"author": "Pufflig AB",
1717
"license": "MIT",
1818
"dependencies": {
19-
"@pufflig/ps-models": "^0.20.1"
19+
"@pufflig/ps-models": "^0.21.0"
2020
},
2121
"devDependencies": {
22-
"@pufflig/ps-types": "^0.20.1",
22+
"@pufflig/ps-types": "^0.21.0",
2323
"@types/jest": "^29.5.1",
2424
"jest": "^29.5.0",
2525
"ts-jest": "^29.1.0",

packages/@pufflig/ps-nodes-config/src/adapters/llm/llm_completion.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const llmCompletionNodeType = "adapter/llm_completion" as const;
55

66
export const llmCompletionConfig: NodeConfig = {
77
name: "Instruction",
8-
description: "Generate a completion using an LLM.",
8+
description: "Generate a completion using an LLM",
99
status: "experimental",
1010
tags: ["adapter", "text"],
1111
globals: [],
@@ -26,19 +26,12 @@ export const llmCompletionConfig: NodeConfig = {
2626
{
2727
id: "completion",
2828
name: "Completion",
29-
description: "Text generated by the LLM.",
29+
description: "Text generated by the LLM",
3030
type: "text",
3131
defaultValue: "",
3232
},
3333
],
3434
inputs: [
35-
{
36-
id: "prompt",
37-
name: "Prompt",
38-
description: "The prompt to send to the LLM.",
39-
type: "text",
40-
defaultValue: "",
41-
},
4235
{
4336
id: "model",
4437
name: "Model",
@@ -50,5 +43,12 @@ export const llmCompletionConfig: NodeConfig = {
5043
parameters: {},
5144
},
5245
},
46+
{
47+
id: "prompt",
48+
name: "Prompt",
49+
description: "The prompt to send to the LLM",
50+
type: "text",
51+
defaultValue: "",
52+
},
5353
],
5454
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { chat_models, completion_models, default_completion_model } from "@pufflig/ps-models";
2+
import { NodeConfig } from "@pufflig/ps-types";
3+
4+
export const documentCheckNodeType = "modifier/document_check" as const;
5+
6+
export const documentCheck: NodeConfig = {
7+
name: "Document Check",
8+
description: "Run a checklist or extract information from a document.",
9+
tags: ["modifier", "document", "text"],
10+
status: "stable",
11+
execution: {
12+
inputs: [
13+
{
14+
id: "exec:input",
15+
},
16+
],
17+
outputs: [
18+
{
19+
id: "exec:output",
20+
name: "Completed",
21+
},
22+
],
23+
},
24+
outputs: [
25+
{
26+
id: "list",
27+
name: "List",
28+
description: "A list, checklist or other information about the document",
29+
type: "text",
30+
defaultValue: "",
31+
},
32+
],
33+
inputs: [
34+
{
35+
id: "model",
36+
name: "Model",
37+
description: "The model to use",
38+
type: "model",
39+
definition: { ...completion_models, ...chat_models },
40+
defaultValue: {
41+
modelId: default_completion_model,
42+
parameters: {},
43+
},
44+
},
45+
{
46+
id: "prompt",
47+
name: "Prompt",
48+
description: "Prompt to check the document with",
49+
type: "text",
50+
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`,
51+
},
52+
{
53+
id: "table",
54+
name: "Table",
55+
description: "The list, table or checklist to parse the document with.",
56+
type: "text",
57+
defaultValue: "",
58+
},
59+
{
60+
id: "document",
61+
name: "Document",
62+
description: "Document to be processed",
63+
type: "text",
64+
defaultValue: "",
65+
},
66+
],
67+
};

packages/@pufflig/ps-nodes-config/src/modifiers/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { addMessage, addMessageNodeType } from "./add_message/add_message";
22
import { addText, addTextNodeType } from "./add_text/add_text";
3+
import { documentCheck, documentCheckNodeType } from "./document_check/document_check";
34
import { parseDocument, parseDocumentNodeType } from "./parse_document/parse_document";
45
import { splitText, splitTextNodeType } from "./split_text/split_text";
56
import { templateChat, templateChatNodeType } from "./template/template_chat";
@@ -12,6 +13,7 @@ export const modifierNodes = {
1213
[splitTextNodeType]: splitText,
1314
[templateChatNodeType]: templateChat,
1415
[templateTextNodeType]: templateText,
16+
[documentCheckNodeType]: documentCheck,
1517
};
1618

1719
export const modifierNodeTypes = {
@@ -21,4 +23,5 @@ export const modifierNodeTypes = {
2123
splitTextNodeType,
2224
templateChatNodeType,
2325
templateTextNodeType,
26+
documentCheckNodeType,
2427
};

packages/@pufflig/ps-nodes-config/src/modifiers/parse_document/parse_document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const parseDocument: NodeConfig = {
66
name: "Parse Document",
77
description: "Run a prompt over a document",
88
tags: ["modifier", "document", "text"],
9-
status: "experimental",
9+
status: "deprecated",
1010
execution: {
1111
inputs: [
1212
{

packages/@pufflig/ps-nodes/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pufflig/ps-nodes",
33
"private": false,
4-
"version": "0.20.1",
4+
"version": "0.21.0",
55
"description": "Collection of nodes used in Prompt Studio",
66
"files": [
77
"dist"
@@ -17,7 +17,7 @@
1717
"author": "Pufflig AB",
1818
"license": "MIT",
1919
"devDependencies": {
20-
"@pufflig/ps-types": "^0.20.1",
20+
"@pufflig/ps-types": "^0.21.0",
2121
"@types/jest": "^29.5.1",
2222
"@types/lodash": "^4.14.196",
2323
"@types/mustache": "^4.2.2",
@@ -33,9 +33,9 @@
3333
},
3434
"dependencies": {
3535
"@dqbd/tiktoken": "^1.0.7",
36-
"@pufflig/ps-models": "^0.20.1",
37-
"@pufflig/ps-nodes-config": "^0.20.1",
38-
"@pufflig/ps-sdk": "^0.20.1",
36+
"@pufflig/ps-models": "^0.21.0",
37+
"@pufflig/ps-nodes-config": "^0.21.0",
38+
"@pufflig/ps-sdk": "^0.21.0",
3939
"axios": "^1.5.0",
4040
"langchain": "^0.0.160",
4141
"lodash": "^4.17.21",

packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ test("getInputDefinition - no variables", () => {
6262
});
6363
expect(variables).toMatchInlineSnapshot(`
6464
[
65-
{
66-
"defaultValue": "summarize {{longText}}",
67-
"description": "The prompt to send to the LLM.",
68-
"id": "prompt",
69-
"name": "Prompt",
70-
"type": "text",
71-
},
7265
{
7366
"defaultValue": {
7467
"modelId": "gpt-3.5-turbo-instruct",
@@ -403,6 +396,13 @@ test("getInputDefinition - no variables", () => {
403396
"name": "Model",
404397
"type": "model",
405398
},
399+
{
400+
"defaultValue": "summarize {{longText}}",
401+
"description": "The prompt to send to the LLM",
402+
"id": "prompt",
403+
"name": "Prompt",
404+
"type": "text",
405+
},
406406
{
407407
"defaultValue": "",
408408
"description": "",
@@ -425,13 +425,6 @@ test("getInputDefinition - if you pass a template and a variable, take value of
425425
});
426426
expect(variables).toMatchInlineSnapshot(`
427427
[
428-
{
429-
"defaultValue": "summarize {{longText}}",
430-
"description": "The prompt to send to the LLM.",
431-
"id": "prompt",
432-
"name": "Prompt",
433-
"type": "text",
434-
},
435428
{
436429
"defaultValue": {
437430
"modelId": "gpt-3.5-turbo-instruct",
@@ -766,6 +759,13 @@ test("getInputDefinition - if you pass a template and a variable, take value of
766759
"name": "Model",
767760
"type": "model",
768761
},
762+
{
763+
"defaultValue": "summarize {{longText}}",
764+
"description": "The prompt to send to the LLM",
765+
"id": "prompt",
766+
"name": "Prompt",
767+
"type": "text",
768+
},
769769
{
770770
"defaultValue": "some long text",
771771
"description": "",
@@ -788,13 +788,6 @@ test("getInputDefinition - ignores non existing variables", () => {
788788
});
789789
expect(variables).toMatchInlineSnapshot(`
790790
[
791-
{
792-
"defaultValue": "summarize {{longText}}",
793-
"description": "The prompt to send to the LLM.",
794-
"id": "prompt",
795-
"name": "Prompt",
796-
"type": "text",
797-
},
798791
{
799792
"defaultValue": {
800793
"modelId": "gpt-3.5-turbo-instruct",
@@ -1129,6 +1122,13 @@ test("getInputDefinition - ignores non existing variables", () => {
11291122
"name": "Model",
11301123
"type": "model",
11311124
},
1125+
{
1126+
"defaultValue": "summarize {{longText}}",
1127+
"description": "The prompt to send to the LLM",
1128+
"id": "prompt",
1129+
"name": "Prompt",
1130+
"type": "text",
1131+
},
11321132
{
11331133
"defaultValue": "",
11341134
"description": "",

packages/@pufflig/ps-nodes/src/adapters/llm/llm_completion.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createCompletion } from "@pufflig/ps-sdk";
33
import { Execute, GetInputDefinition, ModelValue, Node, Param } from "@pufflig/ps-types";
44
import { getPromptStudioKey } from "../../utils/getPromptStudioKey";
55
import { extractVariables } from "../../utils/extractVariables";
6+
import Mustache from "mustache";
67

78
export interface LLMCompletionInput {
89
prompt: string;
@@ -15,14 +16,16 @@ export interface LLMCompletionOutput {
1516
}
1617

1718
export const execute: Execute<LLMCompletionInput, LLMCompletionOutput> = async (input, options = {}) => {
18-
const { prompt, model } = input;
19+
const { prompt, model, ...variables } = input;
1920
const { modelId, parameters } = model;
2021
const { globals } = options;
2122

23+
const renderedTemplate = Mustache.render(prompt, variables);
24+
2225
const result = await createCompletion({
2326
apiKey: getPromptStudioKey(globals || {}),
2427
modelId,
25-
prompt,
28+
prompt: renderedTemplate,
2629
parameters,
2730
config: globals,
2831
options: {

0 commit comments

Comments
 (0)