Search

3,377 results found for openai (7087ms)

Code
3,282

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" },
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" },
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" },
// === Replace these with your real keys/numbers ===
const openai = new OpenAI({ apiKey: "sk-..." });
const clinicianPhone = "+1YOURCELLPHONE";
const twilioNumber = "+1YOURTWILIONUMBER";
`A dental patient asked: "${question}". Write 3 short, professional draft responses a dentis
const result = await openai.chat.completions.create({
model: "gpt-4",
messages: [{ role: "user", content: prompt }],
// === Replace these with your real keys/numbers ===
const openai = new OpenAI({ apiKey: "sk-..." });
const clinicianPhone = "+1YOURCELLPHONE";
const twilioNumber = "+1YOURTWILIONUMBER";
const prompt = `A dental patient asked: "${question}". Write 3 short, professional draft respons
const result = await openai.chat.completions.create({
model: "gpt-4",
messages: [{ role: "user", content: prompt }],
// src/openai_service.ts
import { LogFunction } from "https://esm.town/v/join/crit/types";
import { OpenAI } from "https://esm.town/v/std/openai"; // Val Town specific import
/**
* Invokes the OpenAI Chat Completion API with specified prompts and parameters.
* @param systemPrompt The system message to guide the AI's behavior.
* @param userPrompt The user's message or query.
* @throws Error if the API call fails critically.
*/
export async function invokeOpenAIChatCompletion(
systemPrompt: string,
userPrompt: string,
logger(
"AUDIT",
"OpenAIService",
`Initiating LLM call for task ${taskId}`,
{ systemPromptLength: systemPrompt.length, userPromptLength: userPrompt.length },
try {
const openAIClient = new OpenAI(); // API key should be configured via environment variables
const completion = await openAIClient.chat.completions.create({
model: "gpt-4o-mini", // Consider making this configurable
messages: [
logger(
"WARN",
"OpenAIService",
`LLM call for task ${taskId} yielded no content.`,
{ usageData, finishReason },
logger(
"INFO",
"OpenAIService",
`LLM call for task ${taskId} successful.`,
{ responseLength: responseText.length, usageData, finishReason },
logger(
"CRITICAL",
"OpenAIService",
`LLM call for task ${taskId} failed: ${error.message}`,
{ error: errorDetails },
);
throw new Error(
`OpenAI Service Failure: ${error.message}`
+ (error.code ? ` (Code: ${error.code}, Status: ${error.status})` : ` (Status: ${error.s
);
// src/ai_agent_runner.ts
import { invokeOpenAIChatCompletion } from "https://esm.town/v/join/crit/openai_service";
import {
BaseIncidentContext,
}
const rawOpenAIResult = await invokeOpenAIChatCompletion(
systemPrompt,
userPrompt,
logger,
);
if (!rawOpenAIResult) {
const msg = `LLM returned no content for task ${taskId}.`;
logger("WARN", agentName, msg, {}, masterIncidentId, taskId);
let parsedOutput: T_Output;
try {
parsedOutput = outputSchemaParser(rawOpenAIResult);
} catch (parseError: any) {
const msg = `Failed to parse LLM output for task ${taskId}. Error: ${parseError.message}`;
agentName,
msg,
{ rawResponsePreview: rawOpenAIResult.substring(0, 500) },
masterIncidentId,
taskId,