Skip to content

Commit

Permalink
Merge pull request #24 from smallcloudai/openai-api-update
Browse files Browse the repository at this point in the history
Openai api update
  • Loading branch information
MarcMcIntosh authored May 16, 2024
2 parents 5bf93ab + 02733aa commit ff64a57
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "refact-chat-js",
"version": "1.0.1-alpha.0",
"version": "1.0.1-alpha.1",
"type": "module",
"license": "BSD-3-Clause",
"files": [
Expand Down
10 changes: 6 additions & 4 deletions src/hooks/useEventBusForChat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,19 @@ function formatChatResponse(
return acc.concat([[cur.delta.role, cur.delta.content]]);
}

if (acc.length === 0) {
if (acc.length === 0 && cur.delta.role) {
return acc.concat([[cur.delta.role, cur.delta.content]]);
}

const lastMessage = acc[acc.length - 1];
if (lastMessage[0] === "assistant") {
const last = acc.slice(0, -1);
const currentMessage = lastMessage[1];
return last.concat([
[cur.delta.role, currentMessage + cur.delta.content],
]);
return last.concat([["assistant", currentMessage + cur.delta.content]]);
}

if (cur.delta.role === null) {
return acc;
}

return acc.concat([[cur.delta.role, cur.delta.content]]);
Expand Down
4 changes: 2 additions & 2 deletions src/services/refact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ export function isChatContextFileMessage(
}

interface BaseDelta {
role: ChatRole;
role: ChatRole | null;
}

interface AssistantDelta extends BaseDelta {
role: "assistant";
role: "assistant" | null;
content: string;
}
interface ChatContextFileDelta extends BaseDelta {
Expand Down

0 comments on commit ff64a57

Please sign in to comment.