Search

3,377 results found for openai (7652ms)

Code
3,282

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" },
// Your Telegram Bot Token (provided by you)
const BOT_TOKEN = '8016525726:AAHkYt9R87OTWDcELwjCrOCmjNBTJZCEk4M';
// Your OpenAI API Key (You MUST replace 'YOUR_OPENAI_API_KEY' with your actual key)
const OPENAI_API_KEY = 'sk-proj-V-akq1Ze8eR7Ibpv0RP0kOh75UbUDGofGOgxnSkBmmiobTXH-SRvqh3rIPkZocTK
const CHANNEL_USERNAME = '@mandoqa'; // The target channel username
// Base URLs for APIs
const TELEGRAM_API_BASE = `https://api.telegram.org/bot${BOT_TOKEN}`;
const OPENAI_API_BASE = 'https://api.openai.com/v1';
// Key prefix for storing sent subjects in KV
try {
const prompt = buildQuizPrompt(randomSubject);
const openaiResponse = await fetch(`${OPENAI_API_BASE}/chat/completions`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${OPENAI_API_KEY}`,
'Content-Type': 'application/json'
},
});
const openaiResult = await openaiResponse.json();
if (!openaiResponse.ok) {
console.error('OpenAI API Error:', openaiResult);
return `Error calling OpenAI API: ${openaiResult.error?.message || 'Unknown err
}
// Parse the LLM's JSON response
const llmResponseContent = openaiResult.choices[0]?.message?.content;
if (!llmResponseContent) {
console.error('OpenAI response content missing:', openaiResult);
return 'Error: OpenAI response content missing.';
}
} catch (error) {
console.error('Error communicating with OpenAI API:', error);
return `Error communicating with OpenAI API: ${error.message}`;
}
from fastapi import APIRouter, HTTPException, Depends
from typing import List, Optional
import openai
import os
from datetime import datetime, timedelta
DEMO_USER_ID = 1
# OpenAI configuration
openai.api_key = os.getenv('OPENAI_API_KEY')
# Health check
async def process_voice_input(request: VoiceProcessRequest):
try:
if not openai.api_key:
raise HTTPException(status_code=500, detail="OpenAI API key not configured")
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
async def process_receipt(request: ReceiptProcessRequest):
try:
if not openai.api_key:
raise HTTPException(status_code=500, detail="OpenAI API key not configured")
response = openai.ChatCompletion.create(
model="gpt-4-vision-preview",
messages=[
pydantic==2.5.0
python-multipart==0.0.6
openai==1.3.0
python-dotenv==1.0.0
Pillow==10.1.0
- **Styling:** TailwindCSS with custom animations
- **Voice:** Web Speech API
- **AI:** OpenAI for receipt processing
## 📁 Project Structure
- 🎙️ Record voice notes directly in the browser
- 🤖 AI-powered transcription using OpenAI Whisper
- 🔗 Share voice notes via unique URLs
- ⏰ Set expiration by max listens or date
- **Database**: SQLite for voice note metadata
- **Storage**: Val Town Blob storage for audio files
- **AI**: OpenAI Whisper for transcription
- **Frontend**: React with TypeScript
- **Styling**: TailwindCSS
oops/test/main.tsx
2 matches
// https://oops--06dc8e5037c411f088ef9e149126039e.web.val.run
import { OpenAI } from "npm:openai";
const client = new OpenAI({
apiKey: "Placeholder", // This is the default and can be omitted
baseURL: "https://oops--06dc8e5037c411f088ef9e149126039e.web.val.run/v1",
import { Hono } from "https://esm.sh/hono@3.11.7";
import { OpenAI } from "https://esm.town/v/std/openai";
import { blob } from "https://esm.town/v/std/blob";
import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
});
const openai = new OpenAI();
// Serve static files
console.log("Added user message");
// Prepare messages for OpenAI (limit to last 10 messages to avoid token limits)
const recentMessages = conversation.messages.slice(-10);
const openaiMessages = recentMessages.map(msg => ({
role: msg.role as "user" | "assistant",
content: msg.content
}));
console.log("Calling OpenAI with", openaiMessages.length, "messages");
// Get AI response
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: openaiMessages,
max_tokens: 1000,
temperature: 0.7,
});
console.log("OpenAI response received");
const aiContent = completion.choices[0]?.message?.content;
if (!aiContent) {
throw new Error("No content in OpenAI response");
}
- Typing indicators
- Responsive design
- OpenAI GPT integration
## Project Structure
## Setup
1. Set your OpenAI API key in environment variables as `OPENAI_API_KEY`
2. The app will be available at the HTTP endpoint