Skip to content

Commit b20fc1f

Browse files
committed
fix again
1 parent c7dd2f6 commit b20fc1f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/app/(backend)/webapi/chat/vertexai/route.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { checkAuth } from '@/app/(backend)/middleware/auth';
22
import { AgentRuntime, ModelProvider } from '@/libs/agent-runtime';
33
import { LobeVertexAI } from '@/libs/agent-runtime/vertexai';
4+
import { safeParseJSON } from '@/utils/safeParseJSON';
45

56
import { POST as UniverseRoute } from '../[provider]/route';
67

@@ -16,10 +17,10 @@ import { POST as UniverseRoute } from '../[provider]/route';
1617
export const POST = checkAuth(async (req: Request, { jwtPayload }) =>
1718
UniverseRoute(req, {
1819
createRuntime: () => {
19-
const googleAuthOptions = jwtPayload.apiKey ?? process.env.VERTEXAI_CREDENTIALS ?? undefined;
20+
const googleAuthStr = jwtPayload.apiKey ?? process.env.VERTEXAI_CREDENTIALS ?? undefined;
2021

2122
const instance = LobeVertexAI.initFromVertexAI({
22-
googleAuthOptions: googleAuthOptions as any,
23+
googleAuthOptions: safeParseJSON(googleAuthStr),
2324
location: process.env.VERTEXAI_LOCATION,
2425
project: process.env.VERTEXAI_PROJECT,
2526
});

src/utils/safeParseJSON.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const safeParseJSON = <T = Record<string, any>>(text: string) => {
1+
export const safeParseJSON = <T = Record<string, any>>(text?: string) => {
22
if (typeof text !== 'string') return undefined;
33

44
let json: T;

0 commit comments

Comments
 (0)