gptToolsWriterOptions1 match
1import { type ClientOptions } from "npm:openai";
23export interface WriterOptions extends ClientOptions {
gptToolsdraftReadme10 matches
1import { fetch } from "https://esm.town/v/std/fetch?v=4";
2import OpenAI, { type ClientOptions } from "npm:openai";
34export interface WriterOptions extends ClientOptions {
40}
4142async function performOpenAICall(prompt: string, model: string, openaiOptions: ClientOptions) {
43const openai = new OpenAI(openaiOptions);
4445try {
46const response = await openai.chat.completions.create({
47messages: [{ role: "system", content: prompt }],
48model: model,
5051if (!response.choices || response.choices.length === 0) {
52throw new Error("No response from OpenAI");
53}
545657if (!readme) {
58throw new Error("No readme returned by OpenAI. Try again.");
59}
608384async function draftReadme(options: WriterOptions) {
85const { username, valName, model = "gpt-3.5-turbo", userPrompt, ...openaiOptions } = options;
86const { id, code } = await getVal(username, valName);
87const prompt = createPrompt(code, userPrompt);
88const readme = await performOpenAICall(prompt, model, openaiOptions);
89return readme;
90}
9192async function writeReadme(options: WriterOptions) {
93const { username, valName, model = "gpt-3.5-turbo", userPrompt, ...openaiOptions } = options;
94const { id, code } = await getVal(username, valName);
95const prompt = createPrompt(code, userPrompt);
96const readme = await performOpenAICall(prompt, model, openaiOptions);
97try {
98const update = await updateReadme(id, readme);
fetchAndStoreOpenAiUsage2main.tsx4 matches
1import { createDayTotal } from "https://esm.town/v/nbbaier/createDayTotal";
2import { cronEvalLogger as logger } from "https://esm.town/v/nbbaier/cronLogger";
3import { fetchOpenAiUsageData } from "https://esm.town/v/nbbaier/fetchOpenAiUsageData";
4import { updateBlobUsageDB } from "https://esm.town/v/nbbaier/updateBlobUsageDB";
5import { blob } from "https://esm.town/v/std/blob?v=11";
7import { DateTime } from "npm:luxon";
89const fetchAndStoreOpenAiUsage = async (interval: Interval) => {
10const timeZone = "America/Chicago";
11const date = DateTime.now();
1516try {
17const { data, whisper_api_data, dalle_api_data } = await fetchOpenAiUsageData(today);
1819const day_total = await createDayTotal(data, whisper_api_data, dalle_api_data);
27};
2829export default logger(fetchAndStoreOpenAiUsage);
openaiPricinggetAudioTotals2 matches
1import { openAiPricing } from "./openAiPricing";
23export const getAudioTotals = (data) => {
4const totals = {};
5const { whisperPricing } = openAiPricing;
6for (const obj of data) {
7// Extract the snapshot_id and token totals from the current object
openaiPricinggetTextTotals2 matches
1import { openAiPricing } from "./openAiPricing";
2import { email } from "https://esm.town/v/std/email?v=9";
310};
11} = {};
12const { textPricing } = openAiPricing;
13for (const obj of data) {
14const { snapshot_id, n_context_tokens_total, n_generated_tokens_total }: {
openaiPricinggetImageTotals2 matches
1import { openAiPricing } from "./openAiPricing";
23export const getImageTotals = (data) => {
4const totals = {};
5const { dallePricing } = openAiPricing;
6for (const obj of data) {
7// Extract the snapshot_id and token totals from the current object
1import { createDayTotal } from "./createDayTotal";
2import { fetchOpenAiUsageData } from "./fetchOpenAiUsageData";
3import { updateBlobUsageDB } from "./updateBlobUsageDB";
4import { fetch } from "https://esm.town/v/std/fetch";
6import { DateTime } from "npm:luxon";
78const fetchAndStoreOpenAiUsage = async () => {
9const timeZone = "America/Chicago";
10const date = DateTime.now();
1415try {
16const { data, whisper_api_data, dalle_api_data } = await fetchOpenAiUsageData("2024-04-01");
17console.log(data.length);
18console.log(whisper_api_data.length);
28};
2930await fetchAndStoreOpenAiUsage();
45} & Partial<Record<Month, Day>>;
4647export let openAiUsageTypes;
openaiPricingfetchOpenAiUsageData5 matches
1import { fetch } from "https://esm.town/v/std/fetch?v=4";
23const fetchOpenAiUsageData = async (today: string) => {
4const response = await fetch(
5`https://api.openai.com/v1/usage?date=${today}`,
6{
7method: "GET",
8headers: {
9Authorization: `Bearer ${Deno.env.get("OPENAI_API_KEY")}`,
10},
11},
1314if (!response.ok) {
15throw new Error("Failed to fetch openAI usage data.");
16}
1719};
2021export { fetchOpenAiUsageData };
openaiPricingcreateDayTotal1 match
2import { getImageTotals } from "./getImageTotals";
3import { getTextTotals } from "./getTextTotals";
4import { DayTotal, UsageDB } from "./openAiUsageTypes";
56const createDayTotal = async (data, whisper_api_data, dalle_api_data) => {