From 76b7b33ec57ed0bc8718638ac47f30efadad85e1 Mon Sep 17 00:00:00 2001 From: ranst91 Date: Fri, 16 Aug 2024 14:16:44 +0200 Subject: [PATCH] feat(proxy): enable pre configured openai base url --- .env.example | 3 +++ apps/proxy/src/lib/OpenAIHandler.ts | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 30f28e50..3f80c710 100644 --- a/.env.example +++ b/.env.example @@ -12,3 +12,6 @@ NX_BASE_API_URL="http://localhost:3000" NX_SUPERTOKENS_API_DOMAIN="http://localhost:3000" NX_SUPERTOKENS_WEBSITE_DOMAIN="http://localhost:4200" NX_DEBUG_MODE="true" + +# Pezzo config +OPENAI_API_BASE_URL="https://api.openai.com/v1" diff --git a/apps/proxy/src/lib/OpenAIHandler.ts b/apps/proxy/src/lib/OpenAIHandler.ts index 917338a3..d4511490 100644 --- a/apps/proxy/src/lib/OpenAIHandler.ts +++ b/apps/proxy/src/lib/OpenAIHandler.ts @@ -3,6 +3,8 @@ import { RequestWithPezzoClient } from "../types/common.types"; import { Response } from "express"; import axios from "axios"; +const baseUrl = process.env.OPENAI_API_BASE_URL ?? "https://api.openai.com/v1"; + export class OpenAIV1Handler { constructor(private req: RequestWithPezzoClient, private res: Response) {} @@ -16,7 +18,7 @@ export class OpenAIV1Handler { try { const result = await axios({ method, - url: `https://api.openai.com/v1/${url}`, + url: `${baseUrl}/${url}`, data: this.req.body, headers: { Authorization: headers.authorization,