Skip to content
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

Remove the Requirement field from the Text Generator node #307

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,6 @@ export const TextGeneratorPropertyPanel: FC<
/>
</div>
<div className="border-t border-[hsla(222,21%,40%,1)]" />
<div className="grid gap-[8px]">
<div className="flex justify-between">
<div className="font-rosart text-[16px] text-black-30">
Requirements
</div>
<button type="button">
<CirclePlusIcon
size={20}
className="stroke-black-100 fill-black-30"
/>
</button>
</div>
</div>
<div className="border-t border-[hsla(222,21%,40%,1)]" />
<div className="grid gap-[8px]">
<div className="flex justify-between">
<div className="font-rosart text-[16px] text-black-30">
Expand Down
5 changes: 0 additions & 5 deletions packages/components/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down
7 changes: 3 additions & 4 deletions packages/components/node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ export function Node({
}: NodeProps<Node> & { preview?: boolean }) {
const targetHandles = useMemo(() => {
if (data.node.content.type === "textGeneration") {
return [
data.node.content.requirement,
...data.node.content.sources,
].filter((item) => item !== undefined);
return [...data.node.content.sources].filter(
(item) => item !== undefined,
);
}
return [];
}, [data.node]);
Expand Down
151 changes: 0 additions & 151 deletions packages/components/properties-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,71 +354,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(),
Expand Down Expand Up @@ -799,15 +734,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;
}) {
Expand All @@ -824,9 +755,6 @@ function TabsContentPrompt({
const connectableFileNodes = nodes.filter(
(node) => node.content.type === "files",
);
const requirementNode = useNode({
targetNodeHandleId: content.requirement?.id,
});
const sourceNodes = useMemo(
() =>
content.sources
Expand Down Expand Up @@ -931,86 +859,7 @@ function TabsContentPrompt({
</div>
</div>
</PropertiesPanelCollapsible>

<div className="border-t border-[hsla(222,21%,40%,1)]" />
<PropertiesPanelCollapsible
title="Requirement"
glanceLabel={
requirementNode === null ? "Not selected" : requirementNode.name
}
>
{requirementNode === null ? (
<div className="flex items-center gap-[4px]">
<div className="py-[4px] text-[12px] flex-1">Not selected</div>
<NodeDropdown
nodes={[
...connectableTextNodes,
...connectableTextGeneratorNodes,
]}
onValueChange={(node) => {
onRequirementConnect?.(node);
}}
/>
</div>
) : (
<Block
hoverCardContent={
<div className="flex justify-between space-x-4">
{requirementNode.content.type === "text" && (
<div className="line-clamp-5 text-[14px]">
{requirementNode.content.text}
</div>
)}
</div>
}
>
<div className="flex items-center justify-between">
<div className="flex items-center gap-[8px]">
<p className="truncate text-[14px] font-rosart">
{requirementNode.name}
</p>
</div>
<button
type="button"
className="group-hover:block hidden p-[2px] hover:bg-black-70 rounded-[4px]"
onClick={() => {
onRequirementRemove?.(requirementNode);
}}
>
<TrashIcon className="w-[16px] h-[16px] text-black-30" />
</button>
</div>
</Block>
)}
{/* <div className="mb-[4px]">
<Select value={requirementNode?.id}>
<SelectTrigger>
<SelectValue placeholder="Select a requirement" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Text Generator</SelectLabel>
{connectableTextGeneratorNodes.map((node) => (
<SelectItem value={node.id} key={node.id} label={node.name}>
<p>it's a text generator</p>
</SelectItem>
))}
</SelectGroup>
<SelectGroup>
<SelectLabel>Text</SelectLabel>
{connectableTextNodes.map((node) => (
<SelectItem value={node.id} key={node.id} label={node.name}>
<p>{node.content.text}</p>
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
</div> */}
</PropertiesPanelCollapsible>

<div className="border-t border-[hsla(222,21%,40%,1)]" />

<PropertiesPanelCollapsible
title="Sources"
glanceLabel={
Expand Down
31 changes: 0 additions & 31 deletions packages/lib/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,32 +241,6 @@ async function resolveSources(
).then((sources) => 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;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 1 addition & 19 deletions packages/lib/prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,14 @@ 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.",
});

expect(result).toContain(
"<instruction>\nWrite a summary about cats.\n</instruction>",
);
expect(result).not.toContain("<requirement>");
expect(result).not.toContain("<sources>");
});

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(
"<instruction>\nWrite a summary about cats.\n</instruction>",
);
expect(result).toContain(
"<requirement>\nMust include information about different breeds.\n</requirement>",
);
expect(result).not.toContain("<sources>");
});

Expand Down Expand Up @@ -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",
Expand All @@ -155,7 +138,6 @@ describe("textGenerationPrompt template", () => {
});

expect(result).toContain("<instruction>");
expect(result).toContain("<requirement>");
expect(result).toContain("<sources>");
expect(result).toContain('<text id="node1">');
expect(result).toContain('<generated id="node2" title="Cat Care Guide">');
Expand Down
26 changes: 7 additions & 19 deletions packages/lib/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
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:

<instruction>
{{instruction}}
</instruction>

{{#if requirement}}
<requirement>
{{requirement}}
</requirement>
{{/if}}

{{#if sources}}
<sources>
{{#each sources}}
Expand All @@ -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 <response> 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.
`;
1 change: 0 additions & 1 deletion packages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export interface TextGenerateActionContent extends ActionContentBase {
temperature: number;
topP: number;
instruction: string;
requirement?: NodeHandle;
system?: string;
sources: NodeHandle[];
}
Expand Down
Loading