1import { OpenAI } from "https://esm.town/v/std/openai";
2import {
3 CodeReviewRequest,
10
11export class AIReviewEngine {
12 private openai: OpenAI;
13
14 constructor() {
15 this.openai = new OpenAI();
16 }
17
25
26 try {
27 const completion = await this.openai.chat.completions.create({
28 model: "gpt-4o-mini",
29 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" },
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101
102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107 messages: [
108 { role: "user", content: "Say hello in a creative way" },
2 const PINECONE_API_KEY = Deno.env.get("PINECONE_API_KEY");
3 const PINECONE_HOST = Deno.env.get("PINECONE_HOST");
4 const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
5
6 console.log("PINECONE_HOST:", PINECONE_HOST);
7 console.log("Has API keys:", !!PINECONE_API_KEY, !!OPENAI_API_KEY);
8
9 try {
10 // Get embedding
11 const embResponse = await fetch("https://api.openai.com/v1/embeddings", {
12 method: "POST",
13 headers: {
14 "Authorization": `Bearer ${OPENAI_API_KEY}`,
15 "Content-Type": "application/json",
16 },
2export const searchEngine = {
3 async search(parsedQuery: any, originalQuery: string) {
4 const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
5 const PINECONE_API_KEY = Deno.env.get("PINECONE_API_KEY");
6 const PINECONE_HOST = Deno.env.get("PINECONE_HOST");
18 console.log("Wants latest?", wantsLatest);
19
20 const embedding = await searchEngine.getEmbedding(originalQuery, OPENAI_API_KEY);
21
22 const filter = {};
94
95 async getEmbedding(text: string, apiKey: string) {
96 const response = await fetch("https://api.openai.com/v1/embeddings", {
97 method: "POST",
98 headers: {
108 if (!response.ok) {
109 const error = await response.text();
110 console.error("OpenAI embedding error:", error);
111 throw new Error(`Embedding generation failed: ${response.status}`);
112 }
4export const answerBot = {
5 async generateAnswer(query: string, searchResults: any, threadId?: string) {
6 const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
7
8 // Get or create thread
80 ];
81
82 const response = await fetch("https://api.openai.com/v1/chat/completions", {
83 method: "POST",
84 headers: {
85 "Authorization": `Bearer ${OPENAI_API_KEY}`,
86 "Content-Type": "application/json",
87 },
98 if (!response.ok) {
99 const error = await response.text();
100 console.error("OpenAI API error:", error);
101 throw new Error(`OpenAI API failed: ${response.status}`);
102 }
103
1export const queryParser = {
2 async parse(query: string) {
3 const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
4
5 const response = await fetch("https://api.openai.com/v1/chat/completions", {
6 method: "POST",
7 headers: {
8 "Authorization": `Bearer ${OPENAI_API_KEY}`,
9 "Content-Type": "application/json",
10 },
2 const PINECONE_API_KEY = Deno.env.get("PINECONE_API_KEY");
3 const PINECONE_HOST = Deno.env.get("PINECONE_HOST");
4 const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
5
6 console.log("PINECONE_HOST:", PINECONE_HOST);
7 console.log("Has API keys:", !!PINECONE_API_KEY, !!OPENAI_API_KEY);
8
9 try {
10 // Get embedding
11 const embResponse = await fetch("https://api.openai.com/v1/embeddings", {
12 method: "POST",
13 headers: {
14 "Authorization": `Bearer ${OPENAI_API_KEY}`,
15 "Content-Type": "application/json",
16 },
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3const openai = new OpenAI();
4
5const completion = await openai.chat.completions.create({
6 messages: [
7 { role: "user", content: "What are some interesting walks in Hertfordshire, starting in Hemel" },