Skip to content

Commit

Permalink
Merge pull request #35 from ugh82/feature/frontend-remove-hard-link
Browse files Browse the repository at this point in the history
Remove hard link , and fix logic of streaming
  • Loading branch information
iamgreggarcia authored Aug 12, 2023
2 parents 086f07e + 58a38a5 commit 51dff09
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
OPENAI_API_KEY=YOUR_API_KEY
OPENAI_API_KEY=YOUR_API_KEY
NEXT_PUBLIC_DOCKER_URL=http://localhost:3333
2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@headlessui/react": "^1.7.15",
"@headlessui/tailwindcss": "^0.1.3",
"@heroicons/react": "^2.0.18",
"@tailwindcss/typography": "^0.5.9",
"@types/node": "20.3.1",
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6",
Expand All @@ -37,6 +38,7 @@
"sqlite3": "^5.1.6",
"tailwindcss": "3.3.2",
"typescript": "5.1.3",
"uuid": "^9.0.0",
"winston": "^3.9.0"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/pages/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function Chat() {
console.log('formData: ', formData);

try {
const response = await fetch('http://localhost:3333/upload', {
const response = await fetch(`${process.env.NEXT_PUBLIC_DOCKER_URL}/upload`, {
method: 'POST',
body: formData
});
Expand All @@ -71,7 +71,7 @@ export default function Chat() {

const onDeleteFile = async () => {
try {
const response = await fetch(`http://localhost:3333/delete-file?fileName=${uploadedFileName}`, {
const response = await fetch(`${process.env.NEXT_PUBLIC_DOCKER_URL}/delete-file?fileName=${uploadedFileName}`, {
method: 'DELETE',
});

Expand Down Expand Up @@ -113,7 +113,7 @@ export default function Chat() {

if (reader) {
while (!done) {
setMessageIsStreaming(true);

if (cancelStreamRef.current === true) {
abortController.abort();
done = true;
Expand Down Expand Up @@ -168,7 +168,7 @@ export default function Chat() {
}
}
}
setMessageIsStreaming(false);

}

return assistantMessageContent;
Expand Down Expand Up @@ -225,7 +225,7 @@ export default function Chat() {
// throw new Error('Endpoint is undefined');
const functionCallMessage: Message = { role: 'assistant', content: `I'm sorry, I used the incorret function name '${functionName}'. Let me try again:\n` };
setMessages(prevMessages => [...prevMessages, functionCallMessage]);
fetchChat([...messages, functionCallMessage], abortController);
await fetchChat([...messages, functionCallMessage], abortController);
} else {
console.log('endpoint: ', endpoint)
const pluginResponse = await fetch(`${serverUrl}${endpoint}`, {
Expand All @@ -239,7 +239,7 @@ export default function Chat() {
console.log('parsedFunctionCallResponse.result: ', parsedFunctionCallResponse.result ?? '')
const functionCallMessage: Message = { role: 'function', name: functionName, content: `result: ${parsedFunctionCallResponse.result}` ?? 'result: ok' };
setMessages(prevMessages => [...prevMessages, functionCallMessage]);
fetchChat([...messages, functionCallMessage], abortController);
await fetchChat([...messages, functionCallMessage], abortController);
}
}
} catch (error) {
Expand Down

0 comments on commit 51dff09

Please sign in to comment.