Search

3,321 results found for openai (4172ms)

Code
3,226

Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
export default async function server(request: Request): Promise<Response> {
// Dynamically import OpenAI only on the server - like DeepSauce
const { OpenAI } = await import("https://esm.town/v/std/openai");
// Ensure API key is set in environment variables
const openai = new OpenAI();
// Handle POST requests for chat and image generation
}
try {
const completion = await openai.chat.completions.create({
messages: [
{
const messageContent = completion?.choices?.[0]?.message?.content;
if (!messageContent) {
throw new Error("No content received from OpenAI.");
}
});
} catch (error) {
console.error("OpenAI Chat API error:", error);
return new Response(
JSON.stringify({ error: "Failed to get response from AI. Maybe it needs more steak sau
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
Get/Future/main.tsx
13 matches
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
import * as ta from "npm:technicalindicators";
}
// --- OpenAI Call Function ---
async function callOpenAI(
systemPrompt: string,
userMessage: string,
): Promise<{ role: "assistant" | "system"; content: string }> {
const callId = Math.random().toString(36).substring(2, 8);
const logPfx = `OpenAI Call [${agentName} ${taskId.split("-")[1] || taskId} ${callId}]`;
try {
log("DEBUG", agentName, `${logPfx}: Initiating (${model}, JSON: ${isJsonOutputRequired})...`
const openai = new OpenAI();
const res = await openai.chat.completions.create({
model,
messages: [{ role: "system", content: systemPrompt }, { role: "user", content: userMessage
const content = res.choices?.[0]?.message?.content;
if (!content) {
log("ERROR", agentName, `${logPfx}: OpenAI returned empty/invalid response.`);
throw new Error("Invalid/empty AI response.");
}
let code = err.status || (err.response ? err.response.status : null);
const errData = err.response?.data || err.error || err.response || err;
if (errData?.message) { errMsg = `OpenAI Err (${code || "?"}) via ${agentName}: ${errData.me
else if (errData?.error?.message) {
errMsg = `OpenAI Err (${code || "?"}) via ${agentName}: ${errData.error.message}`;
}
else if (err.message) { errMsg += ` Details: ${err.message}`; }
" (ACTION: Bad request/prompt issue)"; else if (
err.code === "ENOTFOUND" || err.code === "ECONNREFUSED" || err.cause?.code === "UND_ERR_CO
twork error)"; else if (code >= 500) errMsg += " (ACTION: OpenAI server issue)";
const escapedErr = errMsg.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n")
if (isJsonOutputRequired) {
const taskId = task.taskId;
log("INFO", agentName, `Task ${taskId}. Goals hash: ${hashCode(JSON.stringify(task.payload))}`
const result = await callOpenAI(
tickerSuggestionAgentSystemPrompt,
JSON.stringify(task.payload),
context: { newsSentiment: context?.newsSentiment?.[ticker] ?? "N/A" },
});
const result = await callOpenAI(
tickerInterpretationAgentSystemPrompt,
input,
pastPerformanceContext: pastPerformanceContext ?? "N/A",
});
const result = await callOpenAI(
synthesisChartingDataAgentSystemPrompt,
input,
},
{
"title": "An Introduction to OpenAI fine-tuning",
"slug": "an-introduction-to-openai-fine-tuning",
"link": "/blog/an-introduction-to-openai-fine-tuning",
"description": "How to customize OpenAI to your liking",
"pubDate": "Fri, 25 Aug 2023 00:00:00 GMT",
"author": "Steve Krouse",
"slug": "val-town-newsletter-16",
"link": "/blog/val-town-newsletter-16",
"description": "Our seed round, growing team, Codeium completions, @std/openai, and more",
"pubDate": "Mon, 22 Apr 2024 00:00:00 GMT",
"author": "Steve Krouse",
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
},
{
"title": "An Introduction to OpenAI fine-tuning",
"slug": "an-introduction-to-openai-fine-tuning",
"link": "/blog/an-introduction-to-openai-fine-tuning",
"description": "How to customize OpenAI to your liking",
"pubDate": "Fri, 25 Aug 2023 00:00:00 GMT",
"author": "Steve Krouse",
"slug": "val-town-newsletter-16",
"link": "/blog/val-town-newsletter-16",
"description": "Our seed round, growing team, Codeium completions, @std/openai, and more",
"pubDate": "Mon, 22 Apr 2024 00:00:00 GMT",
"author": "Steve Krouse",