Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

separate endpoints

Steven Teyeb8ebe12bc46
diff --git a/apps/web/app/api/ai/completion-internal/route.ts b/apps/web/app/api/ai/generate-support-title/route.ts
similarity index 79%
rename from apps/web/app/api/ai/completion-internal/route.ts
rename to apps/web/app/api/ai/generate-support-title/route.ts
index d15477621e..e270bdb8da 100644
--- a/apps/web/app/api/ai/completion-internal/route.ts
+++ b/apps/web/app/api/ai/generate-support-title/route.ts
@@ -1,7 +1,6 @@
import { anthropic } from "@/lib/anthropic";
import { DubApiError, handleAndReturnErrorResponse } from "@/lib/api/errors";
import { ratelimit } from "@/lib/upstash";
-import { ipAddress } from "@vercel/edge";
import { AnthropicStream, StreamingTextResponse } from "ai";
import { getToken } from "next-auth/jwt";
import { NextRequest } from "next/server";
@@ -21,8 +20,10 @@ export async function POST(req: NextRequest) {
});
}
- const ip = ipAddress(req);
- const { success } = await ratelimit(5, "1 m").limit(`ai-completion:${ip}`);
+ // you can only generate a support completion 3 times per minute
+ const { success } = await ratelimit(3, "1 m").limit(
+ `ai-completion:${session.sub}`,
+ );
if (!success) {
throw new DubApiError({
code: "rate_limit_exceeded",
@@ -38,7 +39,9 @@ export async function POST(req: NextRequest) {
messages: [
{
role: "user",
- content: prompt,
+ content: `Create a short but concise title that summarizes the following support request. Only return the generated title, and nothing else. Don't use quotation marks.
+
+ ${prompt}`,
},
],
model: "claude-3-sonnet-20240229",
diff --git a/apps/web/ui/layout/help/contact-form.tsx b/apps/web/ui/layout/help/contact-form.tsx
index 23e9381145..f8101b0cf4 100644
--- a/apps/web/ui/layout/help/contact-form.tsx
+++ b/apps/web/ui/layout/help/contact-form.tsx
@@ -84,7 +84,7 @@ export function ContactForm({
const { handleKeyDown } = useEnterSubmit(formRef);
const { completion, complete } = useCompletion({
- api: `/api/ai/completion-internal`,
+ api: `/api/ai/generate-support-title`,
onError: (error) => {
toast.error(error.message);
},
@@ -175,9 +175,7 @@ export function ContactForm({
value={data.message}
onBlur={() => {
if (!data.title && data.message) {
- complete(`Create a short but concise title that summarizes the following support request. Only return the generated title, and nothing else. Don't use quotation marks
-
- ${data.message}`);
+ complete(data.message);
}
}}
onChange={(e) =>