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
31
32
import process from "node:process";
export const untitled_chocolateSquid = (async () => {
const { ChatOpenAI } = await import(
"https://esm.sh/langchain@0.0.146/chat_models/openai"
);
const { LLMChain } = await import("https://esm.sh/langchain@0.0.146/chains");
const { ChatPromptTemplate } = await import(
"https://esm.sh/langchain@0.0.146/prompts"
);
const template =
"You are a helpful assistant that translates {input_language} to {output_language}.";
const humanTemplate = "{text}";
const chatPrompt = ChatPromptTemplate.fromPromptMessages([
["system", template],
["human", humanTemplate],
]);
const chat = new ChatOpenAI({
temperature: 0,
openAIApiKey: process.env.OPENAI_API_KEY,
});
const chain = new LLMChain({
llm: chat,
prompt: chatPrompt,
});
const result = await chain.call({
input_language: "English",
output_language: "French",
text: "I love programming!",
});
return result;
})();
👆 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.