2import { z } from "npm:zod@3.23.8";
3// @ts-ignore
4import { OpenAI } from "https://esm.town/v/std/openai?v=4";
5
6// --- Input and Output Schema Definitions ---
16});
17
18// Defines the expected JSON structure from the OpenAI API.
19// This allows us to validate the AI's output before using it.
20const AIResponseSchema = z.object({
44// --- Service Initialization ---
45const app = new Hono();
46const openai = new OpenAI();
47
48// --- API Endpoints ---
66
67 try {
68 // 2. Request structured data from the OpenAI API.
69 const completion = await openai.chat.completions.create({
70 model: "gpt-4o",
71 messages: [
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
1// @ts-ignore
2import { OpenAI } from "https://esm.town/v/std/openai?v=4";
3// @ts-ignore
4import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
433
434const app = new Hono();
435const openai = new OpenAI();
436
437// Helper to get all boundaries from the database
490 }
491
492 const completion = await openai.chat.completions.create({
493 model: "gpt-4o",
494 messages: [
537
538 // 2a. Generate Counselor Response
539 const counselorCompletion = await openai.chat.completions.create({
540 model: "gpt-4o",
541 messages: [
548
549 // 2b. Check with Boundary Guardian
550 const guardCompletion = await openai.chat.completions.create({
551 model: "gpt-4o",
552 messages: [{
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
88Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
89
90### OpenAI
91
92```ts
93import { OpenAI } from "https://esm.town/v/std/openai";
94const openai = new OpenAI();
95const completion = await openai.chat.completions.create({
96 messages: [
97 { role: "user", content: "Say hello in a creative way" },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { email } from "https://esm.town/v/std/email";
3
150 deploymentRequest: string;
151}): Promise<string> {
152 const openai = new OpenAI();
153
154 const prompt =
164The poem should be 12-16 lines, use elevated but accessible language, and blend DevOps terminology with natural imagery. Think of code as seeds, deployments as harvests, servers as fertile soil, and developers as gardeners tending the digital earth.`;
165
166 const completion = await openai.chat.completions.create({
167 messages: [
168 { role: "user", content: prompt },
94Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
95
96### OpenAI
97
98```ts
99import { OpenAI } from "https://esm.town/v/std/openai";
100const openai = new OpenAI();
101const completion = await openai.chat.completions.create({
102 messages: [
103 { role: "user", content: "Say hello in a creative way" },
452 }
453
454 // Test OpenAI directly
455 const { OpenAI } = await import("https://esm.town/v/std/openai");
456 const openai = new OpenAI();
457
458 const completion = await openai.chat.completions.create({
459 messages: [
460 {
476 input: message,
477 response: response,
478 provider: 'openai',
479 model: 'gpt-4o-mini',
480 tokensUsed: completion.usage?.total_tokens || 0
730
731 // Use AI engine directly
732 const { OpenAI } = await import("https://esm.town/v/std/openai");
733 const openai = new OpenAI();
734
735 const completion = await openai.chat.completions.create({
736 messages: [
737 { role: "system", content: `You are ${persona.name}, a ${persona.role} in a software team. ${persona.communicationStyle}` },