Search
Code3,279
import { OpenAI } from "https://esm.town/v/std/openai";import { Video, ClipSuggestion, KeyframeInfo, TranscriptSegment } from '../../shared/types.ts';// Initialize OpenAI clientconst openai = new OpenAI();/** // In a real implementation, we would analyze the actual video content // For this demo, we'll simulate video analysis using OpenAI // First, check if we have transcript dataasync function simulateTranscriptGeneration(video: Video): Promise<TranscriptSegment[]> { // In a real implementation, we would use a speech-to-text service // For this demo, we'll generate a fake transcript using OpenAI const prompt = `Generate a realistic transcript for a ${video.duration || 300} second video titled "${video.title}".Format the response as a JSON array of objects with 'start', 'end', and 'text' properties.`; const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: prompt }],): Promise<KeyframeInfo[]> { // In a real implementation, we would analyze video frames and audio // For this demo, we'll use OpenAI to identify potential key moments from the transcript const transcriptText = transcript.map(segment => segment.text).join(" ");Format the response as a JSON array of objects with 'time', 'confidence', and 'description' properties.`; const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: prompt }],): Promise<string> { // In a real implementation, we would use more sophisticated NLP // For this demo, we'll use OpenAI to generate a title const transcriptText = relevantTranscript.map(segment => segment.text).join(" ");The title should be attention-grabbing and optimized for social media engagement.`; const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: prompt }],): Promise<string> { // In a real implementation, we would use more sophisticated NLP // For this demo, we'll use OpenAI to generate a description const transcriptText = relevantTranscript.map(segment => segment.text).join(" ");Include relevant hashtags if appropriate.`; const completion = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: prompt }],
- **Backend**: Hono (API framework)- **Database**: SQLite- **AI Services**: OpenAI for content analysis, external video processing APIs- **Authentication**: JWT-based auth system- **Storage**: Val Town blob storage for metadata, external storage for video files
import { OpenAI } from "https://esm.town/v/std/openai";import { Resume, JobRequirement, ResumeScore } from "../shared/types.ts";// Initialize OpenAI clientconst openai = new OpenAI();/** `; const response = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: prompt }],/** * Calculate similarity score between two texts using OpenAI embeddings */export async function calculateSimilarity(text1: string, text2: string): Promise<number> { const response = await openai.embeddings.create({ model: "text-embedding-3-small", input: [text1, text2],
- **Frontend**: HTML, CSS (Tailwind), and TypeScript with React- **Database**: SQLite for storing resumes and job requirements- **NLP/ML**: OpenAI embeddings for semantic matching## Project Structure
# Small subset of OpenAI API>![WARNING]```bashcurl 'https://www.val.town/v/YOUR_USER_NAME/openai_api' \ -H 'Content-Type: application/json' \ -X POST \```jsconst response = await fetch('https://www.val.town/v/YOUR_USER_NAME/openai_api', { method: 'POST', headers: {
import Ajv from "https://esm.sh/ajv@8.13.0";import { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const sharedHeaders = { "Access-Control-Allow-Origin": "*", </head> <body> <h1>Small subset of OpenAI API</h1> <blockquote> <pre><code>curl 'https://www.val.town/v/YOUR_USER_NAME/openai_api' -H 'Content-Type: application/json' -X POST <p>or in JS</p> <pre><code>const response = await fetch('https://www.val.town/v/YOUR_USER_NAME/openai_api', { method: 'POST', headers: { } const completion = await openai.chat.completions.create({ ...body, model: "gpt-3.5-turbo",
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" },
- `NEWSLETTER_RECIPIENT_EMAIL`: The email address where the newsletter will be sent- `OPENAI_API_KEY`: For generating content (automatically provided by Val Town)- `GITHUB_TOKEN` (optional): A GitHub personal access token to avoid rate limiting when fetching trending repositoriesThe newsletter uses:- OpenAI to generate unique React/JS/TS knowledge tips- React's blog API to fetch the latest React news (with OpenAI as a fallback)- GitHub's API to find trending repositories related to React/JS/TS- Val Town's email functionality to send the formatted newsletterYou can customize the newsletter by modifying the `daily-react-newsletter.ts` file:- Adjust the OpenAI prompts to get different types of content- Change the email template design- Modify the GitHub search query to find different types of repositories1. Check the logs in Val Town to see any error messages2. Verify that all environment variables are set correctly3. Ensure your OpenAI API key has sufficient quota4. If GitHub API requests are failing, consider adding a GitHub token
import { OpenAI } from "https://esm.town/v/std/openai";import { email } from "https://esm.town/v/std/email";// Function to generate React/JS/TS knowledge using OpenAIasync function generateReactKnowledge(): Promise<string> { const openai = new OpenAI(); const prompt = "Share one useful but lesser-known fact or technique about React, JavaScript, or TypeScript that most developers don't know. Explain it concisely with a small code example if applicable."; const completion = await openai.chat.completions.create({ messages: [{ role: "user", content: prompt }], model: "gpt-4o-mini", console.error("Error fetching React news:", error); // Fallback to OpenAI for React news if the API fails const openai = new OpenAI(); const prompt = "What's a recent development or news in the React ecosystem? Provide a brief summary of something new or upcoming in the React world from the past month."; const completion = await openai.chat.completions.create({ messages: [{ role: "user", content: prompt }], model: "gpt-4o-mini", console.error("Error fetching trending repos:", error); // Fallback to OpenAI for trending repos if the API fails const openai = new OpenAI(); const prompt = "What's a trending GitHub repository related to React, JavaScript, or TypeScript that's gaining popularity? Provide the name, a brief description, and what makes it interesting."; const completion = await openai.chat.completions.create({ messages: [{ role: "user", content: prompt }], model: "gpt-4o-mini",
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