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" },
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
3import * as ta from "npm:technicalindicators";
237}
238239// --- OpenAI Call Function ---
240async function callOpenAI(
241systemPrompt: string,
242userMessage: string,
248): Promise<{ role: "assistant" | "system"; content: string }> {
249const callId = Math.random().toString(36).substring(2, 8);
250const logPfx = `OpenAI Call [${agentName} ${taskId.split("-")[1] || taskId} ${callId}]`;
251try {
252log("DEBUG", agentName, `${logPfx}: Initiating (${model}, JSON: ${isJsonOutputRequired})...`);
253const openai = new OpenAI();
254const res = await openai.chat.completions.create({
255model,
256messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage }],
260const content = res.choices?.[0]?.message?.content;
261if (!content) {
262log("ERROR", agentName, `${logPfx}: OpenAI returned empty/invalid response.`);
263throw new Error("Invalid/empty AI response.");
264}
270let code = err.status || (err.response ? err.response.status : null);
271const errData = err.response?.data || err.error || err.response || err;
272if (errData?.message) { errMsg = `OpenAI Err (${code || "?"}) via ${agentName}: ${errData.message}`; }
273else if (errData?.error?.message) {
274errMsg = `OpenAI Err (${code || "?"}) via ${agentName}: ${errData.error.message}`;
275}
276else if (err.message) { errMsg += ` Details: ${err.message}`; }
285" (ACTION: Bad request/prompt issue)"; else if (
286err.code === "ENOTFOUND" || err.code === "ECONNREFUSED" || err.cause?.code === "UND_ERR_CONNECT_TIMEOUT"
287) errMsg += " (ACTION: Network error)"; else if (code >= 500) errMsg += " (ACTION: OpenAI server issue)";
288const escapedErr = errMsg.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n");
289if (isJsonOutputRequired) {
595const taskId = task.taskId;
596log("INFO", agentName, `Task ${taskId}. Goals hash: ${hashCode(JSON.stringify(task.payload))}`);
597const result = await callOpenAI(
598tickerSuggestionAgentSystemPrompt,
599JSON.stringify(task.payload),
938context: { newsSentiment: context?.newsSentiment?.[ticker] ?? "N/A" },
939});
940const result = await callOpenAI(
941tickerInterpretationAgentSystemPrompt,
942input,
1054pastPerformanceContext: pastPerformanceContext ?? "N/A",
1055});
1056const result = await callOpenAI(
1057synthesisChartingDataAgentSystemPrompt,
1058input,
vt-blog-1get-old-posts.ts5 matches
198},
199{
200"title": "An Introduction to OpenAI fine-tuning",
201"slug": "an-introduction-to-openai-fine-tuning",
202"link": "/blog/an-introduction-to-openai-fine-tuning",
203"description": "How to customize OpenAI to your liking",
204"pubDate": "Fri, 25 Aug 2023 00:00:00 GMT",
205"author": "Steve Krouse",
417"slug": "val-town-newsletter-16",
418"link": "/blog/val-town-newsletter-16",
419"description": "Our seed round, growing team, Codeium completions, @std/openai, and more",
420"pubDate": "Mon, 22 Apr 2024 00:00:00 GMT",
421"author": "Steve Krouse",
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" },