Search

4,263 results found for openai (4028ms)

Code
4,154

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;
import { fetch } from "https://esm.town/v/std/fetch?v=4";
const fetchOpenAiUsageData = async (today: string) => {
const response = await fetch(
`https://api.openai.com/v1/usage?date=${today}`,
{
method: "GET",
headers: {
Authorization: `Bearer ${Deno.env.get("OPENAI_API_KEY")}`,
},
},
if (!response.ok) {
throw new Error("Failed to fetch openAI usage data.");
}
};
export { fetchOpenAiUsageData };
import { getImageTotals } from "./getImageTotals";
import { getTextTotals } from "./getTextTotals";
import { DayTotal, UsageDB } from "./openAiUsageTypes";
const createDayTotal = async (data, whisper_api_data, dalle_api_data) => {
});
interface OpenAiPricing {
textPricing: {
[key: string]: {
}
export const openAiPricing: OpenAiPricing = {
textPricing: {
"gpt-3.5-turbo-16k-0613": createPricing(3000, 4000),

Vals

95
View more
peterqliu
PineconeIndex
Vector db's on Pinecone, with OpenAI embeddings
Public
openai-agents
stevekrouse
openai-agents
Template to use the OpenAI Agents SDK
Public
Ronsykes
hello-realtime
Sample app for the OpenAI Realtime API
Public
Ronsykes
hello-realtime-rs
Sample app for the OpenAI Realtime API
Public
dcm31
turso_events_estimator
Estimate OpenAI calls from Turso GitHub events
Public

Docs

11
View more
No docs found