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
2 changes: 2 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
deno = "2.5.2"
19 changes: 19 additions & 0 deletions packages/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,20 @@ export interface BuiltInGenerateObjectParams {
metadata?: Record<string, string | undefined | object>;
}

export interface BuiltInGenerateTextParams {
prompt: string;
system?: string;
model?: string;
maxTokens?: number;
}

export interface BuiltInGenerateTextState {
pending: boolean;
result?: string;
partial?: string;
requestHash?: string;
}

export interface BuiltInCompileAndRunParams<T> {
files: Array<{ name: string; contents: string }>;
main: string;
Expand Down Expand Up @@ -883,6 +897,10 @@ export type GenerateObjectFunction = <T = any>(
params: Opaque<BuiltInGenerateObjectParams>,
) => OpaqueRef<BuiltInLLMGenerateObjectState<T>>;

export type GenerateTextFunction = (
params: Opaque<BuiltInGenerateTextParams>,
) => OpaqueRef<BuiltInGenerateTextState>;

export type FetchOptions = {
body?: JSONValue;
headers?: Record<string, string>;
Expand Down Expand Up @@ -989,6 +1007,7 @@ export declare const ifElse: IfElseFunction;
export declare const llm: LLMFunction;
export declare const llmDialog: LLMDialogFunction;
export declare const generateObject: GenerateObjectFunction;
export declare const generateText: GenerateTextFunction;
export declare const fetchData: FetchDataFunction;
export declare const streamData: StreamDataFunction;
export declare const compileAndRun: CompileAndRunFunction;
Expand Down
13 changes: 3 additions & 10 deletions packages/patterns/note.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/// <cts-enable />
import {
type BuiltInLLMMessage,
type Cell,
cell,
type Default,
derive,
generateText,
handler,
llm,
NAME,
navigateTo,
type Opaque,
Expand Down Expand Up @@ -175,15 +174,9 @@ const Note = recipe<Input, Output>(
content: string;
},
) => {
const result = llm({
const result = generateText({
system: str`Translate the content to ${language}.`,
messages: derive(content, (c) =>
[
{
role: "user",
content: c,
},
] satisfies BuiltInLLMMessage[]),
prompt: str`<to_translate>${content}</to_translate>`,
});

return derive(result, ({ pending, result }) => {
Expand Down
9 changes: 9 additions & 0 deletions packages/runner/src/builder/built-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import type {
BuiltInCompileAndRunParams,
BuiltInCompileAndRunState,
BuiltInGenerateObjectParams,
BuiltInGenerateTextParams,
BuiltInGenerateTextState,
BuiltInLLMGenerateObjectState,
BuiltInLLMParams,
BuiltInLLMState,
Expand Down Expand Up @@ -50,6 +52,13 @@ export const generateObject = createNodeFactory({
params: Opaque<BuiltInGenerateObjectParams>,
) => OpaqueRef<BuiltInLLMGenerateObjectState<T>>;

export const generateText = createNodeFactory({
type: "ref",
implementation: "generateText",
}) as (
params: Opaque<BuiltInGenerateTextParams>,
) => OpaqueRef<BuiltInGenerateTextState>;

export const fetchData = createNodeFactory({
type: "ref",
implementation: "fetchData",
Expand Down
2 changes: 2 additions & 0 deletions packages/runner/src/builder/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
compileAndRun,
fetchData,
generateObject,
generateText,
ifElse,
llm,
llmDialog,
Expand Down Expand Up @@ -117,6 +118,7 @@ export const createBuilder = (
llm,
llmDialog,
generateObject,
generateText,
fetchData,
streamData,
compileAndRun,
Expand Down
2 changes: 2 additions & 0 deletions packages/runner/src/builder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
DeriveFunction,
FetchDataFunction,
GenerateObjectFunction,
GenerateTextFunction,
GetRecipeEnvironmentFunction,
HandlerFunction,
HFunction,
Expand Down Expand Up @@ -282,6 +283,7 @@ export interface BuilderFunctionsAndConstants {
llm: LLMFunction;
llmDialog: LLMDialogFunction;
generateObject: GenerateObjectFunction;
generateText: GenerateTextFunction;
fetchData: FetchDataFunction;
streamData: StreamDataFunction;
compileAndRun: CompileAndRunFunction;
Expand Down
16 changes: 14 additions & 2 deletions packages/runner/src/builtins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { raw } from "../module.ts";
import { map } from "./map.ts";
import { fetchData } from "./fetch-data.ts";
import { streamData } from "./stream-data.ts";
import { generateObject, llm } from "./llm.ts";
import { generateObject, generateText, llm } from "./llm.ts";
import { ifElse } from "./if-else.ts";
import type { IRuntime } from "../runtime.ts";
import { compileAndRun } from "./compile-and-run.ts";
import { navigateTo } from "./navigate-to.ts";
import { wish } from "./wish.ts";
import type { Cell } from "../cell.ts";
import type { BuiltInGenerateObjectParams } from "@commontools/api";
import type {
BuiltInGenerateObjectParams,
BuiltInGenerateTextParams,
} from "@commontools/api";
import { llmDialog } from "./llm-dialog.ts";

/**
Expand All @@ -34,6 +37,15 @@ export function registerBuiltins(runtime: IRuntime) {
requestHash: Cell<string | undefined>;
}>(generateObject),
);
moduleRegistry.addModuleByRef(
"generateText",
raw<BuiltInGenerateTextParams, {
pending: Cell<boolean>;
result: Cell<string | undefined>;
partial: Cell<string | undefined>;
requestHash: Cell<string | undefined>;
}>(generateText),
);
moduleRegistry.addModuleByRef("navigateTo", raw(navigateTo));
moduleRegistry.addModuleByRef("wish", raw(wish));
}
Loading