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
33
34
35
36
37
38
39
40
41
42
43
44
45
import { OpenAI } from "https://esm.town/v/std/openai?v=4";
const openai = new OpenAI();
async function runConversation() {
const inputWord = "almond latte";
const prompt = `
You are a helpful assistant capable of teaching Katakana. I will provide you with an english word,
and you will respond by replacing a syllable with Katakana. Each line should display the
transformed word. Repeat this process, one per line, until the english word is fully translated.
Do not include any other info, only print the translations. Please translate "${inputWord}."
`.replaceAll(/\s+/g, "");
const response = await openai.chat.completions.create({
messages: [
{ role: "user", content: prompt },
],
model: "gpt-4-turbo-preview",
});
return [inputWord, ...response.choices[0].message.content.split(/\s+/)];
// if (message.tool_calls) {
// for (let i = 0; i < message.tool_calls.length; i++) {
// console.log("[CALLING]", message.tool_calls[i].function);
// const tool = toolbox[message.tool_calls[i].function.name];
// if (tool) {
// const result = await tool.call(JSON.parse(message.tool_calls[i].function.arguments));
// console.log("[RESULT]", truncate(result));
// transcript.push({
// role: "tool",
// tool_call_id: message.tool_calls[i].id,
// content: typeof result === "string" ? result : JSON.stringify(result),
// });
// }
// }
// return await runConversation();
// } else {
// return message.content;
// }
}
console.log(await runConversation());
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
May 4, 2024