valTownChatGPTREADME.md1 match
1# ChatGPT Implemented in Val Town
23Demonstrated how to use assistants and threads with the OpenAI SDK and how to stream the response with Server-Sent Events.
45<p align=center>
valTownChatGPTmain.tsx8 matches
1/** @jsxImportSource https://esm.sh/react */
2import OpenAI from "npm:openai";
3import { renderToString } from "npm:react-dom/server";
45// This uses by personal API key, you'll need to provide your own if
6// you fork this. We'll be adding support to the std/openai lib soon!
7const openai = new OpenAI();
8import { Hono } from "npm:hono@3";
938});
3940// Setup the SSE connection and stream back the response. OpenAI handles determining
41// which message is the correct response based on what was last read from the
42// thread. This is likely vulnerable to race conditions.
58const app = new Hono();
59app.get("/", async (c) => {
60const thread = await openai.beta.threads.create();
61const assistant = await openai.beta.assistants.create({
62name: "",
63instructions:
114app.post("/post-message", async (c) => {
115let message = await c.req.text();
116await openai.beta.threads.messages.create(
117c.req.query("threadId"),
118{ role: "user", content: message },
132));
133};
134const run = openai.beta.threads.runs.stream(threadId, {
135assistant_id: assistantId,
136// Make sure we only display messages we haven't seen yet.
twitterAlertmain.tsx5 matches
1import { zodResponseFormat } from "https://esm.sh/openai/helpers/zod";
2import { z } from "https://esm.sh/zod";
3import { OpenAI } from "https://esm.town/v/std/openai";
4import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
5import { socialDataSearch, Tweet } from "https://esm.town/v/stevekrouse/socialDataSearch";
11.join(" OR ") + " " + excludes;
1213const openai = new OpenAI();
1415const RelevanceSchema = z.object({
2930try {
31const completion = await openai.beta.chat.completions.parse({
32model: "gpt-4o-mini",
33messages: [
42return completion.choices[0].message.parsed;
43} catch (error) {
44console.error("Error parsing OpenAI response:", error);
45return { isRelevant: false, confidence: 0, reason: "Error in processing" };
46}
neatEmeraldVicunamain.tsx5 matches
1import { zodResponseFormat } from "https://esm.sh/openai/helpers/zod";
2import { z } from "https://esm.sh/zod";
3import { OpenAI } from "https://esm.town/v/std/openai";
4import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
5import { socialDataSearch, Tweet } from "https://esm.town/v/stevekrouse/socialDataSearch";
11.join(" OR ") + " " + excludes;
1213const openai = new OpenAI();
1415const RelevanceSchema = z.object({
2930try {
31const completion = await openai.beta.chat.completions.parse({
32model: "gpt-4o-mini",
33messages: [
42return completion.choices[0].message.parsed;
43} catch (error) {
44console.error("Error parsing OpenAI response:", error);
45return { isRelevant: false, confidence: 0, reason: "Error in processing" };
46}
weatherGPTmain.tsx3 matches
1import { email } from "https://esm.town/v/std/email?v=11";
2import { OpenAI } from "npm:openai";
34let location = "brooklyn ny";
8).then(r => r.json());
910const openai = new OpenAI();
11let chatCompletion = await openai.chat.completions.create({
12messages: [{
13role: "user",
interview_practicemain.tsx3 matches
235const { intervieweeResponse, interviewPosition } = await request.json();
236237const { OpenAI } = await import("https://esm.town/v/std/openai");
238const openai = new OpenAI();
239240const completion = await openai.chat.completions.create({
241messages: [
242{
webpage_summarizermain.tsx4 matches
228const webpageText = await webpageResponse.text();
229230// Use OpenAI as Claude proxy
231const { OpenAI } = await import("https://esm.town/v/std/openai");
232const openai = new OpenAI();
233234const completion = await openai.chat.completions.create({
235messages: [
236{
reflective_qamain.tsx3 matches
339const { question } = await request.json();
340341const { OpenAI } = await import("https://esm.town/v/std/openai");
342const openai = new OpenAI();
343344const completion = await openai.chat.completions.create({
345messages: [
346{
getShowcaseValsmain.tsx4 matches
1import { OpenAI } from "https://esm.sh/openai";
2import { zodResponseFormat } from "https://esm.sh/openai/helpers/zod";
3import { z } from "https://esm.sh/zod";
4import { zip } from "https://esm.town/v/pomdtr/sql";
42}, { concurrency: 3 });
4344const openai = new OpenAI();
4546const ValDescriptions = z.object({
5051async function getDescriptions(val) {
52const completion = await openai.beta.chat.completions.parse({
53model: "gpt-4o-mini",
54messages: [
reflective_qamain.tsx3 matches
339const { question } = await request.json();
340341const { OpenAI } = await import("https://esm.town/v/std/openai");
342const openai = new OpenAI();
343344const completion = await openai.chat.completions.create({
345messages: [
346{