Skip to content

Commit

Permalink
to: close google-bard stream output
Browse files Browse the repository at this point in the history
  • Loading branch information
UNICKCHENG committed Jul 18, 2023
1 parent 15c1eb6 commit 1cd2c0b
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions app/api/google/bard/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextRequest } from 'next/server'
import { NextRequest, NextResponse } from 'next/server'
import { cookies } from 'next/headers'
import { Bard } from "googlebard"
import { cache } from 'react'
Expand All @@ -13,22 +13,16 @@ const googlebard = async (
conversationId?: string
) => {
let bot = bard(token);
return await bot.askStream((res) => { }, prompt, conversationId);
return await bot.ask(prompt, conversationId || 'default');
}

export async function POST(req: NextRequest) {
const { prompt, conversationId } = await req.json();
const cookie = `__Secure-1PSID=${cookies().get("__Secure-1PSID")?.value}, __Secure-1PSIDTS=${cookies().get("__Secure-1PSIDTS")?.value}`;
try {
const data = await googlebard(cookie, prompt, conversationId);
return new Response(data, {
headers: {
'Content-Type': 'text/event-stream',
'Connection': 'keep-alive',
'Cache-Control': 'no-cache, no-transform',
},
});
return NextResponse.json(data);
} catch (error) {
return new Response(error, { status: 400 });
return NextResponse.json(error, { status: 400 });
}
}

1 comment on commit 1cd2c0b

@vercel
Copy link

@vercel vercel bot commented on 1cd2c0b Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.