From b7e26ba18ffee819d58759361a3d8e831bc4146a Mon Sep 17 00:00:00 2001 From: Hk-Gosuto Date: Tue, 25 Feb 2025 13:14:22 +0800 Subject: [PATCH] fix: vercel edge function size limit --- app/api/search/route.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/api/search/route.ts b/app/api/search/route.ts index 310a0c863..d0edc9bd2 100644 --- a/app/api/search/route.ts +++ b/app/api/search/route.ts @@ -2,7 +2,6 @@ import { getServerSideConfig } from "@/app/config/server"; import { NextRequest, NextResponse } from "next/server"; import { auth } from "../auth"; import { ModelProvider } from "@/app/constant"; -import { tavily } from "@tavily/core"; const serverConfig = getServerSideConfig(); @@ -46,12 +45,26 @@ async function handle(req: NextRequest) { }, ); } - const tvly = tavily({ apiKey: tavilyApiKey }); - const response = await tvly.search(query, { - maxResults: maxReturns, + const response = await fetch("https://api.tavily.com/search", { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${tavilyApiKey}`, + }, + body: JSON.stringify({ + query: query, + max_results: maxReturns, + }), }); - return NextResponse.json(response); + if (!response.ok) { + throw new Error( + `Tavily API request failed with status ${response.status}`, + ); + } + + const data = await response.json(); + return NextResponse.json(data); } catch (error) { console.error("[Tavily] search error:", error); return NextResponse.json(