getContentFromUrlmain.tsx3 matches
61prompt = prompt || "Summarize this article in 30 words, focusing on the primary author. Do not respond with JSON or XML or stage instructions. Only reply in text. Text:"
62let result = await ai({
63provider: "openai",
64model: "gpt-3.5-turbo",
65prompt: prompt + content
71prompt = prompt || "Return a comma separated list of 3-4 tags that broadly describes the text. Do not repeat the given text. Just return text and commas, no other symbols. Text to categorize:"
72let result = await ai({
73provider: "openai",
74model: "gpt-3.5-turbo",
75prompt: prompt + content
80export const getEmbeddingsFn = async (content) => {
81let result = await ai({
82provider: "openai",
83embed:true,
84value: content
tomatoMinnowmain.tsx2 matches
1import { openai } from "npm:@ai-sdk/openai";
2import { StreamingTextResponse, streamText } from "npm:ai";
34export default async function(req: Request): Promise<Response> {
5const result = await streamText({
6model: openai("gpt-4o"),
7prompt: "Generate a fast recipe for Lasagna.",
8});
tomatoMinnowREADME.md1 match
2Use the Vercel AI SDK in your Vals.
34**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.
56Prefer 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
1import { OpenAI } from "https://esm.town/v/std/openai";
2export default async function(req: Request): Promise<Response> {
3const openai = new OpenAI();
4const stream = await openai.chat.completions.create({
5stream: true,
6messages: [{ role: "user", content: "Write a poem in the style of beowulf about the DMV" }],
openAIStreamingExamplemain.tsx3 matches
1import { OpenAI } from "https://esm.town/v/std/openai";
23export default async function(req: Request): Promise<Response> {
4const openai = new OpenAI();
5const stream = await openai.chat.completions.create({
6stream: true,
7messages: [{
1Migrated from folder: Archive/openAIStreamingExample
1import { blob } from "https://esm.town/v/std/blob?v=12";
2import OpenAI from "npm:openai";
34const openai = new OpenAI();
56const getCacheKey = (url: string): string => {
90let pageResult = "";
9192// // 2. Do one OpenAI inference to expand that URL to a longer page description
93const pageDescriptionStream = await openai.chat.completions.create({
94model: "gpt-4o",
95messages: [{
127128// 3. Generate the page
129const stream = await openai.chat.completions.create({
130model: "gpt-4o",
131messages: [{
convertToResumeJSONmain.tsx1 match
8}
910const endpoint = 'https://api.openai.com/v1/chat/completions';
11const model = 'gpt-4';
12
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.