///
import {
BuiltInLLMContent,
Cell,
Default,
derive,
generateText,
handler,
NAME,
recipe,
UI,
} from "commontools";
type LLMTestInput = {
title: Default;
};
type LLMTestResult = {
question: string;
response?: BuiltInLLMContent;
};
const askQuestion = handler<
{ detail: { message: string } },
{ question: Cell }
>((event, { question }) => {
const userQuestion = event.detail?.message?.trim();
if (userQuestion) {
question.set(userQuestion);
}
});
export default recipe(({ title }) => {
const question = Cell.of("");
const llmResponse = generateText({
system:
"You are a helpful assistant. Answer questions clearly and concisely.",
prompt: question,
});
return {
[NAME]: title,
[UI]: (
{title}
{derive(question, (q) =>
q
? (
)
: null)}
{derive(
[llmResponse.pending, llmResponse.result],
([pending, r]) =>
pending
? (
Thinking...
)
: r
? (
)
: null,
)}
),
question,
response: llmResponse.result,
};
});