Search

3,377 results found for openai (1774ms)

Code
3,282

import { fetch } from "https://esm.town/v/std/fetch";
import { OpenAI } from "https://esm.town/v/std/openai";
import { z } from "npm:zod";
}
// --- OpenAI API Call ---
async function callOpenAI(sysP: string, userP: string, mid: string, tid: string, log: LogFn): Pr
log("DB", "OpenAI", `Call tid=${tid}`, { sL: sysP.length, uL: userP.length }, mid, tid);
try { // @ts-ignore
const oai = new OpenAI(); // Assumes OPENAI_API_KEY is in env
const comp = await oai.chat.completions.create({
model: "gpt-4o-mini", // Using the specified model
const usg = comp.usage;
if (!resT) {
log("WN", "OpenAI", `No text tid=${tid}.`, { usg, fin: comp.choices[0]?.finish_reason }, m
return null;
}
log("IN", "OpenAI", `OK tid=${tid}`, { rL: resT.length, usg, fin: comp.choices[0]?.finish_re
return resT.trim();
} catch (err: any) {
st: err.status,
};
log("ER", "OpenAI", `Fail tid=${tid}:${err.message}`, { e: eD }, mid, tid);
throw new Error(
`OpenAI Fail: ${err.message}` + (err.code ? `(C:${err.code},S:${err.status})` : `(S:${err.
);
}
return { mid, cid: tid, p: {} as TOD, e: `${aC.name} fail:PromptGenErr.` };
}
const rOR = await callOpenAI(sP, uP, mid, tid, l);
if (!rOR) {
l("WN", aC.name, `OpenAI no content tid=${tid}.`, {}, mid, tid);
return { mid, cid: tid, p: {} as TOD, e: `${aC.name} fail:AI no content.` };
}
import { fetch } from "https://esm.town/v/std/fetch";
import { OpenAI } from "https://esm.town/v/std/openai";
import { z } from "npm:zod";
}
// --- OpenAI API Call ---
async function callOpenAI(sysP: string, userP: string, mid: string, tid: string, log: LogFn): Pr
log("DB", "OpenAI", `Call tid=${tid}`, { sL: sysP.length, uL: userP.length }, mid, tid);
try { // @ts-ignore
const oai = new OpenAI(); // Assumes OPENAI_API_KEY is in env
const comp = await oai.chat.completions.create({
model: "gpt-4o-mini", // Using the specified model
const usg = comp.usage;
if (!resT) {
log("WN", "OpenAI", `No text tid=${tid}.`, { usg, fin: comp.choices[0]?.finish_reason }, m
return null;
}
log("IN", "OpenAI", `OK tid=${tid}`, { rL: resT.length, usg, fin: comp.choices[0]?.finish_re
return resT.trim();
} catch (err: any) {
st: err.status,
};
log("ER", "OpenAI", `Fail tid=${tid}:${err.message}`, { e: eD }, mid, tid);
throw new Error(
`OpenAI Fail: ${err.message}` + (err.code ? `(C:${err.code},S:${err.status})` : `(S:${err.
);
}
return { mid, cid: tid, p: {} as TOD, e: `${aC.name} fail:PromptGenErr.` };
}
const rOR = await callOpenAI(sP, uP, mid, tid, l);
if (!rOR) {
l("WN", aC.name, `OpenAI no content tid=${tid}.`, {}, mid, tid);
return { mid, cid: tid, p: {} as TOD, e: `${aC.name} fail:AI no content.` };
}
// Automated response system for social media interactions
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
import { TwitterAPI } from "./twitter-api.ts";
export class AutoResponder {
private openai: OpenAI;
private twitterAPI: TwitterAPI;
constructor() {
this.openai = new OpenAI();
this.twitterAPI = new TwitterAPI();
this.initDatabase();
Do not include hashtags in the response. Return only the response text.`;
const completion = await this.openai.chat.completions.create({
messages: [
{
<p class="text-white/70 text-sm">
Add your API keys as environment variables:
<br>• OPENAI_API_KEY
<br>• TWITTER_API_KEY, TWITTER_API_SECRET
<br>• LINKEDIN_ACCESS_TOKEN
import { OpenAI } from "https://esm.town/v/std/openai";
import type { ContentType, ContentTemplate, BotConfig, GenerateContentRequest } from "../shared/
export class ContentGenerator {
private openai: OpenAI;
constructor() {
this.openai = new OpenAI();
}
try {
const completion = await this.openai.chat.completions.create({
messages: [
{
1. Set up environment variables:
- `OPENAI_API_KEY` (for content generation)
- `TWITTER_API_KEY`, `TWITTER_API_SECRET`, `TWITTER_ACCESS_TOKEN`, `TWITTER_ACCESS_SECRET`
- `LINKEDIN_ACCESS_TOKEN` (optional)
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" },
<option value="meta-llama/llama-3.1-8b-instruct">Llama 3.1 8B</option>
<option value="anthropic/claude-3.5-sonnet">Claude 3.5 Sonnet</option>
<option value="openai/gpt-4o">GPT-4o</option>
</>
)}