Skip to content

Commit

Permalink
Merge pull request #300 from reorproject/fix-anthropic-2
Browse files Browse the repository at this point in the history
Fix anthropic 2
  • Loading branch information
joseplayero authored Jul 6, 2024
2 parents 2baa6ef + c98b6b7 commit c5eb56d
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 370 deletions.
18 changes: 12 additions & 6 deletions electron/main/llm/models/Anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class AnthropicModelSessionService implements LLMSessionService {

const stream = await anthropic.messages.create({
model: modelName,
messages: messageHistory.map(cleanMessage) as MessageParam[],
messages: messageHistory.map(cleanMessage),
stream: true,
temperature: generationParams?.temperature,
max_tokens: generationParams?.maxTokens || 1024,
Expand All @@ -85,10 +85,16 @@ export class AnthropicModelSessionService implements LLMSessionService {
}
}

function cleanMessage(
message: ChatMessageToDisplay
): ChatCompletionMessageParam {
function cleanMessage(message: ChatMessageToDisplay): MessageParam {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { ...cleanMessage } = message;
return cleanMessage;
// check that message.content is a string and not undefined:
if (typeof message.content !== "string") {
throw new Error("Message content is not a string");
}
if (message.role === "system") {
return { role: "user", content: message.content };
} else if (message.role === "user" || message.role === "assistant") {
return { role: message.role, content: message.content };
}
throw new Error("Message role is not valid");
}
9 changes: 9 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0",
"@headlessui/react": "^1.7.19",
"@heroicons/react": "^2.1.4",
"@huggingface/hub": "^0.12.0",
"@material-tailwind/react": "^2.1.5",
"@mui/icons-material": "^5.15.15",
Expand Down Expand Up @@ -153,4 +154,4 @@
"node"
]
}
}
}
11 changes: 5 additions & 6 deletions src/components/Settings/DirectorySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const DirectorySelector: React.FC<DirectorySelectorProps> = ({
setUserDirectory(directory);
}
};

fetchDirectory();
}, []);

Expand All @@ -36,19 +35,19 @@ const DirectorySelector: React.FC<DirectorySelectorProps> = ({
window.electronStore.setVaultDirectoryForWindow(userDirectory);
setErrorMsg("");
}
}, [userDirectory]);
}, [userDirectory, setErrorMsg]);

return (
<div>
<div className="flex flex-col items-end">
<Button
className="bg-blue-300 border-none h-10 hover:bg-blue-400 cursor-pointer w-[140px] text-center pt-0 pb-0 pr-2 pl-2"
className="bg-blue-300 border-none h-10 hover:bg-blue-400 cursor-pointer w-[140px] text-center pt-0 pb-0 pr-2 pl-2"
onClick={handleDirectorySelection}
placeholder=""
placeholder={""}
>
Select Directory
</Button>
{userDirectory && (
<p className="mt-2 text-xs text-gray-100">
<p className="mt-2 text-xs text-gray-100 text-right w-full">
Selected: <strong>{userDirectory}</strong>
</p>
)}
Expand Down
Loading

0 comments on commit c5eb56d

Please sign in to comment.