From bbdfcce50c9eca734e70ada63260a70fd1aaa23d Mon Sep 17 00:00:00 2001 From: Patrick C Davis Date: Mon, 26 Feb 2024 15:28:47 -0500 Subject: [PATCH] updated to use the latest apis --- components/Chat/Chat.tsx | 5 +++-- pages/api/home/home.tsx | 2 +- pages/api/models.ts | 1 + utils/server/index.ts | 14 ++++++++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/components/Chat/Chat.tsx b/components/Chat/Chat.tsx index 2e05158a38..1cc6ed4f5c 100644 --- a/components/Chat/Chat.tsx +++ b/components/Chat/Chat.tsx @@ -29,7 +29,7 @@ import Spinner from '../Spinner'; import { ChatInput } from './ChatInput'; import { ChatLoader } from './ChatLoader'; import { ErrorMessageDiv } from './ErrorMessageDiv'; -import { ModelSelect } from './ModelSelect'; +//import { ModelSelect } from './ModelSelect'; import { SystemPrompt } from './SystemPrompt'; import { TemperatureSlider } from './Temperature'; import { MemoizedChatMessage } from './MemoizedChatMessage'; @@ -456,7 +456,8 @@ export const Chat = memo(({ stopConversationRef }: Props) => { {false && showSettings && (
- + {// + }
)} diff --git a/pages/api/home/home.tsx b/pages/api/home/home.tsx index 05a91b7926..2cc0f3d1e3 100644 --- a/pages/api/home/home.tsx +++ b/pages/api/home/home.tsx @@ -80,7 +80,7 @@ const Home = ({ ['GetModels', apiKey, serverSideApiKeyIsSet], ({ signal }) => { if (!apiKey && !serverSideApiKeyIsSet) return null; - + return {}; return getModels( { key: apiKey, diff --git a/pages/api/models.ts b/pages/api/models.ts index 11facd4081..7b7be01539 100644 --- a/pages/api/models.ts +++ b/pages/api/models.ts @@ -22,6 +22,7 @@ const handler = async (req: Request): Promise => { console.log(req.headers); const response = await fetch(url, { + method: 'post', headers: { 'Content-Type': 'application/json', ...(OPENAI_API_TYPE === 'openai' && { diff --git a/utils/server/index.ts b/utils/server/index.ts index 82799acdbd..59f804bb60 100644 --- a/utils/server/index.ts +++ b/utils/server/index.ts @@ -75,14 +75,18 @@ export const OpenAIStream = async ( temperature: temperature, stream: true, }; + + //console.log("!!!Sending to APIM!!!") + console.log("URL: " + url); + //console.log("Header: " + JSON.stringify(header)); + console.log("Messages: " +JSON.stringify(body)); const res = await fetch(url, { headers: header, - method: 'POST', + method: 'post', body: JSON.stringify(body), }); - //console.log("!!!Sending to APIM!!!") - //console.log(JSON.stringify(body)); + const encoder = new TextEncoder(); const decoder = new TextDecoder(); @@ -119,13 +123,15 @@ export const OpenAIStream = async ( if(data !== "[DONE]"){ try { const json = JSON.parse(data); - if (json.choices[0].finish_reason != null) { + if (json.choices[0] && json.choices[0].finish_reason && json.choices[0].finish_reason != null) { controller.close(); return; } + if (json.choices[0] && json.choices[0].delta) { const text = json.choices[0].delta.content; const queue = encoder.encode(text); controller.enqueue(queue); + } } catch (e) { controller.error(e + " Data: " + data); }