Search

3,275 results found for openai (1977ms)

Code
3,180

},
{
"title": "An Introduction to OpenAI fine-tuning",
"slug": "an-introduction-to-openai-fine-tuning",
"link": "/blog/an-introduction-to-openai-fine-tuning",
"description": "How to customize OpenAI to your liking",
"pubDate": "Fri, 25 Aug 2023 00:00:00 GMT",
"author": "Steve Krouse",
"slug": "val-town-newsletter-16",
"link": "/blog/val-town-newsletter-16",
"description": "Our seed round, growing team, Codeium completions, @std/openai, and more",
"pubDate": "Mon, 22 Apr 2024 00:00:00 GMT",
"author": "Steve Krouse",
Learn/sbir/main.tsx
15 matches
// Combined Frontend (React/ChakraUI) and Backend (Hono/OpenAI) for Val Town
// Funding Assistant Dashboard Prototype - v6 (Corrected AgencyInfo Prompt Logic)
export default async function server(request: Request): Promise<Response> {
// Only import server-side dependencies here
const { OpenAI } = await import("https://esm.town/v/std/openai");
// const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite"); // DB optional
const { Hono } = await import("npm:hono");
// --- OpenAI Client ---
// Ensure API key is set as Val Town env var 'openai'
let openai;
try {
openai = new OpenAI();
} catch (e) {
console.error("FATAL: Failed to initialize OpenAI client. Is the 'openai' environment varia
// Return a generic server error response if OpenAI cannot be initialized
error: "Server configuration error. Unable to initialize OpenAI client." }), {
status: 500,
headers: { "Content-Type": "application/json" },
];
// --- Call OpenAI ---
console.log(`Calling OpenAI for agent: ${agentType}...`);
const completion = await openai.chat.completions.create({
messages: messages,
model: "gpt-4o",
} catch (error) {
// Catches errors in request handling, OpenAI API call itself, etc.
console.error(`Critical error initiating agent ${agentType}:`, error);
let errorMsg = `Server error initiating agent ${agentType}.`;
// Check for specific OpenAI errors if needed for better diagnostics
// if (error instanceof OpenAI.APIError) { errorMsg = `OpenAI API Error: ${error.status}
else if (error.message) {
errorMsg = `${errorMsg} Details: ${error.message}`;
},
{
"title": "An Introduction to OpenAI fine-tuning",
"slug": "an-introduction-to-openai-fine-tuning",
"link": "/blog/an-introduction-to-openai-fine-tuning",
"description": "How to customize OpenAI to your liking",
"pubDate": "Fri, 25 Aug 2023 00:00:00 GMT",
"author": "Steve Krouse",
"slug": "val-town-newsletter-16",
"link": "/blog/val-town-newsletter-16",
"description": "Our seed round, growing team, Codeium completions, @std/openai, and more",
"pubDate": "Mon, 22 Apr 2024 00:00:00 GMT",
"author": "Steve Krouse",
},
{
"title": "An Introduction to OpenAI fine-tuning",
"slug": "an-introduction-to-openai-fine-tuning",
"link": "/blog/an-introduction-to-openai-fine-tuning",
"description": "How to customize OpenAI to your liking",
"pubDate": "Fri, 25 Aug 2023 00:00:00 GMT",
"author": "Steve Krouse",
"slug": "val-town-newsletter-16",
"link": "/blog/val-town-newsletter-16",
"description": "Our seed round, growing team, Codeium completions, @std/openai, and more",
"pubDate": "Mon, 22 Apr 2024 00:00:00 GMT",
"author": "Steve Krouse",
async function gpt4(prompt: string): Promise<string> {
const { OpenAI } = await import("https://esm.town/v/std/openai");
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-4-mini",
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "Say hello in a creative way" },
// --- Backend Server (Val Town) ---
export default async function server(request: Request): Promise<Response> {
const { OpenAI } = await import("https://esm.town/v/std/openai");
if (request.method === "OPTIONS") {
if (request.method === "POST" && new URL(request.url).pathname === "/grade-card") {
try {
// Check for OpenAI API Key in Val Town secrets
const openai = new OpenAI(); // Assumes OPENAI_API_KEY is set in Val Town secrets
const { imageBase64 } = await request.json();
if (!imageBase64 || typeof imageBase64 !== "string") {
}
console.log("Received image data, preparing request to OpenAI...");
const modelChoice = "gpt-4o"; // Or "gpt-4o-mini"
// --- Construct the detailed prompt for OpenAI ---
const prompt = `
Alright, listen up, collector fam—here’s the no-BS, sharp-as-a-PSA-10 shorthand guide to grading
`;
const response = await openai.chat.completions.create({
model: modelChoice,
response_format: { type: "json_object" },
});
console.log("Received response from OpenAI.");
const jsonString = response.choices[0]?.message?.content;
if (!jsonString) {
throw new Error("OpenAI did not return valid response content.");
}
console.log("Successfully parsed JSON response.");
} catch (parseError) {
console.error("Failed to parse JSON from OpenAI:", jsonString);
throw new Error("AI returned improperly formatted JSON data.");
}
// --- Backend Server (Val Town) ---
export default async function server(request: Request): Promise<Response> {
const { OpenAI } = await import("https://esm.town/v/std/openai");
if (request.method === "OPTIONS") {
if (request.method === "POST" && new URL(request.url).pathname === "/grade-card") {
try {
// Check for OpenAI API Key in Val Town secrets
const openai = new OpenAI(); // Assumes OPENAI_API_KEY is set in Val Town secrets
const { imageBase64 } = await request.json();
if (!imageBase64 || typeof imageBase64 !== "string") {
}
console.log("Received image data, preparing request to OpenAI...");
const modelChoice = "gpt-4o"; // Or "gpt-4o-mini"
// --- Construct the detailed prompt for OpenAI ---
const prompt = `
Alright, listen up, collector fam—here’s the no-BS, sharp-as-a-PSA-10 shorthand guide to g
`;
const response = await openai.chat.completions.create({
model: modelChoice,
response_format: { type: "json_object" },
});
console.log("Received response from OpenAI.");
const jsonString = response.choices[0]?.message?.content;
if (!jsonString) {
throw new Error("OpenAI did not return valid response content.");
}
console.log("Successfully parsed JSON response.");
} catch (parseError) {
console.error("Failed to parse JSON from OpenAI:", jsonString);
throw new Error("AI returned improperly formatted JSON data.");
}
// --- Backend Server (Val Town / Cloud Function) ---
export default async function server(request: Request): Promise<Response> {
// Dynamically import OpenAI only when needed on the server
const { OpenAI } = await import("https://esm.town/v/std/openai");
// Standard CORS preflight handling
if (request.method === "POST" && new URL(request.url).pathname === "/analyze-aircraft") {
try {
// Check for OpenAI API Key in Val Town secrets (Val Town automatically injects process.en
// The library handles finding the key from secrets/env vars.
const openai = new OpenAI(); // Instantiates with key from secrets
const { imageBase64 } = await request.json();
}
console.log("Received image data for aircraft analysis, preparing request to OpenAI...");
const modelChoice = "gpt-4o"; // Use the powerful vision model
// --- Construct the detailed prompt for OpenAI ---
// This prompt guides the AI to act as an aircraft maintenance analyzer.
const prompt = `
`;
// --- Call OpenAI API ---
const response = await openai.chat.completions.create({
model: modelChoice,
response_format: { type: "json_object" }, // Enforce JSON output
});
console.log("Received response from OpenAI for aircraft analysis.");
const jsonString = response.choices[0]?.message?.content;
if (!jsonString) {
throw new Error("OpenAI did not return valid response content.");
}
try {
parsedResponse = JSON.parse(jsonString);
console.log("Successfully parsed JSON response from OpenAI.");
} catch (parseError) {
console.error("Failed to parse JSON from OpenAI:", jsonString);
// Try to provide the invalid JSON in the error for debugging
throw new Error(`AI returned improperly formatted JSON data. Received: ${jsonString.subs