Search

3,304 results found for openai (1736ms)

Code
3,209

import { type WriterOptions } from "./WriterOptions";
import { fetch } from "https://esm.town/v/std/fetch?v=4";
import OpenAI, { type ClientOptions } from "npm:openai";
export class ReadmeWriter {
model: string;
openai: OpenAI;
apiKey: string;
valtownKey: string;
constructor(options: WriterOptions) {
const { model, ...openaiOptions } = options;
this.model = model ? model : "gpt-3.5-turbo";
this.openai = new OpenAI(openaiOptions);
this.valtownKey = Deno.env.get("valtown");
}
}
private async performOpenAICall(prompt: string) {
try {
const response = await this.openai.chat.completions.create({
messages: [{ role: "system", content: prompt }],
model: this.model,
if (!response.choices || response.choices.length === 0) {
throw new Error("No response from OpenAI");
}
if (!readme) {
throw new Error("No readme returned by OpenAI. Try again.");
}
const { id, code } = await this.getVal(username, valName);
const prompt = this.createPrompt(code, userPrompt);
const readme = await this.performOpenAICall(prompt);
return { id, readme };
}
import { type WriterOptions } from "./WriterOptions";
import { sqlite } from "https://esm.town/v/std/sqlite";
import OpenAI from "npm:openai";
interface QueryWriterOptons extends WriterOptions {
model: string;
apiKey: string;
openai: OpenAI;
constructor(options: QueryWriterOptons) {
const { table, model, ...openaiOptions } = options;
this.table = table;
this.model = model;
// this.apiKey = openaiOptions.apiKey ? openaiOptions.apiKey : Deno.env.get("OPENAI_API_KEY"
this.openai = new OpenAI(openaiOptions);
}
try {
const response = await this.openai.chat.completions.create({
messages: [{ role: "system", content: prompt }],
model: this.model,
if (!response.choices || response.choices.length === 0) {
throw new Error("No response from OpenAI");
}
if (!query) {
throw new Error("No SQL returned from OpenAI. Try again.");
}
try {
const response = await this.openai.chat.completions.create({
messages: [{ role: "system", content: prompt }],
model: this.model,
if (!response.choices || response.choices.length === 0) {
throw new Error("No response from OpenAI");
}
if (!query) {
throw new Error("No SQL returned from OpenAI. Try again.");
}
import { type ClientOptions } from "npm:openai";
export interface WriterOptions extends ClientOptions {
import { fetch } from "https://esm.town/v/std/fetch?v=4";
import OpenAI, { type ClientOptions } from "npm:openai";
export interface WriterOptions extends ClientOptions {
}
async function performOpenAICall(prompt: string, model: string, openaiOptions: ClientOptions) {
const openai = new OpenAI(openaiOptions);
try {
const response = await openai.chat.completions.create({
messages: [{ role: "system", content: prompt }],
model: model,
if (!response.choices || response.choices.length === 0) {
throw new Error("No response from OpenAI");
}
if (!readme) {
throw new Error("No readme returned by OpenAI. Try again.");
}
async function draftReadme(options: WriterOptions) {
const { username, valName, model = "gpt-3.5-turbo", userPrompt, ...openaiOptions } = options;
const { id, code } = await getVal(username, valName);
const prompt = createPrompt(code, userPrompt);
const readme = await performOpenAICall(prompt, model, openaiOptions);
return readme;
}
async function writeReadme(options: WriterOptions) {
const { username, valName, model = "gpt-3.5-turbo", userPrompt, ...openaiOptions } = options;
const { id, code } = await getVal(username, valName);
const prompt = createPrompt(code, userPrompt);
const readme = await performOpenAICall(prompt, model, openaiOptions);
try {
const update = await updateReadme(id, readme);
import { createDayTotal } from "https://esm.town/v/nbbaier/createDayTotal";
import { cronEvalLogger as logger } from "https://esm.town/v/nbbaier/cronLogger";
import { fetchOpenAiUsageData } from "https://esm.town/v/nbbaier/fetchOpenAiUsageData";
import { updateBlobUsageDB } from "https://esm.town/v/nbbaier/updateBlobUsageDB";
import { blob } from "https://esm.town/v/std/blob?v=11";
import { DateTime } from "npm:luxon";
const fetchAndStoreOpenAiUsage = async (interval: Interval) => {
const timeZone = "America/Chicago";
const date = DateTime.now();
try {
const { data, whisper_api_data, dalle_api_data } = await fetchOpenAiUsageData(today);
const day_total = await createDayTotal(data, whisper_api_data, dalle_api_data);
};
export default logger(fetchAndStoreOpenAiUsage);
import { openAiPricing } from "./openAiPricing";
export const getAudioTotals = (data) => {
const totals = {};
const { whisperPricing } = openAiPricing;
for (const obj of data) {
// Extract the snapshot_id and token totals from the current object
import { openAiPricing } from "./openAiPricing";
import { email } from "https://esm.town/v/std/email?v=9";
};
} = {};
const { textPricing } = openAiPricing;
for (const obj of data) {
const { snapshot_id, n_context_tokens_total, n_generated_tokens_total }: {
import { openAiPricing } from "./openAiPricing";
export const getImageTotals = (data) => {
const totals = {};
const { dallePricing } = openAiPricing;
for (const obj of data) {
// Extract the snapshot_id and token totals from the current object
import { createDayTotal } from "./createDayTotal";
import { fetchOpenAiUsageData } from "./fetchOpenAiUsageData";
import { updateBlobUsageDB } from "./updateBlobUsageDB";
import { fetch } from "https://esm.town/v/std/fetch";
import { DateTime } from "npm:luxon";
const fetchAndStoreOpenAiUsage = async () => {
const timeZone = "America/Chicago";
const date = DateTime.now();
try {
const { data, whisper_api_data, dalle_api_data } = await fetchOpenAiUsageData("2024-04-01");
console.log(data.length);
console.log(whisper_api_data.length);
};
await fetchAndStoreOpenAiUsage();
} & Partial<Record<Month, Day>>;
export let openAiUsageTypes;