Search
Code3,172
import { OpenAI } from "https://esm.town/v/std/openai";import { Post } from "./database/queries.ts";export class TwitterSentimentAnalyzer { private config: SentimentAnalysisConfig; private openai: OpenAI | null = null; private requestTimestamps: number[] = []; // Store timestamps of recent API requests if (this.config.useAI) { this.initializeOpenAI(); } } /** * Initialize OpenAI client */ private initializeOpenAI(): void { try { this.openai = new OpenAI(); } catch (error: unknown) { console.error("Failed to initialize OpenAI client:", error); const errorMessage = error instanceof Error ? error instanceof Error ? error.message : String(error) : String(error); throw new Error( `OpenAI initialization failed: ${errorMessage}. Make sure OPENAI_API_KEY is set.`, ); } /** * Analyze tweets using OpenAI * @param tweets Array of tweets to analyze * @returns Array of sentiment analysis results */ private async analyzeWithAI(tweets: Post[]): Promise<SentimentResult[]> { if (!this.openai) { throw new Error("OpenAI client not initialized"); } this.recordRequest(); // Call OpenAI API const completion = await this.openai.chat.completions.create({ messages: [ { const responseContent = completion.choices[0]?.message?.content || ""; if (!responseContent) { throw new Error("Empty response from OpenAI"); } if (!parsedResponse.results || !Array.isArray(parsedResponse.results)) { throw new Error("Invalid response format from OpenAI"); } } } catch (parseError) { console.error("Failed to parse OpenAI response:", parseError); const parseErrorMessage = parseError instanceof Error ? parseError.message : String(parseError); throw new Error( `Failed to parse OpenAI response: ${parseErrorMessage}`, ); } * Build the prompt for sentiment analysis * @param tweets Array of tweets to analyze * @returns Formatted prompt for OpenAI */ private buildSentimentPrompt(tweets: Post[]): string {
<div style="background: #f7fafc; padding: 15px; border-radius: 8px; margin-top: 30px; font-size: 12px; color: #718096;"> <p>Please check the logs for more details and consider investigating the issue.</p> <p>You may want to check your OpenAI API key and quota limits.</p> </div> </div>
import { Hono } from "https://esm.sh/hono@3.11.7";import { OpenAI } from "https://esm.town/v/std/openai";const app = new Hono();app.onError((err) => Promise.reject(err));const openai = new OpenAI();// Common shell script patterns and best practicesasync function generateShellScript(prompt: string): Promise<string> { try { const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [
- Built with Hono framework on Val Town- Uses OpenAI GPT-4o-mini for script generation- Implements caching for better performance- Returns plain text scripts suitable for piping to bash
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { 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 create a fresh table.### OpenAI```tsimport { 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" },
import { OpenAI } from "https://esm.town/v/std/openai";import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";import { Octokit } from "npm:octokit";const octokit = new Octokit({ auth: Deno.env.get("GITHUB_TOKEN") });const openai = new OpenAI();export async function fetchAndPostCommits(since: string, until: string) { // AI Summary const { choices } = await openai.chat.completions.create({ model: "gpt-4o-mini", temperature: 0.2,
const MODEL = "gpt-realtime";const INSTRUCTIONS = ` Greet the user in English, and thank them for trying the new OpenAI Realtime API. Give them a brief summary based on the list below, and then ask if they have any questions. Answer questions using the information below. For questions outside this scope, - higher audio quality - improved handling of alphanumerics (eg, properly understanding credit card and phone numbers) - support for the OpenAI Prompts API - support for MCP-based tools - auto-truncation to reduce context sizeconst VOICE = "marin";const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");if (!OPENAI_API_KEY) { throw new Error("🔴 OpenAI API key not configured");}export function makeHeaders(contentType?: string) { const obj: Record<string, string> = { Authorization: `Bearer ${OPENAI_API_KEY}`, }; if (contentType) obj["Content-Type"] = contentType;
sip.post("/", async (c) => { // Verify the webhook. const OPENAI_SIGNING_SECRET = Deno.env.get("OPENAI_SIGNING_SECRET"); if (!OPENAI_SIGNING_SECRET) { console.error("🔴 webhook secret not configured"); return c.text("Internal error", 500); } const webhook = new Webhook(OPENAI_SIGNING_SECRET); const bodyStr = await c.req.text(); let callId: string | undefined; // Accept the call. const url = `https://api.openai.com/v1/realtime/calls/${callId}/accept`; const headers = makeHeaders("application/json"); const body = JSON.stringify(makeSession());
rtc.post("/", async (c) => { // Create the call. const url = "https://api.openai.com/v1/realtime/calls"; const headers = makeHeaders(); const fd = new FormData();
reconsumeralization
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
/**
* Practical Implementation of Collective Content Intelligence
* Bridging advanced AI with collaborative content creation
*/
exp
kwhinnery_openai
lost1991
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
No docs found