Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/docs/content/docs/getting-started/fin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ need various API keys from each of them. See [the environment variables section]
- [Google](https://console.cloud.google.com/)
- [Open Router](https://openrouter.ai/)
- [Resend](https://resend.com/)
- [Upstash](https://upstash.com/)
- [UploadThing](https://uploadthing.com/)

## Running the app locally
Expand Down
1 change: 0 additions & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"@polar-sh/sdk": "catalog:",
"@react-email/components": "^1.0.12",
"@react-email/render": "^2.0.6",
"@upstash/redis": "^1.35.3",
"ai": "catalog:",
"convex": "catalog:",
"convex-env": "^3.0.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/db/src/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ import type * as convex_helpers from "../convex_helpers.js";
import type * as counter from "../counter.js";
import type * as crons from "../crons.js";
import type * as http from "../http.js";
import type * as kv from "../kv.js";
import type * as lib_date_time_utils from "../lib/date_time_utils.js";
import type * as lib_utils from "../lib/utils.js";
import type * as limiter from "../limiter.js";
Expand Down Expand Up @@ -262,7 +261,6 @@ declare const fullApi: ApiFromModules<{
counter: typeof counter;
crons: typeof crons;
http: typeof http;
kv: typeof kv;
"lib/date_time_utils": typeof lib_date_time_utils;
"lib/utils": typeof lib_utils;
limiter: typeof limiter;
Expand Down
31 changes: 1 addition & 30 deletions packages/db/src/ai/tools/search/current_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import { z } from "zod";

import type { SearchReturnType } from "./schemas";
import { createTool } from "../../../agent/tools";
import { kv } from "../../../kv";
import { getCurrentDateTime } from "../../../lib/date_time_utils";
import { tryCatch } from "../../../lib/utils";
import {
exaSearchAndContents,
formatCacheKey,
logSearchCost,
} from "../tool_helpers";
import { CachedSourceSchema } from "./schemas";
import { exaSearchAndContents, logSearchCost } from "../tool_helpers";

const NUM_RESULTS = 5;

Expand Down Expand Up @@ -46,20 +40,6 @@ export const currentEvents = createTool({
),
}),
execute: async (ctx, args): Promise<SearchReturnType> => {
// check cache
const cacheKey = formatCacheKey("current-events", [args.query]);
const cachedData = await kv.get(cacheKey);
const cachedSources = await CachedSourceSchema.safeParseAsync(cachedData);
if (cachedSources.success) {
return {
sources: cachedSources.data.sources,
currentDateTime: {
timezone: "America/New_York",
dateTime: getCurrentDateTime({ timezone: "America/New_York" }),
},
};
}

const { data: response, error: responseError } = await tryCatch(
exaSearchAndContents(args.query, {
numResults: NUM_RESULTS,
Expand Down Expand Up @@ -87,15 +67,6 @@ export const currentEvents = createTool({
image: result.image,
}));

// write to cache
await kv.set(
cacheKey,
{ sources },
{
ex: 60 * 10, // 10 minutes
},
);

const dateTime = getCurrentDateTime({
timezone: "America/New_York",
});
Expand Down
34 changes: 1 addition & 33 deletions packages/db/src/ai/tools/search/postition_holder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import { z } from "zod";

import type { SearchReturnType } from "./schemas";
import { createTool } from "../../../agent/tools";
import { kv } from "../../../kv";
import { getCurrentDateTime } from "../../../lib/date_time_utils";
import { tryCatch } from "../../../lib/utils";
import {
exaSearchAndContents,
formatCacheKey,
logSearchCost,
} from "../tool_helpers";
import { CachedSourceSchema } from "./schemas";
import { exaSearchAndContents, logSearchCost } from "../tool_helpers";

const NUM_RESULTS = 5;
const MAX_CHARACTERS = 3000;
Expand Down Expand Up @@ -59,23 +53,6 @@ export const positionHolder = createTool({
),
}),
execute: async (ctx, args): Promise<SearchReturnType> => {
// check cache
const cacheKey = formatCacheKey("position-holder", [
args.position,
args.group,
]);
const cachedData = await kv.get(cacheKey);
const cachedResult = await CachedSourceSchema.safeParseAsync(cachedData);
if (cachedResult.success) {
return {
sources: cachedResult.data.sources,
currentDateTime: {
timezone: "America/New_York",
dateTime: getCurrentDateTime({ timezone: "America/New_York" }),
},
};
}

const { data: response, error: responseError } = await tryCatch(
exaSearchAndContents(args.query, {
numResults: NUM_RESULTS,
Expand All @@ -102,15 +79,6 @@ export const positionHolder = createTool({
image: result.image,
}));

// write to cache
await kv.set(
cacheKey,
{
sources,
},
{ ex: 60 * 60 }, // 1 hour
);

const dateTime = getCurrentDateTime({
timezone: "America/New_York",
});
Expand Down
3 changes: 0 additions & 3 deletions packages/db/src/ai/tools/search/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export const SourceSchema = z.object({
favicon: z.string().optional().nullable(),
image: z.string().optional().nullable(),
});
export const CachedSourceSchema = z.object({
sources: z.array(SourceSchema),
});
export type Source = z.infer<typeof SourceSchema>;

export type SearchReturnType = {
Expand Down
7 changes: 0 additions & 7 deletions packages/db/src/ai/tools/tool_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,3 @@ export async function logSearchCost(
cost: totalCost,
});
}

export function formatCacheKey(toolName: string, args: string[]) {
const formattedArgs = args.map((arg) =>
arg.replace(/[\s,]+/g, "-").toLowerCase(),
);
return `tool:${toolName}:${formattedArgs.join("_")}`;
}
32 changes: 0 additions & 32 deletions packages/db/src/ai/tools/weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { z } from "zod";
import { internal } from "../../_generated/api";
import { createTool } from "../../agent/tools";
import { env } from "../../convex.env";
import { kv } from "../../kv";
import { tryCatch } from "../../lib/utils";
import { formatCacheKey } from "./tool_helpers";

const weatherArgs = z.object({
location: z
Expand Down Expand Up @@ -77,19 +75,6 @@ function buildWeatherUrl(
}
}

function getCacheTtl(queryType: QueryType) {
switch (queryType) {
case "current-conditions":
return 60 * 10; // 10 minutes
case "daily-forecast":
return 60 * 60; // 1 hour
case "hourly-forecast":
return 60 * 10; // 10 minutes
case "last-24-hours":
return 60 * 10; // 10 minutes
}
}

async function getCoordinates(location: string) {
const geocodingResponse = await fetch(
`https://maps.googleapis.com/maps/api/geocode/json?address=${location}&key=${env.GOOGLE_API_KEY}`,
Expand Down Expand Up @@ -118,19 +103,6 @@ export const weather = createTool({
`,
inputSchema: weatherArgs,
execute: async (ctx, args) => {
// check cache
const cacheKey = formatCacheKey("weather", [
args.location,
args.queryType,
args.days.toString(),
args.unitSystem,
]);
const cachedWeather = await kv.get(cacheKey);
if (cachedWeather) {
return cachedWeather;
}

// get lat and long for location
const { data: coordinates, error: coordinatesError } = await tryCatch(
getCoordinates(args.location),
);
Expand All @@ -156,10 +128,6 @@ export const weather = createTool({
return null;
}

// write to cache
const ttl = getCacheTtl(args.queryType);
await kv.set(cacheKey, weatherData, { ex: ttl });

// log usage
if (ctx.userId) {
await ctx.runMutation(internal.user.usage.log, {
Expand Down
2 changes: 0 additions & 2 deletions packages/db/src/convex.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import {
polar,
resend,
uploadthing,
upstash,
} from "convex-env/presets";
import { v } from "convex/values";

export const env = createEnv({
...environment,
...upstash,
...uploadthing,
...resend,
...polar,
Expand Down
8 changes: 0 additions & 8 deletions packages/db/src/kv.ts

This file was deleted.

7 changes: 3 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading