Skip to content
Open
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
5 changes: 3 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"author": "",
"license": "ISC",
"dependencies": {
"@ai-sdk/openai": "^0.0.45",
"@ai-sdk/anthropic": "^1.1.6",
"@ai-sdk/openai": "^1.1.9",
"@notionhq/client": "^0.4.13",
"@octokit/core": "^4.2.0",
"@sendgrid/mail": "^7.4.6",
"@supabase/supabase-js": "^2.31.0",
"@upstash/ratelimit": "^1.1.3",
"@vercel/kv": "^1.0.1",
"ai": "^3.3.6",
"ai": "^4.1.21",
"ajv": "^8.12.0",
"axios": "^0.27.2",
"csv-parse": "^5.3.6",
Expand Down
16 changes: 8 additions & 8 deletions api/prompt/_shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { streamText } from "ai";
import { stripe } from "../_lib/_stripe";
import { kv } from "@vercel/kv";
import { Ratelimit } from "@upstash/ratelimit";
import { createOpenAI, type openai as OpenAI } from "@ai-sdk/openai";
import { createAnthropic } from "@ai-sdk/anthropic";

export const reqSchema = z.object({
prompt: z.string().min(1),
Expand Down Expand Up @@ -94,18 +94,18 @@ export async function processRequest(
req: Request,
systemMessage: string,
content: string,
model: Parameters<typeof OpenAI.chat>[0] = "gpt-4-turbo"
model = "claude-3-5-sonnet-latest"
) {
const { isPro, customerId } = await checkUserStatus(req);
const rateLimitResponse = await handleRateLimit(req, isPro, customerId);
if (rateLimitResponse) return rateLimitResponse;

const openai = createOpenAI({
apiKey: getOpenAiApiKey(isPro),
const anthropic = createAnthropic({
apiKey: getAnthropicApiKey(isPro),
});

const result = await streamText({
model: openai.chat(model),
model: anthropic(model),
system: systemMessage,
temperature: 1,
messages: [
Expand All @@ -124,12 +124,12 @@ export async function processRequest(
* so we can track usage. Bear in mind a development key is used for
* anything that's not production.
*/
function getOpenAiApiKey(isPro: boolean) {
function getAnthropicApiKey(isPro: boolean) {
if (isPro) {
return process.env.OPENAI_API_KEY_PRO;
return process.env.ANTHROPIC_API_KEY_PRO;
}

return process.env.OPENAI_API_KEY_FREE;
return process.env.ANTHROPIC_API_KEY_FREE;
}

function getIp(req: Request) {
Expand Down
12 changes: 10 additions & 2 deletions api/prompt/choose-template.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { templateRateLimit } from "./_shared";
import { generateObject } from "ai";
import { openai } from "@ai-sdk/openai";
import { createAnthropic } from "@ai-sdk/anthropic";
import { templates } from "shared";

const schema = z.object({
Expand All @@ -28,8 +28,16 @@ export default async function handler(req: Request) {
return new Response(JSON.stringify(parsed.error), { status: 400 });
}

if (!process.env.ANTHROPIC_API_KEY_FREE) {
throw new Error("No Anthropic API key provided");
}

const anthropic = createAnthropic({
apiKey: process.env.ANTHROPIC_API_KEY_FREE,
});

const result = await generateObject({
model: openai("gpt-3.5-turbo"),
model: anthropic("claude-3-5-sonnet-latest"),
schema,
prompt: getContent(parsed.data.prompt),
system: systemMessage,
Expand Down
5 changes: 3 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"screenshot-templates": "node scripts/screenshot-templates.mjs"
},
"dependencies": {
"@ai-sdk/openai": "^0.0.37",
"@ai-sdk/anthropic": "^1.1.6",
"@ai-sdk/openai": "^1.1.9",
"@formkit/auto-animate": "1.0.0-beta.6",
"@lingui/core": "^3.8.9",
"@lingui/react": "^3.8.9",
Expand Down Expand Up @@ -61,7 +62,7 @@
"@svgr/webpack": "^6.3.1",
"@tone-row/slang": "^1.2.35",
"@tone-row/strip-comments": "^2.0.1",
"ai": "^3.2.32",
"ai": "^4.1.21",
"buffer": "^6.0.3",
"classnames": "^2.3.2",
"construct-style-sheets-polyfill": "^3.1.0",
Expand Down
Loading
Loading