Search

3,380 results found for openai (5254ms)

Code
3,285

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" },
const PINECONE_API_KEY = Deno.env.get("PINECONE_API_KEY");
const PINECONE_HOST = Deno.env.get("PINECONE_HOST");
const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
console.log("PINECONE_HOST:", PINECONE_HOST);
console.log("Has API keys:", !!PINECONE_API_KEY, !!OPENAI_API_KEY);
try {
// Get embedding
const embResponse = await fetch("https://api.openai.com/v1/embeddings", {
method: "POST",
headers: {
"Authorization": `Bearer ${OPENAI_API_KEY}`,
"Content-Type": "application/json",
},
export const searchEngine = {
async search(parsedQuery: any, originalQuery: string) {
const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
const PINECONE_API_KEY = Deno.env.get("PINECONE_API_KEY");
const PINECONE_HOST = Deno.env.get("PINECONE_HOST");
console.log("Wants latest?", wantsLatest);
const embedding = await searchEngine.getEmbedding(originalQuery, OPENAI_API_KEY);
const filter = {};
async getEmbedding(text: string, apiKey: string) {
const response = await fetch("https://api.openai.com/v1/embeddings", {
method: "POST",
headers: {
if (!response.ok) {
const error = await response.text();
console.error("OpenAI embedding error:", error);
throw new Error(`Embedding generation failed: ${response.status}`);
}
export const answerBot = {
async generateAnswer(query: string, searchResults: any, threadId?: string) {
const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
// Get or create thread
];
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${OPENAI_API_KEY}`,
"Content-Type": "application/json",
},
if (!response.ok) {
const error = await response.text();
console.error("OpenAI API error:", error);
throw new Error(`OpenAI API failed: ${response.status}`);
}
export const queryParser = {
async parse(query: string) {
const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${OPENAI_API_KEY}`,
"Content-Type": "application/json",
},
const PINECONE_API_KEY = Deno.env.get("PINECONE_API_KEY");
const PINECONE_HOST = Deno.env.get("PINECONE_HOST");
const OPENAI_API_KEY = Deno.env.get("OPENAI_API_KEY");
console.log("PINECONE_HOST:", PINECONE_HOST);
console.log("Has API keys:", !!PINECONE_API_KEY, !!OPENAI_API_KEY);
try {
// Get embedding
const embResponse = await fetch("https://api.openai.com/v1/embeddings", {
method: "POST",
headers: {
"Authorization": `Bearer ${OPENAI_API_KEY}`,
"Content-Type": "application/json",
},
import { OpenAI } from "https://esm.town/v/std/openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
messages: [
{ role: "user", content: "What are some interesting walks in Hertfordshire, starting in Heme
import { Hono } from "https://esm.sh/hono@3.11.7";
import { OpenAI } from "https://esm.town/v/std/openai";
import type { AIPrioritizeAllResponse, AIPriorityResponse } from "../../shared/types.ts";
import { getAllTodos, updateTodoAIPriority } from "../database/queries.ts";
const ai = new Hono();
const openai = new OpenAI();
// Get AI priority suggestion for a single todo
`;
const completion = await openai.chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-4o-mini",
const response = completion.choices[0]?.message?.content;
if (!response) {
throw new Error("No response from OpenAI");
}
`;
const completion = await openai.chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-4o-mini",
const response = completion.choices[0]?.message?.content;
if (!response) {
throw new Error("No response from OpenAI");
}