Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/$%7Bsuccess?q=openai&page=121&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=openai

Returns an array of strings in format "username" or "username/projectName"

Found 1599 results for "openai"(2450ms)

tomatoMinnowREADME.md1 match

@nicoalbanese•Updated 10 months ago
2Use the Vercel AI SDK in your Vals.
3
4**Note**: you must add your OpenAI key to your Val Town [Env variables](https://www.val.town/settings/environment-variables) under `OPENAI_API_KEY`. If you would like to specify a different name for your API Key, you can [create a custom OpenAI provider](https://sdk.vercel.ai/providers/ai-sdk-providers/openai#provider-instance) with the `createOpenAI` function.
5
6Prefer another AI provider? Use [any supported provider](https://sdk.vercel.ai/providers/ai-sdk-providers) by changing just two lines of code!

tealBadgermain.tsx3 matches

@stevekrouse•Updated 10 months ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2export default async function(req: Request): Promise<Response> {
3 const openai = new OpenAI();
4 const stream = await openai.chat.completions.create({
5 stream: true,
6 messages: [{ role: "user", content: "Write a poem in the style of beowulf about the DMV" }],

openAIStreamingExamplemain.tsx3 matches

@stevekrouse•Updated 10 months ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function(req: Request): Promise<Response> {
4 const openai = new OpenAI();
5 const stream = await openai.chat.completions.create({
6 stream: true,
7 messages: [{

openAIStreamingExampleREADME.md1 match

@stevekrouse•Updated 10 months ago
1Migrated from folder: Archive/openAIStreamingExample

webgenmain.tsx5 matches

@stevekrouse•Updated 10 months ago
1import { blob } from "https://esm.town/v/std/blob?v=12";
2import OpenAI from "npm:openai";
3
4const openai = new OpenAI();
5
6const getCacheKey = (url: string): string => {
90 let pageResult = "";
91
92 // // 2. Do one OpenAI inference to expand that URL to a longer page description
93 const pageDescriptionStream = await openai.chat.completions.create({
94 model: "gpt-4o",
95 messages: [{
127
128 // 3. Generate the page
129 const stream = await openai.chat.completions.create({
130 model: "gpt-4o",
131 messages: [{

convertToResumeJSONmain.tsx1 match

@iamseeley•Updated 10 months ago
8 }
9
10 const endpoint = 'https://api.openai.com/v1/chat/completions';
11 const model = 'gpt-4';
12

valTownChatGPTREADME.md1 match

@xuybin•Updated 10 months ago
1# ChatGPT Implemented in Val Town
2
3Demonstrated how to use assistants and threads with the OpenAI SDK and how to stream the response with Server-Sent Events.
4
5<p align=center>

valTownChatGPTmain.tsx8 matches

@xuybin•Updated 10 months ago
1/** @jsxImportSource https://esm.sh/react */
2import OpenAI from "npm:openai";
3import { renderToString } from "npm:react-dom/server";
4
5// 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";
9
38 });
39
40 // 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) => {
60 const thread = await openai.beta.threads.create();
61 const assistant = await openai.beta.assistants.create({
62 name: "",
63 instructions:
114app.post("/post-message", async (c) => {
115 let message = await c.req.text();
116 await openai.beta.threads.messages.create(
117 c.req.query("threadId"),
118 { role: "user", content: message },
132 ));
133 };
134 const run = openai.beta.threads.runs.stream(threadId, {
135 assistant_id: assistantId,
136 // Make sure we only display messages we haven't seen yet.

openAIStreamingREADME.md2 matches

@xuybin•Updated 10 months ago
1# OpenAI Streaming - Assistant and Threads
2
3An example of using OpenAI to stream back a chat with an assistant. This example sends two messages to the assistant and streams back the responses when they come in.
4
5Example response:

openAIStreamingmain.tsx6 matches

@xuybin•Updated 10 months ago
1import OpenAI from "npm:openai";
2const openai = new OpenAI();
3import process from "node:process";
4
5// Define our assistant.
6const assistant = await openai.beta.assistants.create({
7 name: "Val Tutor",
8 instructions: `You are a personal Val tutor.
14
15// Create a thread to chat in.
16const thread = await openai.beta.threads.create();
17
18// These are the messages we'll send to the assistant.
44 }, 100);
45
46 const message = await openai.beta.threads.messages.create(
47 thread.id,
48 { role: "user", content: messages[i] },
49 );
50
51 const run = openai.beta.threads.runs.stream(thread.id, {
52 assistant_id: assistant.id,
53 // Make sure we only display messages we haven't seen yet.

translateToEnglishWithOpenAI1 file match

@shlmt•Updated 20 hours ago

testOpenAI1 file match

@stevekrouse•Updated 2 days ago
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": "*",