blog-cloneget-old-posts.ts5 matches
198},
199{
200"title": "An Introduction to OpenAI fine-tuning",
201"slug": "an-introduction-to-openai-fine-tuning",
202"link": "/blog/an-introduction-to-openai-fine-tuning",
203"description": "How to customize OpenAI to your liking",
204"pubDate": "Fri, 25 Aug 2023 00:00:00 GMT",
205"author": "Steve Krouse",
417"slug": "val-town-newsletter-16",
418"link": "/blog/val-town-newsletter-16",
419"description": "Our seed round, growing team, Codeium completions, @std/openai, and more",
420"pubDate": "Mon, 22 Apr 2024 00:00:00 GMT",
421"author": "Steve Krouse",
blogget-old-posts.ts5 matches
198},
199{
200"title": "An Introduction to OpenAI fine-tuning",
201"slug": "an-introduction-to-openai-fine-tuning",
202"link": "/blog/an-introduction-to-openai-fine-tuning",
203"description": "How to customize OpenAI to your liking",
204"pubDate": "Fri, 25 Aug 2023 00:00:00 GMT",
205"author": "Steve Krouse",
417"slug": "val-town-newsletter-16",
418"link": "/blog/val-town-newsletter-16",
419"description": "Our seed round, growing team, Codeium completions, @std/openai, and more",
420"pubDate": "Mon, 22 Apr 2024 00:00:00 GMT",
421"author": "Steve Krouse",
French_Bulldogmain.tsx5 matches
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { telegramSendMessage } from "https://esm.town/v/vtdocs/telegramSendMessage?v=5";
3import {
15console.log(`received: ${text}`)
16if (text) {
17const response = await translateWithOpenAI(text);
18console.log(`translated to: ${response}`);
19ctx.reply(response);
333435async function translateWithOpenAI(text: string) {
36const openai = new OpenAI();
37const completion = await openai.chat.completions.create({
38messages: [
39{
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { telegramSendMessage } from "https://esm.town/v/vtdocs/telegramSendMessage?v=5";
3import {
15console.log(`received: ${text}`)
16if (text) {
17const response = await translateWithOpenAI(text);
18console.log(`translated to: ${response}`);
19ctx.reply(response);
333435async function translateWithOpenAI(text: string) {
36const openai = new OpenAI();
37const completion = await openai.chat.completions.create({
38messages: [
39{
4// SERVER-SIDE LOGIC (TypeScript)
5// =============================================================================
6import { OpenAI } from "https://esm.town/v/std/openai";
78// --- Configuration ---
23maskSrc?: string;
24}
25interface OpenAIResponse {
26races: RaceInfo[];
27}
105];
106107// --- OpenAI Generation Function ---
108async function generateRaceDataWithOpenAI(): Promise<RaceInfo[]> {
109const openai = new OpenAI();
110const numToRequest = Math.max(1, NUM_CARDS_TO_GENERATE);
111const prompt =
126Return STRICTLY as a single JSON object: { "races": [ { race1 }, { race2 }, ... ] }. No introductory text or explanations outside the JSON structure.`;
127try {
128console.info(`Requesting ${numToRequest} race data generation from OpenAI...`);
129const completion = await openai.chat.completions.create({
130model: "gpt-4o",
131messages: [{ role: "user", content: prompt }],
134});
135const rawContent = completion.choices[0]?.message?.content;
136if (!rawContent) throw new Error("OpenAI returned an empty response message.");
137138let parsedJson;
140parsedJson = JSON.parse(rawContent);
141} catch (parseError) {
142console.error("Failed to parse OpenAI JSON response:", parseError);
143console.error("Raw OpenAI response:", rawContent);
144throw new Error(`JSON Parsing Error: ${parseError.message}`);
145}
160) {
161console.warn(
162`OpenAI response JSON failed validation for ${numToRequest} races:`,
163JSON.stringify(parsedJson, null, 2),
164);
165throw new Error(
166"OpenAI response JSON structure, count, data types, color format, hint value, or mask URL invalid.",
167);
168}
169170const generatedData = (parsedJson as OpenAIResponse).races.map(race => ({
171...race,
172borderAnimationHint: race.borderAnimationHint || "none",
173}));
174console.info(`Successfully generated and validated ${generatedData.length} races from OpenAI.`);
175return generatedData;
176} catch (error) {
177console.error("Error fetching or processing data from OpenAI:", error);
178console.warn("Using fallback race data due to the error.");
179return fallbackRaceData.slice(0, numToRequest).map(race => ({
186// --- Main HTTP Handler (Val Town Entry Point) ---
187export default async function server(request: Request): Promise<Response> {
188const activeRaceData = await generateRaceDataWithOpenAI();
189190const css = `
ArabicChef_Botmain.tsx5 matches
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { telegramSendMessage } from "https://esm.town/v/vtdocs/telegramSendMessage?v=5";
3import {
15console.log(`received: ${text}`)
16if (text) {
17const response = await translateWithOpenAI(text);
18console.log(`translated to: ${response}`);
19ctx.reply(response);
333435async function translateWithOpenAI(text: string) {
36const openai = new OpenAI();
37const completion = await openai.chat.completions.create({
38messages: [
39{
SpanishPanda_botmain.tsx5 matches
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { telegramSendMessage } from "https://esm.town/v/vtdocs/telegramSendMessage?v=5";
3import {
15console.log(`received: ${text}`)
16if (text) {
17const response = await translateToSpanishWithOpenAI(text);
18console.log(`translated to: ${response}`);
19ctx.reply(response);
333435async function translateToSpanishWithOpenAI(text: string) {
36const openai = new OpenAI();
37const completion = await openai.chat.completions.create({
38messages: [
39{
3import { AgentContext, AgentInput, AgentOutput } from "https://esm.town/v/salon/mandate/interfaces.ts";
4import { fetch } from "https://esm.town/v/std/fetch";
5import { OpenAI } from "https://esm.town/v/std/openai";
67// Summarizer Agent (unchanged, but shown for completeness)
23}
2425const openai = new OpenAI();
2627log("INFO", "SummarizerAgent", "Generating summary with OpenAI...");
28const completion = await openai.chat.completions.create({
29messages: [
30{
4041if (summary === "Could not generate summary.") {
42log("WARN", "SummarizerAgent", "OpenAI did not return a valid summary content.");
43}
44267}
268269const openai = new OpenAI();
270log("INFO", "CombinerAgent", "Combining text with OpenAI...");
271const completion = await openai.chat.completions.create({
272messages: [
273{
294295if (combined === "Could not combine information.") {
296log("WARN", "CombinerAgent", "OpenAI did not return valid combined content.");
297}
298
whatsapp-callbackindex.tsx1 match
177try {
178console.log(`[SmartAck] Attempting to generate smart ack for: "${userQuery.substring(0, 50)}..." with ${QUICK_ACK_MODEL}`);
179const groqResponse = await fetch("https://api.groq.com/openai/v1/chat/completions", {
180method: "POST",
181headers: {
GitHub-Release-Notesllm.ts5 matches
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { CommitWithPR, ReleaseNote } from "../shared/types.ts";
34// Initialize OpenAI client
5const openai = new OpenAI();
67/**
186`;
187188// Call the OpenAI API
189const completion = await openai.chat.completions.create({
190model: "gpt-4o",
191messages: [