Skip to content

Commit

Permalink
Chore: Add knowledge description, enforce unique urls (#416)
Browse files Browse the repository at this point in the history
Signed-off-by: Daishan Peng <[email protected]>
  • Loading branch information
StrongMonkey authored Nov 1, 2024
1 parent 8239c4b commit 1bf96b1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
6 changes: 5 additions & 1 deletion ui/admin/app/components/agent/Agent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ function AgentContent({ className, onRefresh }: AgentProps) {
website, or external links in order to give it context
about various topics.
</TypographyP>
<AgentKnowledgePanel agentId={agent.id} />
<AgentKnowledgePanel
agentId={agent.id}
agent={agent}
updateAgent={debouncedSetAgentInfo}
/>
</div>
</ScrollArea>

Expand Down
35 changes: 34 additions & 1 deletion ui/admin/app/components/knowledge/AgentKnowledgePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Globe, SettingsIcon, UploadIcon } from "lucide-react";
import { useEffect, useMemo, useState } from "react";
import useSWR, { SWRResponse } from "swr";

import { Agent } from "~/lib/model/agents";
import {
KnowledgeFile,
KnowledgeFileState,
Expand All @@ -13,12 +14,24 @@ import { assetUrl } from "~/lib/utils";
import { Button } from "~/components/ui/button";

import { Avatar } from "../ui/avatar";
import { Label } from "../ui/label";
import { Textarea } from "../ui/textarea";
import FileModal from "./file/FileModal";
import { NotionModal } from "./notion/NotionModal";
import { OnedriveModal } from "./onedrive/OneDriveModal";
import { WebsiteModal } from "./website/WebsiteModal";

export default function AgentKnowledgePanel({ agentId }: { agentId: string }) {
type AgentKnowledgePanelProps = {
agentId: string;
agent: Agent;
updateAgent: (updatedAgent: Agent) => void;
};

export default function AgentKnowledgePanel({
agentId,
agent,
updateAgent,
}: AgentKnowledgePanelProps) {
const [blockPollingLocalFiles, setBlockPollingLocalFiles] = useState(false);
const [blockPollingOneDrive, setBlockPollingOneDrive] = useState(false);
const [blockPollingNotion, setBlockPollingNotion] = useState(false);
Expand All @@ -34,6 +47,10 @@ export default function AgentKnowledgePanel({ agentId }: { agentId: string }) {
const [isNotionModalOpen, setIsNotionModalOpen] = useState(false);
const [isWebsiteModalOpen, setIsWebsiteModalOpen] = useState(false);

const [knowledgeDescription, setKnowledgeDescription] = useState(
agent.knowledgeDescription
);

const getLocalFiles: SWRResponse<KnowledgeFile[], Error> = useSWR(
KnowledgeService.getLocalKnowledgeFilesForAgent.key(agentId),
({ agentId }) =>
Expand Down Expand Up @@ -347,6 +364,22 @@ export default function AgentKnowledgePanel({ agentId }: { agentId: string }) {

return (
<div className="flex flex-col gap-4 justify-center items-center">
<div className="grid w-full gap-2">
<Label htmlFor="message">Knowledge Description</Label>
<Textarea
placeholder="Provide a brief description of the information contained in this knowledge base. Example: A collection of documents about the human resources policies and procedures for Acme Corporation."
id="message"
value={knowledgeDescription ?? ""}
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => {
setKnowledgeDescription(e.target.value);
updateAgent({
...agent,
knowledgeDescription: e.target.value,
});
}}
/>
</div>

<div className="flex w-full items-center justify-between gap-3 rounded-md bg-background px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-muted-foreground/20 focus-visible:ring-transparent">
<div className="flex items-center gap-2 text-foreground">
<UploadIcon className="h-5 w-5" />
Expand Down
10 changes: 6 additions & 4 deletions ui/admin/app/components/knowledge/onedrive/AddLinkModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const AddLinkModal: FC<AddLinkModalProps> = ({
if (!knowledgeSource) {
await KnowledgeService.createKnowledgeSource(agentId, {
onedriveConfig: {
sharedLinks: [newLink],
sharedLinks: [newLink.trim()],
},
});
} else {
Expand All @@ -46,9 +46,11 @@ const AddLinkModal: FC<AddLinkModalProps> = ({
...knowledgeSource,
onedriveConfig: {
sharedLinks: [
...(knowledgeSource.onedriveConfig?.sharedLinks ||
[]),
newLink,
...(
knowledgeSource.onedriveConfig?.sharedLinks ||
[]
).filter((url) => url !== newLink.trim()),
newLink.trim(),
],
},
}
Expand Down
10 changes: 6 additions & 4 deletions ui/admin/app/components/knowledge/website/AddWebsiteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const AddWebsiteModal: FC<AddWebsiteModalProps> = ({
const formattedWebsite =
newWebsite.startsWith("http://") ||
newWebsite.startsWith("https://")
? newWebsite
: `https://${newWebsite}`;
? newWebsite.trim()
: `https://${newWebsite.trim()}`;

if (!knowledgeSource) {
await KnowledgeService.createKnowledgeSource(agentId, {
Expand All @@ -47,8 +47,10 @@ const AddWebsiteModal: FC<AddWebsiteModalProps> = ({
...knowledgeSource,
websiteCrawlingConfig: {
urls: [
...(knowledgeSource.websiteCrawlingConfig
?.urls || []),
...(
knowledgeSource.websiteCrawlingConfig
?.urls || []
).filter((url) => url !== formattedWebsite),
formattedWebsite,
],
},
Expand Down
2 changes: 1 addition & 1 deletion ui/admin/app/components/knowledge/website/WebsiteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export const WebsiteModal: FC<WebsiteModalProps> = ({
<RemoteFileItemChip
key={item.fileName}
file={item}
fileName={item.fileName}
fileName={item.url}
knowledgeSourceType={
RemoteKnowledgeSourceType.Website
}
Expand Down
2 changes: 1 addition & 1 deletion ui/admin/app/lib/model/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type AgentBase = {
workflows?: string[];
tools?: string[];
params?: Record<string, string>;
knowledgeSetStatues: KnowledgeSetStatus[];
knowledgeDescription?: string;
};

export type KnowledgeSetStatus = {
Expand Down

0 comments on commit 1bf96b1

Please sign in to comment.