Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ local-dev-toolshed.log
local-dev-shell.log
tools/ralph/logs/
tools/ralph/smoketest/
.worktrees
28 changes: 28 additions & 0 deletions packages/patterns/note.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
Default,
derive,
handler,
llm,
NAME,
navigateTo,
Opaque,
OpaqueRef,
patternTool,
recipe,
str,
UI,
wish,
} from "commontools";
Expand All @@ -27,6 +29,7 @@ type Output = {
/** The content of the note */
content: Default<string, "">;
grep: OpaqueRef<{ query: string }>;
translate: OpaqueRef<{ language: string }>;
editContent: OpaqueRef<{ detail: { value: string } }>;
};

Expand Down Expand Up @@ -164,6 +167,31 @@ const Note = recipe<Input, Output>(
},
{ content },
),
translate: patternTool(
(
{ language, content }: {
language: string;
content: string;
},
) => {
const result = llm({
system: str`Translate the content to ${language}.`,
messages: derive(content, (c) => [
{
role: "user",
content: c,
},
]),
});

return derive(result, ({ pending, result }) => {
if (pending) return undefined;
if (result == null) return "Error occured";
return result;
});
},
{ content },
),
editContent: handleEditContent({ content }),
};
},
Expand Down
7 changes: 5 additions & 2 deletions packages/runner/src/builtins/llm-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ async function invokeToolCall(
const cancel = result.sink((r) => {
r !== undefined && resolve(r);
});
const resultValue = await promise;
let resultValue = await promise;
cancel();

if (pattern) {
Expand All @@ -842,7 +842,10 @@ async function invokeToolCall(
await runtime.idle(); // maybe pointless
}

return { type: "json", value: resultValue ?? "OK" }; // if there was no return value, just tell the LLM it worked
// Prevent links being returned
resultValue = JSON.parse(JSON.stringify(resultValue ?? "OK"));

return { type: "json", value: resultValue };
}

/**
Expand Down