From f05388bf740c61ab076dbb51192725009d7f8cac Mon Sep 17 00:00:00 2001 From: kentaro-m Date: Mon, 13 Jan 2025 22:26:22 +0900 Subject: [PATCH 1/5] fix: remove requirement from text generation prompt --- packages/lib/prompts.test.ts | 20 +------------------- packages/lib/prompts.ts | 26 +++++++------------------- 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/packages/lib/prompts.test.ts b/packages/lib/prompts.test.ts index 6240aff1..41006cde 100644 --- a/packages/lib/prompts.test.ts +++ b/packages/lib/prompts.test.ts @@ -5,7 +5,7 @@ import { textGenerationPrompt } from "./prompts"; describe("textGenerationPrompt template", () => { const template = HandleBars.compile(textGenerationPrompt); - test("should render basic instruction without sources or requirement", () => { + test("should render basic instruction without sources", () => { const result = template({ instruction: "Write a summary about cats.", }); @@ -13,22 +13,6 @@ describe("textGenerationPrompt template", () => { expect(result).toContain( "\nWrite a summary about cats.\n", ); - expect(result).not.toContain(""); - expect(result).not.toContain(""); - }); - - test("should render instruction with requirement", () => { - const result = template({ - instruction: "Write a summary about cats.", - requirement: "Must include information about different breeds.", - }); - - expect(result).toContain( - "\nWrite a summary about cats.\n", - ); - expect(result).toContain( - "\nMust include information about different breeds.\n", - ); expect(result).not.toContain(""); }); @@ -138,7 +122,6 @@ describe("textGenerationPrompt template", () => { test("should render all components together", () => { const result = template({ instruction: "Write a summary about cats.", - requirement: "Must include information about different breeds.", sources: [ { type: "text", @@ -155,7 +138,6 @@ describe("textGenerationPrompt template", () => { }); expect(result).toContain(""); - expect(result).toContain(""); expect(result).toContain(""); expect(result).toContain(''); expect(result).toContain(''); diff --git a/packages/lib/prompts.ts b/packages/lib/prompts.ts index 8cfb998a..0da16cfd 100644 --- a/packages/lib/prompts.ts +++ b/packages/lib/prompts.ts @@ -1,7 +1,7 @@ import HandleBars from "handlebars"; HandleBars.registerHelper("eq", (arg1, arg2) => arg1 === arg2); -export const textGenerationPrompt = `You are tasked with generating text based on specific instructions, requirements, and sources provided by the user. Follow these steps carefully: +export const textGenerationPrompt = `You are tasked with generating text based on specific instructions and sources provided by the user. Follow these steps carefully: 1. Read and analyze the following inputs: @@ -9,12 +9,6 @@ export const textGenerationPrompt = `You are tasked with generating text based o {{instruction}} -{{#if requirement}} - -{{requirement}} - -{{/if}} - {{#if sources}} {{#each sources}} @@ -40,30 +34,24 @@ export const textGenerationPrompt = `You are tasked with generating text based o - Identify the main points and objectives of the task. - If the instruction is unclear or ambiguous, interpret it to the best of your ability. -3. Incorporate the requirement: - - Review the requirement thoroughly. - - Ensure that your generated text fully satisfies this requirement. - - If there are multiple requirements, address each one systematically. - -4. Reference the sources: +3. Reference the sources: - Examine the provided sources carefully. - Use information from these sources to support your generated text. - When referencing a source, cite it appropriately within your text. - If no specific citation format is mentioned in the instruction, use a simple (Source X) format, where X is the number or identifier of the source. -5. Generate your response: - - Combine the instruction, requirement, and sources to create your text. +4. Generate your response: + - Combine the instruction and sources to create your text. - Ensure that your writing style and tone match what is requested in the instruction. - Be concise yet comprehensive in addressing all aspects of the task. -6. Review and refine: +5. Review and refine: - After generating your text, review it to ensure it fully addresses the instruction. - - Check that all requirements are met. - Verify that sources are appropriately referenced and cited. -7. Format your output: +6. Format your output: - Present your final generated text within tags. - If the instruction asks for specific sections or formatting, include appropriate subtags within your response. -Remember to adhere strictly to the given instruction, fulfill all requirements, and make proper use of the provided sources. Your goal is to produce a well-crafted, accurate, and relevant piece of text that fully satisfies the user's request. +Remember to adhere strictly to the given instruction and make proper use of the provided sources. Your goal is to produce a well-crafted, accurate, and relevant piece of text that fully satisfies the user's request. `; From 0b52d932e618abcaca7495b095d9962ca696ed70 Mon Sep 17 00:00:00 2001 From: kentaro-m Date: Mon, 13 Jan 2025 22:27:42 +0900 Subject: [PATCH 2/5] fix: remove the Requirement field from the Text Generator node --- packages/components/editor.tsx | 5 - packages/components/node.tsx | 1 - packages/components/properties-panel.tsx | 155 ----------------------- packages/lib/execution.ts | 31 ----- packages/types.ts | 1 - 5 files changed, 193 deletions(-) diff --git a/packages/components/editor.tsx b/packages/components/editor.tsx index c6360e37..092c492b 100644 --- a/packages/components/editor.tsx +++ b/packages/components/editor.tsx @@ -178,11 +178,6 @@ export function Editor() { ...dependentNode, content: { ...dependentNode.content, - requirement: handleIds.includes( - dependentNode.content.requirement?.id, - ) - ? undefined - : dependentNode.content.requirement, sources: dependentNode.content.sources.filter( (source) => !handleIds.includes(source.id), ), diff --git a/packages/components/node.tsx b/packages/components/node.tsx index eb37afb7..829a6113 100644 --- a/packages/components/node.tsx +++ b/packages/components/node.tsx @@ -211,7 +211,6 @@ export function Node({ const targetHandles = useMemo(() => { if (data.node.content.type === "textGeneration") { return [ - data.node.content.requirement, ...data.node.content.sources, ].filter((item) => item !== undefined); } diff --git a/packages/components/properties-panel.tsx b/packages/components/properties-panel.tsx index 88896700..1b4ade48 100644 --- a/packages/components/properties-panel.tsx +++ b/packages/components/properties-panel.tsx @@ -39,14 +39,12 @@ import { useExecution } from "../contexts/execution"; import { useArtifact, useGraph, - useNode, useSelectedNode, } from "../contexts/graph"; import { usePropertiesPanel } from "../contexts/properties-panel"; import { useToast } from "../contexts/toast"; import { textGenerationPrompt } from "../lib/prompts"; import { - createArtifactId, createConnectionId, createFileId, createNodeHandleId, @@ -62,13 +60,11 @@ import { import type { FileContent, FileData, - FileId, FilesContent, Node, NodeHandle, NodeId, Text, - TextArtifactObject, TextContent, TextGenerateActionContent, } from "../types"; @@ -354,71 +350,6 @@ export function PropertiesPanel() { }, }); }} - onRequirementConnect={(sourceNode) => { - const requirement: NodeHandle = { - id: createNodeHandleId(), - label: "Requirement", - }; - dispatch([ - { - type: "updateNode", - input: { - nodeId: selectedNode.id, - node: { - ...selectedNode, - content: { - ...selectedNode.content, - requirement, - }, - }, - }, - }, - { - type: "addConnection", - input: { - connection: { - id: createConnectionId(), - sourceNodeId: sourceNode.id, - sourceNodeType: sourceNode.type, - targetNodeId: selectedNode.id, - targetNodeType: selectedNode.type, - targetNodeHandleId: requirement.id, - }, - }, - }, - ]); - }} - onRequirementRemove={(sourceNode) => { - const connection = graph.connections.find( - (connection) => - connection.targetNodeId === selectedNode.id && - connection.sourceNodeId === sourceNode.id, - ); - if (connection === undefined) { - return; - } - dispatch([ - { - type: "removeConnection", - input: { - connectionId: connection.id, - }, - }, - { - type: "updateNode", - input: { - nodeId: selectedNode.id, - node: { - ...selectedNode, - content: { - ...selectedNode.content, - requirement: undefined, - }, - }, - }, - }, - ]); - }} onSourceConnect={(sourceNode) => { const source: NodeHandle = { id: createNodeHandleId(), @@ -799,15 +730,11 @@ function SystemPromptTextarea({ function TabsContentPrompt({ content, onContentChange, - onRequirementConnect, - onRequirementRemove, onSourceConnect, onSourceRemove, }: { content: TextGenerateActionContent; onContentChange?: (content: TextGenerateActionContent) => void; - onRequirementConnect?: (sourceNode: Node) => void; - onRequirementRemove?: (sourceNode: Node) => void; onSourceConnect?: (sourceNode: Node) => void; onSourceRemove?: (sourceNode: Node) => void; }) { @@ -824,9 +751,6 @@ function TabsContentPrompt({ const connectableFileNodes = nodes.filter( (node) => node.content.type === "files", ); - const requirementNode = useNode({ - targetNodeHandleId: content.requirement?.id, - }); const sourceNodes = useMemo( () => content.sources @@ -931,86 +855,7 @@ function TabsContentPrompt({ - -
- - {requirementNode === null ? ( -
-
Not selected
- { - onRequirementConnect?.(node); - }} - /> -
- ) : ( - - {requirementNode.content.type === "text" && ( -
- {requirementNode.content.text} -
- )} -
- } - > -
-
-

- {requirementNode.name} -

-
- -
- - )} - {/*
- -
*/} - -
- sources.filter((source) => source !== null).flat()); } -function resolveRequirement( - requirement: NodeHandle | null, - context: ExecutionContext, -) { - if (requirement === null) { - return null; - } - const node = nodeResolver(requirement.id, context); - switch (node?.content.type) { - case "text": - return node.content.text; - case "textGeneration": { - const generatedArtifact = artifactResolver(node.id, context); - if ( - generatedArtifact === null || - generatedArtifact.type === "generatedArtifact" - ) { - return null; - } - return generatedArtifact.object.content; - } - default: - return null; - } -} - interface ExecutionContext { agentId: AgentId; executionId: ExecutionId; @@ -294,17 +268,12 @@ async function performFlowExecution( switch (node.content.type) { case "textGeneration": { const actionSources = await resolveSources(node.content.sources, context); - const requirement = resolveRequirement( - node.content.requirement ?? null, - context, - ); const model = resolveLanguageModel(node.content.llm); const promptTemplate = HandleBars.compile( node.content.system ?? textGenerationPrompt, ); const prompt = promptTemplate({ instruction: node.content.instruction, - requirement, sources: actionSources, }); const topP = node.content.topP; diff --git a/packages/types.ts b/packages/types.ts index b57c07bc..7cd235c0 100644 --- a/packages/types.ts +++ b/packages/types.ts @@ -27,7 +27,6 @@ export interface TextGenerateActionContent extends ActionContentBase { temperature: number; topP: number; instruction: string; - requirement?: NodeHandle; system?: string; sources: NodeHandle[]; } From 372fcdbb1249ee02ba46d38abb39c56c67ac1207 Mon Sep 17 00:00:00 2001 From: kentaro-m Date: Mon, 13 Jan 2025 22:28:20 +0900 Subject: [PATCH 3/5] fix: remove the Requirement field from the Text Generator node (v2) --- .../components/panel/text-generator.tsx | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/app/(playground)/p/[agentId]/prev/beta-proto/giselle-node/components/panel/text-generator.tsx b/app/(playground)/p/[agentId]/prev/beta-proto/giselle-node/components/panel/text-generator.tsx index d2fd8f92..b66206de 100644 --- a/app/(playground)/p/[agentId]/prev/beta-proto/giselle-node/components/panel/text-generator.tsx +++ b/app/(playground)/p/[agentId]/prev/beta-proto/giselle-node/components/panel/text-generator.tsx @@ -117,20 +117,6 @@ export const TextGeneratorPropertyPanel: FC< />
-
-
-
- Requirements -
- -
-
-
From 361cd9ae55f8a36b4f57f49951ea305ba8000e68 Mon Sep 17 00:00:00 2001 From: kentaro-m Date: Mon, 13 Jan 2025 22:41:11 +0900 Subject: [PATCH 4/5] chore: run biome check --- packages/components/node.tsx | 6 +++--- packages/components/properties-panel.tsx | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/components/node.tsx b/packages/components/node.tsx index 829a6113..6f0e975c 100644 --- a/packages/components/node.tsx +++ b/packages/components/node.tsx @@ -210,9 +210,9 @@ export function Node({ }: NodeProps & { preview?: boolean }) { const targetHandles = useMemo(() => { if (data.node.content.type === "textGeneration") { - return [ - ...data.node.content.sources, - ].filter((item) => item !== undefined); + return [...data.node.content.sources].filter( + (item) => item !== undefined, + ); } return []; }, [data.node]); diff --git a/packages/components/properties-panel.tsx b/packages/components/properties-panel.tsx index 1b4ade48..d0950564 100644 --- a/packages/components/properties-panel.tsx +++ b/packages/components/properties-panel.tsx @@ -36,11 +36,7 @@ import { parse, remove } from "../actions"; import { vercelBlobFileFolder } from "../constants"; import { useDeveloperMode } from "../contexts/developer-mode"; import { useExecution } from "../contexts/execution"; -import { - useArtifact, - useGraph, - useSelectedNode, -} from "../contexts/graph"; +import { useArtifact, useGraph, useSelectedNode } from "../contexts/graph"; import { usePropertiesPanel } from "../contexts/properties-panel"; import { useToast } from "../contexts/toast"; import { textGenerationPrompt } from "../lib/prompts"; From 34acbcad7993d2d7eaa8dc166c3886955d237867 Mon Sep 17 00:00:00 2001 From: kentaro-m Date: Mon, 13 Jan 2025 22:59:44 +0900 Subject: [PATCH 5/5] revert: remove variables --- packages/components/properties-panel.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/components/properties-panel.tsx b/packages/components/properties-panel.tsx index d0950564..e7febbd7 100644 --- a/packages/components/properties-panel.tsx +++ b/packages/components/properties-panel.tsx @@ -36,11 +36,17 @@ import { parse, remove } from "../actions"; import { vercelBlobFileFolder } from "../constants"; import { useDeveloperMode } from "../contexts/developer-mode"; import { useExecution } from "../contexts/execution"; -import { useArtifact, useGraph, useSelectedNode } from "../contexts/graph"; +import { + useArtifact, + useGraph, + useNode, + useSelectedNode, +} from "../contexts/graph"; import { usePropertiesPanel } from "../contexts/properties-panel"; import { useToast } from "../contexts/toast"; import { textGenerationPrompt } from "../lib/prompts"; import { + createArtifactId, createConnectionId, createFileId, createNodeHandleId, @@ -56,11 +62,13 @@ import { import type { FileContent, FileData, + FileId, FilesContent, Node, NodeHandle, NodeId, Text, + TextArtifactObject, TextContent, TextGenerateActionContent, } from "../types";