1import { OpenAI } from "https://esm.town/v/std/openai";
2import { Resume, JobRequirement, ResumeScore } from "../shared/types.ts";
3
4// Initialize OpenAI client
5const openai = new OpenAI();
6
7/**
28 `;
29
30 const response = await openai.chat.completions.create({
31 model: "gpt-4o-mini",
32 messages: [{ role: "user", content: prompt }],
48
49/**
50 * Calculate similarity score between two texts using OpenAI embeddings
51 */
52export async function calculateSimilarity(text1: string, text2: string): Promise<number> {
53 const response = await openai.embeddings.create({
54 model: "text-embedding-3-small",
55 input: [text1, text2],
15- **Frontend**: HTML, CSS (Tailwind), and TypeScript with React
16- **Database**: SQLite for storing resumes and job requirements
17- **NLP/ML**: OpenAI embeddings for semantic matching
18
19## Project Structure
1# Small subset of OpenAI API
2
3>![WARNING]
9
10```bash
11curl 'https://www.val.town/v/YOUR_USER_NAME/openai_api' \
12 -H 'Content-Type: application/json' \
13 -X POST \
26
27```js
28const response = await fetch('https://www.val.town/v/YOUR_USER_NAME/openai_api', {
29 method: 'POST',
30 headers: {
1import Ajv from "https://esm.sh/ajv@8.13.0";
2import { OpenAI } from "https://esm.town/v/std/openai";
3
4const openai = new OpenAI();
5const sharedHeaders = {
6 "Access-Control-Allow-Origin": "*",
62 </head>
63 <body>
64 <h1>Small subset of OpenAI API</h1>
65
66 <blockquote>
75
76
77 <pre><code>curl 'https://www.val.town/v/YOUR_USER_NAME/openai_api'
78 -H 'Content-Type: application/json'
79 -X POST
89 <p>or in JS</p>
90
91 <pre><code>const response = await fetch('https://www.val.town/v/YOUR_USER_NAME/openai_api', {
92 method: 'POST',
93 headers: {
145 }
146
147 const completion = await openai.chat.completions.create({
148 ...body,
149 model: "gpt-3.5-turbo",
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
14
15- `NEWSLETTER_RECIPIENT_EMAIL`: The email address where the newsletter will be sent
16- `OPENAI_API_KEY`: For generating content (automatically provided by Val Town)
17- `GITHUB_TOKEN` (optional): A GitHub personal access token to avoid rate limiting when fetching trending repositories
18
35The newsletter uses:
36
37- OpenAI to generate unique React/JS/TS knowledge tips
38- React's blog API to fetch the latest React news (with OpenAI as a fallback)
39- GitHub's API to find trending repositories related to React/JS/TS
40- Val Town's email functionality to send the formatted newsletter
44You can customize the newsletter by modifying the `daily-react-newsletter.ts` file:
45
46- Adjust the OpenAI prompts to get different types of content
47- Change the email template design
48- Modify the GitHub search query to find different types of repositories
551. Check the logs in Val Town to see any error messages
562. Verify that all environment variables are set correctly
573. Ensure your OpenAI API key has sufficient quota
584. If GitHub API requests are failing, consider adding a GitHub token
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { email } from "https://esm.town/v/std/email";
3
4// Function to generate React/JS/TS knowledge using OpenAI
5async function generateReactKnowledge(): Promise<string> {
6 const openai = new OpenAI();
7 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.";
8
9 const completion = await openai.chat.completions.create({
10 messages: [{ role: "user", content: prompt }],
11 model: "gpt-4o-mini",
37 console.error("Error fetching React news:", error);
38
39 // Fallback to OpenAI for React news if the API fails
40 const openai = new OpenAI();
41 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.";
42
43 const completion = await openai.chat.completions.create({
44 messages: [{ role: "user", content: prompt }],
45 model: "gpt-4o-mini",
80 console.error("Error fetching trending repos:", error);
81
82 // Fallback to OpenAI for trending repos if the API fails
83 const openai = new OpenAI();
84 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.";
85
86 const completion = await openai.chat.completions.create({
87 messages: [{ role: "user", content: prompt }],
88 model: "gpt-4o-mini",
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },