Skip to content

Commit

Permalink
Merge branch 'ztjhz:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzt committed Apr 5, 2023
2 parents 8805849 + 7e7df20 commit 735c819
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { ShareGPTSubmitBodyInterface } from '@type/api';
import { ConfigInterface, MessageInterface } from '@type/chat';
import { isAzureEndpoint } from '@utils/api';

export const getChatCompletion = async (
endpoint: string,
messages: MessageInterface[],
config: ConfigInterface,
apiKey?: string
apiKey?: string,
customHeaders?: Record<string, string>
) => {
const headers: HeadersInit = {
'Content-Type': 'application/json',
...customHeaders,
};
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
if (isAzureEndpoint(endpoint) && apiKey) headers['api-key'] = apiKey;

const response = await fetch(endpoint, {
method: 'POST',
Expand All @@ -31,12 +35,15 @@ export const getChatCompletionStream = async (
endpoint: string,
messages: MessageInterface[],
config: ConfigInterface,
apiKey?: string
apiKey?: string,
customHeaders?: Record<string, string>
) => {
const headers: HeadersInit = {
'Content-Type': 'application/json',
...customHeaders,
};
if (apiKey) headers.Authorization = `Bearer ${apiKey}`;
if (isAzureEndpoint(endpoint) && apiKey) headers['api-key'] = apiKey;

const response = await fetch(endpoint, {
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion src/components/Chat/ChatContent/Message/MessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ const EditView = ({
>
<textarea
ref={textareaRef}
className='m-0 resize-none rounded-lg bg-transparent overflow-y-hidden focus:ring-0 focus-visible:ring-0 leading-7 w-full'
className='m-0 resize-none rounded-lg bg-transparent overflow-y-hidden focus:ring-0 focus-visible:ring-0 leading-7 w-full placeholder:text-gray-500/40'
onChange={(e) => {
_setContent(e.target.value);
}}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Menu = () => {
>
<div className='flex h-full min-h-0 flex-col'>
<div className='flex h-full w-full flex-1 items-start border-white/20'>
<nav className='flex h-full flex-1 flex-col space-y-1 p-2'>
<nav className='flex h-full flex-1 flex-col space-y-1 px-2 pt-2'>
<NewChat />
<ChatHistoryList />
<MenuOptions />
Expand Down
3 changes: 3 additions & 0 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const isAzureEndpoint = (endpoint: string) => {
return endpoint.includes('openai.azure.com');
};

0 comments on commit 735c819

Please sign in to comment.