Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include agent personality through subtasks and support custom agents #916

Merged
merged 16 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
bdf267f
Initialize changes to introduce the agent personality into the contex…
sabaimran Sep 16, 2024
4ffcc0e
Merge branch 'master' of github.com:khoj-ai/khoj into features/weave-…
sabaimran Sep 16, 2024
5b7bc46
Add agents personality to extract_references flow as well, for each r…
sabaimran Sep 16, 2024
61a5446
Merge branch 'master' of github.com:khoj-ai/khoj into features/weave-…
sabaimran Sep 16, 2024
32b14c3
Merge branch 'master' of github.com:khoj-ai/khoj into features/weave-…
sabaimran Sep 17, 2024
ab3d8d1
Merge branch 'master' of github.com:khoj-ai/khoj into features/weave-…
sabaimran Sep 19, 2024
2615f9d
break up pypicollectstatic steps into a separate gh action step
sabaimran Sep 19, 2024
ee7431a
Use rsync when copying generated static files to avoid duplicates
sabaimran Sep 19, 2024
ee96bd3
Fix filepath for outputted static assets
sabaimran Sep 19, 2024
aed0651
Merge branch 'master' of github.com:khoj-ai/khoj into features/weave-…
sabaimran Sep 24, 2024
4d87c9e
Correct the formatting for extract questions
sabaimran Sep 28, 2024
fe9ca01
Merge branch 'master' of github.com:khoj-ai/khoj into features/weave-…
sabaimran Oct 1, 2024
6795b99
Merge branch 'master' of github.com:khoj-ai/khoj into features/weave-…
sabaimran Oct 3, 2024
d067983
Add support for personal agents with custom knowledge bases (#928)
sabaimran Oct 7, 2024
cbd88c7
Merge branch 'master' of github.com:khoj-ai/khoj into features/weave-…
sabaimran Oct 7, 2024
7ba348d
Merge branch 'features/weave-agent-personality-through-subtasks' of g…
sabaimran Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,512 changes: 1,381 additions & 131 deletions src/interface/web/app/agents/page.tsx

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/interface/web/app/common/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ export interface SyncedContent {
github: boolean;
notion: boolean;
}

export enum SubscriptionStates {
EXPIRED = "expired",
TRIAL = "trial",
SUBSCRIBED = "subscribed",
UNSUBSCRIBED = "unsubscribed",
INVALID = "invalid",
}

export interface UserConfig {
// user info
username: string;
Expand All @@ -58,7 +67,7 @@ export interface UserConfig {
voice_model_options: ModelOptions[];
selected_voice_model_config: number;
// user billing info
subscription_state: string;
subscription_state: SubscriptionStates;
subscription_renewal_date: string;
// server settings
khoj_cloud_subscription_url: string | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/interface/web/app/common/colorUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const tailwindColors = [
export const tailwindColors = [
"red",
"yellow",
"green",
Expand Down
112 changes: 111 additions & 1 deletion src/interface/web/app/common/iconUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ import {
Wallet,
PencilLine,
Chalkboard,
Gps,
Question,
Browser,
Notebook,
Shapes,
ChatsTeardrop,
GlobeSimple,
ArrowRight,
Cigarette,
CraneTower,
Heart,
Leaf,
NewspaperClipping,
OrangeSlice,
Rainbow,
SmileyMelting,
YinYang,
SneakerMove,
Student,
Oven,
Gavel,
Broadcast,
} from "@phosphor-icons/react";
import { Markdown, OrgMode, Pdf, Word } from "@/app/components/logo/fileLogo";

Expand Down Expand Up @@ -103,8 +125,92 @@ const iconMap: IconMap = {
Chalkboard: (color: string, width: string, height: string) => (
<Chalkboard className={`${width} ${height} ${color} mr-2`} />
),
Cigarette: (color: string, width: string, height: string) => (
<Cigarette className={`${width} ${height} ${color} mr-2`} />
),
CraneTower: (color: string, width: string, height: string) => (
<CraneTower className={`${width} ${height} ${color} mr-2`} />
),
Heart: (color: string, width: string, height: string) => (
<Heart className={`${width} ${height} ${color} mr-2`} />
),
Leaf: (color: string, width: string, height: string) => (
<Leaf className={`${width} ${height} ${color} mr-2`} />
),
NewspaperClipping: (color: string, width: string, height: string) => (
<NewspaperClipping className={`${width} ${height} ${color} mr-2`} />
),
OrangeSlice: (color: string, width: string, height: string) => (
<OrangeSlice className={`${width} ${height} ${color} mr-2`} />
),
SmileyMelting: (color: string, width: string, height: string) => (
<SmileyMelting className={`${width} ${height} ${color} mr-2`} />
),
YinYang: (color: string, width: string, height: string) => (
<YinYang className={`${width} ${height} ${color} mr-2`} />
),
SneakerMove: (color: string, width: string, height: string) => (
<SneakerMove className={`${width} ${height} ${color} mr-2`} />
),
Student: (color: string, width: string, height: string) => (
<Student className={`${width} ${height} ${color} mr-2`} />
),
Oven: (color: string, width: string, height: string) => (
<Oven className={`${width} ${height} ${color} mr-2`} />
),
Gavel: (color: string, width: string, height: string) => (
<Gavel className={`${width} ${height} ${color} mr-2`} />
),
Broadcast: (color: string, width: string, height: string) => (
<Broadcast className={`${width} ${height} ${color} mr-2`} />
),
};

export function getIconForSlashCommand(command: string, customClassName: string | null = null) {
const className = customClassName ?? "h-4 w-4";
if (command.includes("summarize")) {
return <Gps className={className} />;
}

if (command.includes("help")) {
return <Question className={className} />;
}

if (command.includes("automation")) {
return <Robot className={className} />;
}

if (command.includes("webpage")) {
return <Browser className={className} />;
}

if (command.includes("notes")) {
return <Notebook className={className} />;
}

if (command.includes("image")) {
return <Image className={className} />;
}

if (command.includes("default")) {
return <Shapes className={className} />;
}

if (command.includes("general")) {
return <ChatsTeardrop className={className} />;
}

if (command.includes("online")) {
return <GlobeSimple className={className} />;
}

if (command.includes("text")) {
return <PencilLine className={className} />;
}

return <ArrowRight className={className} />;
}

function getIconFromIconName(
iconName: string,
color: string = "gray",
Expand Down Expand Up @@ -141,4 +247,8 @@ function getIconFromFilename(
}
}

export { getIconFromIconName, getIconFromFilename };
function getAvailableIcons() {
return Object.keys(iconMap);
}

export { getIconFromIconName, getIconFromFilename, getAvailableIcons };
4 changes: 2 additions & 2 deletions src/interface/web/app/components/chatHistory/chatHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { InlineLoading } from "../loading/loading";

import { Lightbulb, ArrowDown } from "@phosphor-icons/react";

import ProfileCard from "../profileCard/profileCard";
import AgentProfileCard from "../profileCard/profileCard";
import { getIconFromIconName } from "@/app/common/iconUtils";
import { AgentData } from "@/app/agents/page";
import React from "react";
Expand Down Expand Up @@ -350,7 +350,7 @@ export default function ChatHistory(props: ChatHistoryProps) {
{data && (
<div className={`${styles.agentIndicator} pb-4`}>
<div className="relative group mx-2 cursor-pointer">
<ProfileCard
<AgentProfileCard
name={constructAgentName()}
link={constructAgentLink()}
avatar={
Expand Down
47 changes: 6 additions & 41 deletions src/interface/web/app/components/chatInputArea/chatInputArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { convertToBGClass } from "@/app/common/colorUtils";
import LoginPrompt from "../loginPrompt/loginPrompt";
import { uploadDataForIndexing } from "../../common/chatFunctions";
import { InlineLoading } from "../loading/loading";
import { getIconForSlashCommand } from "@/app/common/iconUtils";

export interface ChatOptions {
[key: string]: string;
Expand Down Expand Up @@ -193,46 +194,6 @@ export default function ChatInputArea(props: ChatInputProps) {
);
}

function getIconForSlashCommand(command: string) {
const className = "h-4 w-4 mr-2";
if (command.includes("summarize")) {
return <Gps className={className} />;
}

if (command.includes("help")) {
return <Question className={className} />;
}

if (command.includes("automation")) {
return <Robot className={className} />;
}

if (command.includes("webpage")) {
return <Browser className={className} />;
}

if (command.includes("notes")) {
return <Notebook className={className} />;
}

if (command.includes("image")) {
return <Image className={className} />;
}

if (command.includes("default")) {
return <Shapes className={className} />;
}

if (command.includes("general")) {
return <ChatsTeardrop className={className} />;
}

if (command.includes("online")) {
return <GlobeSimple className={className} />;
}
return <ArrowRight className={className} />;
}

// Assuming this function is added within the same context as the provided excerpt
async function startRecordingAndTranscribe() {
try {
Expand Down Expand Up @@ -426,7 +387,11 @@ export default function ChatInputArea(props: ChatInputProps) {
>
<div className="grid grid-cols-1 gap-1">
<div className="font-bold flex items-center">
{getIconForSlashCommand(key)}/{key}
{getIconForSlashCommand(
key,
"h-4 w-4 mr-2",
)}
/{key}
</div>
<div>{value}</div>
</div>
Expand Down
7 changes: 3 additions & 4 deletions src/interface/web/app/components/profileCard/profileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ interface ProfileCardProps {
description?: string; // Optional description field
}

const ProfileCard: React.FC<ProfileCardProps> = ({ name, avatar, link, description }) => {
const AgentProfileCard: React.FC<ProfileCardProps> = ({ name, avatar, link, description }) => {
return (
<div className="relative group flex">
<TooltipProvider>
<Tooltip>
<Tooltip delayDuration={0}>
<TooltipTrigger asChild>
<Button variant="ghost" className="flex items-center justify-center">
{avatar}
Expand All @@ -24,7 +24,6 @@ const ProfileCard: React.FC<ProfileCardProps> = ({ name, avatar, link, descripti
</TooltipTrigger>
<TooltipContent>
<div className="w-80 h-30">
{/* <div className="absolute left-0 bottom-full w-80 h-30 p-2 pb-4 bg-white border border-gray-300 rounded-lg shadow-lg opacity-0 group-hover:opacity-100 transition-opacity duration-300"> */}
<a
href={link}
target="_blank"
Expand Down Expand Up @@ -52,4 +51,4 @@ const ProfileCard: React.FC<ProfileCardProps> = ({ name, avatar, link, descripti
);
};

export default ProfileCard;
export default AgentProfileCard;
14 changes: 11 additions & 3 deletions src/interface/web/app/components/shareLink/shareLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ interface ShareLinkProps {
title: string;
description: string;
url: string;
onShare: () => void;
buttonVariant?: keyof typeof buttonVariants;
onShare?: () => void;
buttonVariant?:
| "default"
| "destructive"
| "outline"
| "secondary"
| "ghost"
| "link"
| null
| undefined;
includeIcon?: boolean;
buttonClassName?: string;
}
Expand All @@ -38,7 +46,7 @@ export default function ShareLink(props: ShareLinkProps) {
<Button
size="sm"
className={`${props.buttonClassName || "px-3"}`}
variant={props.buttonVariant ?? ("default" as const)}
variant={props.buttonVariant ?? "default"}
>
{props.includeIcon && <Share className="w-4 h-4 mr-2" />}
{props.buttonTitle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ interface ChatHistory {
conversation_id: string;
slug: string;
agent_name: string;
agent_avatar: string;
compressed: boolean;
created: string;
updated: string;
Expand Down Expand Up @@ -435,7 +434,6 @@ function SessionsAndFiles(props: SessionsAndFilesProps) {
chatHistory.conversation_id
}
slug={chatHistory.slug}
agent_avatar={chatHistory.agent_avatar}
agent_name={chatHistory.agent_name}
showSidePanel={props.setEnabled}
/>
Expand Down Expand Up @@ -713,7 +711,6 @@ function ChatSessionsModal({ data, showSidePanel }: ChatSessionsModalProps) {
key={chatHistory.conversation_id}
conversation_id={chatHistory.conversation_id}
slug={chatHistory.slug}
agent_avatar={chatHistory.agent_avatar}
agent_name={chatHistory.agent_name}
showSidePanel={showSidePanel}
/>
Expand Down
13 changes: 1 addition & 12 deletions src/interface/web/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,7 @@ function ChatBodyData(props: ChatBodyDataProps) {
//generate colored icons for the selected agents
const agentIcons = agents
.filter((agent) => agent !== null && agent !== undefined)
.map(
(agent) =>
getIconFromIconName(agent.icon, agent.color) || (
<Image
key={agent.name}
src={agent.avatar}
alt={agent.name}
width={50}
height={50}
/>
),
);
.map((agent) => getIconFromIconName(agent.icon, agent.color)!);
setAgentIcons(agentIcons);
}, [agentsData, props.isMobileWidth]);

Expand Down
9 changes: 5 additions & 4 deletions src/interface/web/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "intl-tel-input/styles";
import { Suspense, useEffect, useRef, useState } from "react";
import { useToast } from "@/components/ui/use-toast";

import { useUserConfig, ModelOptions, UserConfig } from "../common/auth";
import { useUserConfig, ModelOptions, UserConfig, SubscriptionStates } from "../common/auth";
import { toTitleCase, useIsMobileWidth } from "../common/utils";

import { isValidPhoneNumber } from "libphonenumber-js";
Expand Down Expand Up @@ -276,7 +276,7 @@ const ManageFilesModal: React.FC<{ onClose: () => void }> = ({ onClose }) => {
)}
</div>
<div
className={`flex-none p-4 bg-secondary border-b ${isDragAndDropping ? "animate-pulse" : ""}`}
className={`flex-none p-4 bg-secondary border-b ${isDragAndDropping ? "animate-pulse" : ""} rounded-lg`}
>
<div className="flex items-center justify-center w-full h-32 border-2 border-dashed border-gray-300 rounded-lg">
{isDragAndDropping ? (
Expand All @@ -294,7 +294,6 @@ const ManageFilesModal: React.FC<{ onClose: () => void }> = ({ onClose }) => {
</div>
</div>
<div className="flex flex-col h-full">
<div className="flex-none p-4">Synced files</div>
<div className="flex-none p-4 bg-background border-b">
<CommandInput
placeholder="Find synced files"
Expand Down Expand Up @@ -615,7 +614,9 @@ export default function SettingsView() {
if (userConfig) {
let newUserConfig = userConfig;
newUserConfig.subscription_state =
state === "cancel" ? "unsubscribed" : "subscribed";
state === "cancel"
? SubscriptionStates.UNSUBSCRIBED
: SubscriptionStates.SUBSCRIBED;
setUserConfig(newUserConfig);
}

Expand Down
Loading
Loading