Skip to content

Commit

Permalink
feat: Update to official ChatGPT API
Browse files Browse the repository at this point in the history
  • Loading branch information
sonngdev committed Mar 8, 2023
1 parent 0e88e6c commit e49777d
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import usePrevious from './hooks/usePrevious';

interface CreateChatGPTMessageResponse {
answer: string;
conversationId: string;
messageId: string;
}

Expand Down Expand Up @@ -93,7 +92,7 @@ function App() {
);
const [voices, setVoices] = useState<SpeechSynthesisVoice[]>([]);
const abortRef = useRef<AbortController | null>(null);
const conversationRef = useRef({ id: '', currentMessageId: '' });
const conversationRef = useRef({ currentMessageId: '' });
const bottomDivRef = useRef<HTMLDivElement>(null);

const availableVoices = useMemo(() => {
Expand Down Expand Up @@ -153,7 +152,7 @@ function App() {
const resetConversation = () => {
setIsProcessing(false);
setMessages(initialMessages);
conversationRef.current = { id: '', currentMessageId: '' };
conversationRef.current = { currentMessageId: '' };

window.speechSynthesis.cancel();
SpeechRecognition.abortListening();
Expand Down Expand Up @@ -261,14 +260,12 @@ function App() {
},
body: JSON.stringify({
text: finalTranscript,
conversationId: conversationRef.current.id || undefined,
parentMessageId: conversationRef.current.currentMessageId || undefined,
}),
signal: abortRef.current.signal,
})
.then((res) => res.json())
.then((res: CreateChatGPTMessageResponse) => {
conversationRef.current.id = res.conversationId;
conversationRef.current.currentMessageId = res.messageId;
setMessages((oldMessages) => [
...oldMessages,
Expand Down

0 comments on commit e49777d

Please sign in to comment.