1import { openai } from "npm:@ai-sdk/openai"; // Ensure OPENAI_API_KEY environment variable is set
2import { generateText } from "npm:ai";
3
14 const recentChanges = body?.recent_changes ?? "The codebase now includes swearwords";
15 const { text } = await generateText({
16 model: openai("gpt-4o-mini"),
17 system: "You a moral counseler who analyes changes made to a codebase and return your opinion",
18 prompt: `
1// This approach fetches GitHub activity for two users specified in the URL,
2// sends it to OpenAI for analysis, and returns collaboration suggestions.
3// It uses the GitHub API (which doesn't require authentication for public data)
4// and the OpenAI API (which does require an API key).
5// Tradeoff: We're using an inline API key for simplicity, which isn't ideal for security.
6// Note: This might hit rate limits for the GitHub API due to fetching a year of data.
7
8import { OpenAI } from "https://esm.town/v/std/openai";
9
10const OPENAI_API_KEY = "your_openai_api_key"; // Replace with your actual OpenAI API key
11
12export default async function main(req: Request): Promise<Response> {
51 const user1Summary = summarizeActivity(user1Data);
52
53 const openai = new OpenAI(OPENAI_API_KEY);
54 const completion = await openai.chat.completions.create({
55 model: "gpt-4o-mini",
56 messages: [
95export default async function server(request: Request): Promise<Response> {
96 if (request.method === "POST" && new URL(request.url).pathname === "/chat") {
97 const { OpenAI } = await import("https://esm.town/v/std/openai");
98 const openai = new OpenAI();
99
100 const { messages } = await request.json();
101
102 const stream = await openai.chat.completions.create({
103 model: "gpt-4o-mini",
104 messages: messages,
100export default async function server(request: Request): Promise<Response> {
101 if (request.method === "POST" && new URL(request.url).pathname === "/chat") {
102 const { OpenAI } = await import("https://esm.town/v/std/openai");
103 const openai = new OpenAI();
104
105 const { messages } = await request.json();
106
107 const stream = await openai.chat.completions.create({
108 model: "gpt-4o-mini",
109 messages: messages,
2import process from "node:process";
3import { marked } from "npm:marked";
4import { OpenAI } from "npm:openai";
5
6function pm(...lines: string[]): string {
16 );
17
18 const client = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: "https://api.perplexity.ai" });
19 const response = await client.chat.completions.create({
20 model: "sonar",
2 const apiKey = "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"; // Use straight quotes
3
4 const response = await fetch(“https://api.openai.com/v1/chat/completions”, {
5 method: “POST”,
6 headers: {
194export default async function server(request: Request): Promise<Response> {
195 if (request.method === "POST" && new URL(request.url).pathname === "/chat") {
196 const { OpenAI } = await import("https://esm.town/v/std/openai");
197 const openai = new OpenAI();
198
199 try {
200 const { messages } = await request.json();
201
202 const completion = await openai.chat.completions.create({
203 messages: [
204 ...messages,
1# GitHub Activity Summarizer
2
3This val.town script fetches a user's recent GitHub activity and generates a summarized narrative overview using OpenAI's GPT model.
4
5## Features
6
7- Retrieves GitHub activity for a specified user from the past week
8- Summarizes activity using OpenAI's GPT-3.5-turbo model
9- Returns a concise, narrative summary of the user's GitHub contributions
10
22## Note
23
24Ensure you have necessary permissions and comply with GitHub's and OpenAI's terms of service when using this script.
2import { email } from "https://esm.town/v/std/email";
3import { extractValInfo } from "https://esm.town/v/stevekrouse/extractValInfo";
4import { OpenAI } from "npm:openai";
5
6function stripHtmlBackticks(html: string): string {
9
10export default async function(e: Email) {
11 const openai = new OpenAI();
12 console.log(`from: ${e.from} to: ${e.to} subject: ${e.subject}, cc: ${e.cc}, bcc: ${e.bcc}`);
13
25 }
26
27 const summary = await openai.chat.completions.create({
28 messages: [
29 {
19async function generateMotivation(userProgress) {
20 try {
21 const { OpenAI } = await import("https://esm.town/v/std/openai");
22 const openai = new OpenAI();
23
24 const motivationPrompt = `Generate a highly personalized, inspiring message for someone who has ${userProgress.totalHabits} habits, ${userProgress.completedHabits} completed habits, and an average streak of ${userProgress.averageStreak} days. Make it motivational and specific.`;
25
26 const response = await openai.chat.completions.create({
27 model: "gpt-4o-mini",
28 messages: [{ role: "user", content: motivationPrompt }],