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/$%7Bart_info.art.src%7D?q=openai&page=117&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 1581 results for "openai"(742ms)

valTownChatGPTmain.tsx8 matches

@simonw•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.

add_to_habitify_from_todoist_w_aimain.tsx4 matches

@nerdymomocat•Updated 10 months ago
4import Instructor from "npm:@instructor-ai/instructor";
5import Jimp from "npm:jimp";
6import OpenAI from "npm:openai";
7import { z } from "npm:zod";
8
17const TODOIST_API_KEY = process.env.TODOIST_API_KEY;
18const HABITIFY_API_KEY = process.env.HABITIFY_API_KEY;
19const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
20const DEF_TIMEZONE = "America/Los_Angeles"; // Get your timezone from here: https://stackoverflow.com/a/54500197
21
49const todoistapi = new TodoistApi(TODOIST_API_KEY);
50
51const oai = new OpenAI({
52 apiKey: OPENAI_API_KEY ?? undefined,
53});
54

exampleTopHackerNewsDailyEmailmain.tsx7 matches

@charlypoly•Updated 10 months ago
1import { loadPageContent } from "https://esm.town/v/charlypoly/browserbaseUtils";
2import { email } from "https://esm.town/v/std/email?v=12";
3import { OpenAI } from "https://esm.town/v/std/openai?v=4";
4import { z } from "npm:zod";
5import { zodToJsonSchema } from "npm:zod-to-json-schema";
26 });
27
28 // we create a OpenAI Tool that takes our schema as argument
29 const extractContentTool: any = {
30 type: "function",
37 };
38
39 const openai = new OpenAI();
40
41 // We ask OpenAI to extract the content from the given web page.
42 // The model will reach out to our `extract_content` tool and
43 // by doing so, the model will extract the required data to satisfy
44 // the requirement of `extract_content`s argument.
45 const completion = await openai.chat.completions.create({
46 model: "gpt-4-turbo",
47 messages: [
56 });
57
58 // we retrieve the serialized arguments generated by OpenAI
59 const result = completion.choices[0].message.tool_calls![0].function.arguments;
60
64 const parsed = schema.parse(JSON.parse(result));
65
66 const completion2 = await openai.chat.completions.create({
67 model: "gpt-4-turbo",
68 messages: [
7import cosSimilarity from "npm:cos-similarity";
8import _ from "npm:lodash";
9import OpenAI from "npm:openai";
10
11export default async function blogPostEmbeddingsDimensionalityReduction() {
23 ];
24
25 const openai = new OpenAI();
26 async function getEmbedding(str) {
27 return (await openai.embeddings.create({
28 model: "text-embedding-3-large",
29 input: str,

compareEmbeddingsmain.tsx3 matches

@janpaul123•Updated 10 months ago
6import cosSimilarity from "npm:cos-similarity";
7import _ from "npm:lodash";
8import OpenAI from "npm:openai";
9
10const comparisons = [
20];
21
22const openai = new OpenAI();
23const cache = {};
24async function getEmbedding(str) {
25 cache[str] = cache[str] || (await openai.embeddings.create({
26 model: "text-embedding-3-large",
27 input: str,

indexValsBlobsmain.tsx4 matches

@janpaul123•Updated 10 months ago
4import { db as allValsDb } from "https://esm.town/v/sqlite/db?v=9";
5import { blob } from "https://esm.town/v/std/blob";
6import OpenAI from "npm:openai";
7import { truncateMessage } from "npm:openai-tokens";
8
9const dimensions = 1536;
39);
40
41const openai = new OpenAI();
42for (const newValsBatch of newValsBatches) {
43 const batchDataIndex = nextDataIndex;
47 const code = getValCode(val);
48
49 const embedding = await openai.embeddings.create({
50 model: "text-embedding-3-small",
51 input: truncateMessage(code, "text-embedding-3-small"),

semanticSearchNeonmain.tsx3 matches

@janpaul123•Updated 10 months ago
3import { db as allValsDb } from "https://esm.town/v/sqlite/db?v=9";
4import { blob } from "https://esm.town/v/std/blob";
5import OpenAI from "npm:openai";
6
7const dimensions = 1536;
11 await client.connect();
12
13 const openai = new OpenAI();
14 const queryEmbedding = (await openai.embeddings.create({
15 model: "text-embedding-3-small",
16 input: query,

indexValsNeonmain.tsx4 matches

@janpaul123•Updated 10 months ago
5import { db as allValsDb } from "https://esm.town/v/sqlite/db?v=9";
6import { blob } from "https://esm.town/v/std/blob";
7import OpenAI from "npm:openai";
8import { truncateMessage } from "npm:openai-tokens";
9
10// CREATE TABLE vals_embeddings (id TEXT PRIMARY KEY, embedding VECTOR(1536));
41 }
42
43 const openai = new OpenAI();
44 for (const newValsBatch of newValsBatches) {
45 await Promise.all([...Array(newValsBatch.length).keys()].map(async (valIndex) => {
47 const code = getValCode(val);
48
49 const embedding = await openai.embeddings.create({
50 model: "text-embedding-3-small",
51 input: truncateMessage(code, "text-embedding-3-small"),

caloriesmain.tsx1 match

@chriswmartin•Updated 10 months ago
2import { fileToDataURL } from "https://esm.town/v/stevekrouse/fileToDataURL";
3import { modifyImage } from "https://esm.town/v/stevekrouse/modifyImage";
4import { chat } from "https://esm.town/v/stevekrouse/openai";
5import { Hono } from "npm:hono@3";
6

convertResumemain.tsx1 match

@iamseeley•Updated 10 months ago
122 event.preventDefault();
123 const resumeContent = document.getElementById('resumeContent').value;
124 const apiKey = '${Deno.env.get("OPENAI_API_KEY")}';
125 const spinner = document.getElementById('spinner');
126 const jsonOutput = document.getElementById('jsonOutput');

testOpenAI1 file match

@stevekrouse•Updated 1 day ago

testOpenAI1 file match

@shouser•Updated 3 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": "*",