Skip to content

Commit

Permalink
updated to use the latest apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick-Davis-MSFT committed Feb 26, 2024
1 parent e67d8fb commit bbdfcce
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
5 changes: 3 additions & 2 deletions components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -456,7 +456,8 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
{false && showSettings && (
<div className="flex flex-col space-y-10 md:mx-auto md:max-w-xl md:gap-6 md:py-3 md:pt-6 lg:max-w-2xl lg:px-0 xl:max-w-3xl">
<div className="flex h-full flex-col space-y-4 border-b border-neutral-200 p-4 dark:border-neutral-600 md:rounded-lg md:border">
<ModelSelect />
{// <ModelSelect />
}
</div>
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion pages/api/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const Home = ({
['GetModels', apiKey, serverSideApiKeyIsSet],
({ signal }) => {
if (!apiKey && !serverSideApiKeyIsSet) return null;

return {};
return getModels(
{
key: apiKey,
Expand Down
1 change: 1 addition & 0 deletions pages/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const handler = async (req: Request): Promise<Response> => {
console.log(req.headers);

const response = await fetch(url, {
method: 'post',
headers: {
'Content-Type': 'application/json',
...(OPENAI_API_TYPE === 'openai' && {
Expand Down
14 changes: 10 additions & 4 deletions utils/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit bbdfcce

Please sign in to comment.