1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import process from "node:process";
export const untitled_silverPinniped = (async () => {
const { ChatPromptTemplate } = await import("npm:langchain/prompts");
const { ChatOpenAI } = await import("npm:langchain/chat_models/openai");
const { StringOutputParser } = await import(
"npm:langchain/schema/output_parser"
);
const SYSTEM_TEMPLATE = `You are an AI programming assistant.`;
const redesignTemplate = ChatPromptTemplate.fromMessages<{
input: string;
initial_code: string;
}>([
["system", SYSTEM_TEMPLATE],
["human", "{input}"],
]);
const model = new ChatOpenAI({
modelName: "gpt-4",
temperature: 0.2,
openAIApiKey: process.env.OPENAI_API_KEY,
});
// Output parser converts the chat message into a raw string. Also works with streaming.
const chain = redesignTemplate.pipe(model).pipe(new StringOutputParser());
const output = await chain.invoke({
input: "A word guessing game.",
initial_code:
`<TextInput id="nameInput" placeholder="Starting test input" />`,
});
return output;
})();
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.