2import { getWeather } from "https://esm.town/v/stevekrouse/getWeather?v=2";
3
4export default async function(interval: Interval) {
5 let weather = await getWeather("Brooklyn, NY");
6 let temperature = weather.current_condition[0].FeelsLikeF;
5const BASE_URL = "https://stevekrouse-cors_example_backend.web.val.run";
6
7export function App() {
8 const [logs, setLogs] = useState([]);
9 async function request(url, options) {
10 try {
11 const response = await fetch(url, options);
3import { OpenAI } from "https://esm.town/v/std/OpenAI";
4
5async function getValByAlias({ author, name }: { author: string; name: string }) {
6 const { id, code, readme } = await api(`/v1/alias/${author}/${name}`, {
7 authenticated: true,
11}
12
13async function updateValCode({ id, code }: { id: string; code: string }) {
14 console.log({ id, code });
15 await api(`/v1/vals/${id}/versions`, {
25}
26
27async function sendEmail({ subject, text }: { subject: string; text: string }) {
28 await email({
29 subject,
66
67Do not communicate with the user directly.
68Instead, use the provided functions to accomplish your task on the behalf of the user.
69
70For example, if you need to modify the code of a val, use the updateValCode function.
71`;
72
73type Tool = {
74 type: "function";
75 function: {
76 function: (...args: any[]) => any;
77 description: string;
78 parse: (...args: any[]) => any;
87};
88
89export function askAI(content: string) {
90 const client = new OpenAI();
91 const runner = client.beta.chat.completions.runTools({
96 }],
97 tools: [{
98 type: "function",
99 function: {
100 function: getValByAlias,
101 description: "Get val info (id, code) from it's alias",
102 parse: JSON.parse,
115 },
116 }, {
117 type: "function",
118 function: {
119 function: updateValCode,
120 description: "update the javascript code of a val",
121 parse: JSON.parse,
134 },
135 }, {
136 type: "function",
137 function: {
138 function: sendEmail,
139 description: "send an email",
140 parse: JSON.parse,
3const openai = new OpenAI();
4
5async function runConversation() {
6 const inputWord = "almond latte";
7
24 // if (message.tool_calls) {
25 // for (let i = 0; i < message.tool_calls.length; i++) {
26 // console.log("[CALLING]", message.tool_calls[i].function);
27 // const tool = toolbox[message.tool_calls[i].function.name];
28 // if (tool) {
29 // const result = await tool.call(JSON.parse(message.tool_calls[i].function.arguments));
30 // console.log("[RESULT]", truncate(result));
31 // transcript.push({
3
4/** load client HTML */
5async function loadClientHtml() {
6 // import VanJS framework and App component
7 const [{ default: van }, { default: App }] = await Promise.all([
28
29/** load client script for App component hydration */
30async function loadClientScript() {
31 // import esbuild and plugins
32 const [{ build }, { denoPlugins }] = await Promise.all([
49}
50
51export default async function fetch(req: Request) {
52 try {
53 const { pathname } = new URL(req.url);