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/image-url.jpg%20%22Optional%20title%22?q=openai&page=144&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 1594 results for "openai"(520ms)

getModelBuildermain.tsx14 matches

@webup•Updated 1 year ago
3export async function getModelBuilder(spec: {
4 type?: "llm" | "chat" | "embedding";
5 provider?: "openai" | "huggingface";
6} = { type: "llm", provider: "openai" }, options?: any) {
7 const { extend, cond, matches, invoke } = await import("npm:lodash-es");
8 // Set up LangSmith tracer
17 // Set up API key for each providers
18 const args = extend({ callbacks }, options);
19 if (spec?.provider === "openai")
20 args.openAIApiKey = process.env.OPENAI;
21 else if (spec?.provider === "huggingface")
22 args.apiKey = process.env.HUGGINGFACE;
24 const setup = cond([
25 [
26 matches({ type: "llm", provider: "openai" }),
27 async () => {
28 const { OpenAI } = await import("npm:langchain/llms/openai");
29 return new OpenAI(args);
30 },
31 ],
32 [
33 matches({ type: "chat", provider: "openai" }),
34 async () => {
35 const { ChatOpenAI } = await import("npm:langchain/chat_models/openai");
36 return new ChatOpenAI(args);
37 },
38 ],
39 [
40 matches({ type: "embedding", provider: "openai" }),
41 async () => {
42 const { OpenAIEmbeddings } = await import(
43 "npm:langchain/embeddings/openai"
44 );
45 return new OpenAIEmbeddings(args);
46 },
47 ],

elevenlabsTTSmain.tsx1 match

@ale_annini•Updated 1 year ago
3
4export const elevenlabsTTS = async (req, res) => {
5 // https://platform.openai.com/docs/api-reference/images/create
6 // https://ale_annini-elevenlabstts.express.val.run/?args=[%22{\%22text\%22:\%22it%20beautiful\%22}%22]
7 const payload = {

chatGPTExamplemain.tsx1 match

@maxdrake•Updated 1 year ago
4 let repsonse_obj = await chatGPT(
5 "hello assistant",
6 [], // this can be an empty list, or if you're using this to continue a conversation, you can pass in someting of the form: https://platform.openai.com/docs/guides/chat/introduction
7 API_KEY
8 );

webscrapeWikipediaIntromain.tsx1 match

@vtdocs•Updated 1 year ago
4 const cheerio = await import("npm:cheerio");
5 const html = await fetchText(
6 "https://en.wikipedia.org/wiki/OpenAI",
7 );
8 const $ = cheerio.load(html);

gpt3main.tsx19 matches

@patrickjm•Updated 1 year ago
1import { trackOpenAiFreeUsage } from "https://esm.town/v/patrickjm/trackOpenAiFreeUsage";
2import { openAiTextCompletion } from "https://esm.town/v/patrickjm/openAiTextCompletion";
3import { openAiModeration } from "https://esm.town/v/patrickjm/openAiModeration";
4import { openAiFreeQuotaExceeded } from "https://esm.town/v/patrickjm/openAiFreeQuotaExceeded";
5import { openAiFreeUsageConfig } from "https://esm.town/v/patrickjm/openAiFreeUsageConfig";
6
7/**
8 * OpenAI text completion. https://platform.openai.com/docs/api-reference/completions
9 *
10 * val.town has generously provided a free daily quota. Until the quota is met, no need to provide an API key.
11 * To see if the quota has been met, you can run @patrickjm.openAiFreeQuotaExceeded()
12 *
13 * For full REST API access, see @patrickjm.openAiTextCompletion
14 */
15export let gpt3 = async (params: {
16 openAiKey?: string,
17 prompt: string,
18 maxTokens?: number,
21
22 // Determine whether to use provided apiKey or free usage apiKey based on daily quota.
23 const apiKey = params.openAiKey ?? openAiFreeUsageConfig.key;
24 const exceeded = await openAiFreeQuotaExceeded();
25 if (!params.openAiKey && exceeded) {
26 throw new Error(openAiFreeUsageConfig.quota_error);
27 }
28
29 // If using free token, first check inputs against moderation api
30 if (!params.openAiKey) {
31 const moderation = await openAiModeration({
32 apiKey,
33 input: params.prompt,
35 if (moderation.results.some((r) => r.flagged)) {
36 throw new Error(
37 "Sorry, this prompt was flagged by OpenAI moderation. If you provide your own API key, moderation will be turned off."
38 );
39 }
41
42 // Call completion API
43 const response = await openAiTextCompletion({
44 apiKey: apiKey,
45 prompt: params.prompt,
50 // If using free token, track usage against the quota.
51 try {
52 if (!params.openAiKey) {
53 await trackOpenAiFreeUsage(MODEL, response.usage.total_tokens);
54 }
55 } catch (e) {}

gpt4main.tsx1 match

@rlimit•Updated 1 year ago
3
4/**
5 * OpenAI text completion. https://platform.openai.com/docs/api-reference/completions
6 *
7 * val.town and rlimit.com has generously provided a free daily quota. Until the quota is met, no need to provide an API key.

getOpenapiEmbeddingmain.tsx1 match

@wilt•Updated 1 year ago
9 query: string;
10}): Promise<number[]> =>
11 fetchJSON("https://api.openai.com/v1/embeddings", {
12 method: "POST",
13 headers: {

questionsWithGuidelinesChainmain.tsx6 matches

@jacoblee93•Updated 1 year ago
2
3export const questionsWithGuidelinesChain = (async () => {
4 const { ChatOpenAI } = await import(
5 "https://esm.sh/langchain@0.0.150/chat_models/openai"
6 );
7 const { LLMChain } = await import("https://esm.sh/langchain@0.0.150/chains");
19 ]);
20 const questionChain = questionPrompt
21 .pipe(new ChatOpenAI({
22 openAIApiKey: process.env.OPENAI_API_KEY,
23 })
24 .pipe(new StringOutputParser()));
31 const styleChain = stylePrompt
32 .pipe(
33 new ChatOpenAI({
34 openAIApiKey: process.env.OPENAI_API_KEY,
35 }),
36 )

askLeximain.tsx6 matches

@thomasatflexos•Updated 1 year ago
15 );
16 const { SupabaseVectorStore } = await import("npm:langchain/vectorstores");
17 const { ChatOpenAI } = await import("npm:langchain/chat_models");
18 const { OpenAIEmbeddings } = await import("npm:langchain/embeddings");
19 const { createClient } = await import(
20 "https://esm.sh/@supabase/supabase-js@2"
25 );
26 let streamedResponse = "";
27 const chat = new ChatOpenAI({
28 modelName: "gpt-3.5-turbo",
29 openAIApiKey: process.env.OPEN_API_KEY,
30 streaming: true,
31 callbacks: [{
35 });
36 const vectorStore = await SupabaseVectorStore.fromExistingIndex(
37 new OpenAIEmbeddings({
38 openAIApiKey: process.env.OPEN_API_KEY,
39 }),
40 {

generateValCodeAPImain.tsx1 match

@andreterron•Updated 1 year ago
4export let generateValCodeAPI = (description: string) =>
5 generateValCode(
6 process.env.VT_OPENAI_KEY,
7 description,
8 );

translateToEnglishWithOpenAI1 file match

@shlmt•Updated 16 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": "*",