valreadmegeneratormain.tsx3 matches
177}
178179const { OpenAI } = await import("https://esm.town/v/std/openai");
180const openai = new OpenAI();
181182const valTownClient = new ValTown({
197198try {
199const completion = await openai.chat.completions.create({
200model: "gpt-4o",
201messages: [
valreadmegeneratorREADME.md1 match
43- **Deno:** The server-side environment.
44- **ValTown SDK:** Integrated to fetch Val details.
45- **OpenAI GPT-4:** To generate natural language README content.
46- **JavaScript Modules (ESM):** For seamless module imports.
47
stevensDemo.cursorrules4 matches
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107messages: [
108{ role: "user", content: "Say hello in a creative way" },
stevensDemo.cursorrules4 matches
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107messages: [
108{ role: "user", content: "Say hello in a creative way" },
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
3import * as ta from "npm:technicalindicators";
362}
363364async function callOpenAI(
365systemPrompt: string,
366userMessage: string,
372): Promise<{ role: "assistant" | "system"; content: string }> {
373const callId = Math.random().toString(36).substring(2, 8);
374const logPfx = `OpenAI Call [${agentName} ${taskId.split("-")[1] || taskId} ${callId}]`;
375try {
376log("DEBUG", agentName, `${logPfx}: Initiating (${model}, JSON: ${isJsonOutputRequired})...`);
377const openai = new OpenAI();
378const res = await openai.chat.completions.create({
379model,
380messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
384const content = res.choices?.[0]?.message?.content;
385if (!content) {
386log("ERROR", agentName, `${logPfx}: OpenAI returned empty/invalid response.`);
387throw new Error("Invalid/empty AI response.");
388}
394let code = err.status || (err.response ? err.response.status : null);
395const errData = err.response?.data || err.error || err.response || err;
396if (errData?.message) { errMsg = `OpenAI Err (${code || "?"}) via ${agentName}: ${errData.message}`; }
397else if (errData?.error?.message) { errMsg = `OpenAI Err (${code || "?"}) via ${agentName}: ${errData.error.message}`; }
398else if (err.message) { errMsg += ` Details: ${err.message}`; }
399else { try { errMsg += ` Unknown err: ${JSON.stringify(errData)}`; } catch { errMsg += " Unknown non-serializable err."; }}
402else if (code === 400) errMsg += " (ACTION: Bad request/prompt issue)";
403else if (err.code === "ENOTFOUND" || err.code === "ECONNREFUSED" || err.cause?.code === "UND_ERR_CONNECT_TIMEOUT") errMsg += " (ACTION: Network error)";
404else if (code >= 500) errMsg += " (ACTION: OpenAI server issue)";
405const escapedErr = errMsg.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n");
406if (isJsonOutputRequired) {
659const taskId = task.taskId;
660log("INFO", agentName, `Task ${taskId}. Processing goals. Hash: ${hashCode(JSON.stringify(task.payload))}`);
661const result = await callOpenAI(
662tickerSuggestionAgentSystemPrompt,
663JSON.stringify(task.payload),
999},
1000});
1001const result = await callOpenAI(
1002tickerInterpretationAgentSystemPrompt,
1003input,
1111pastPerformanceContext: pastPerformanceContext ?? "N/A",
1112});
1113const result = await callOpenAI(
1114synthesisChartingDataAgentSystemPrompt,
1115input,
stevensDemo.cursorrules4 matches
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107messages: [
108{ role: "user", content: "Say hello in a creative way" },
stevensDemo.cursorrules4 matches
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107messages: [
108{ role: "user", content: "Say hello in a creative way" },
stevensDemo.cursorrules4 matches
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107messages: [
108{ role: "user", content: "Say hello in a creative way" },
stevensDemo.cursorrules4 matches
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107messages: [
108{ role: "user", content: "Say hello in a creative way" },
stevensDemo.cursorrules4 matches
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107messages: [
108{ role: "user", content: "Say hello in a creative way" },