Skip to content

Commit

Permalink
Merge pull request #901 from TransformerOptimus/knowledge_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nborthy authored Jul 28, 2023
2 parents d978a6a + 85ba809 commit 90f6ede
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 33 deletions.
3 changes: 2 additions & 1 deletion gui/pages/Content/Knowledge/AddKnowledge.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useState, useEffect} from 'react';
import KnowledgeForm from "@/pages/Content/Knowledge/KnowledgeForm";

export default function AddKnowledge({internalId, sendKnowledgeData}) {
export default function AddKnowledge({internalId, sendKnowledgeData, sendDatabaseData}) {
const [knowledgeName, setKnowledgeName] = useState('');
const [knowledgeDescription, setKnowledgeDescription] = useState('');
const [selectedIndex, setSelectedIndex] = useState(null);
Expand Down Expand Up @@ -38,6 +38,7 @@ export default function AddKnowledge({internalId, sendKnowledgeData}) {
isEditing={false}
setIsEditing={null}
sendKnowledgeData={sendKnowledgeData}
sendDatabaseData={sendDatabaseData}
/>
</div>
<div className="col-3"></div>
Expand Down
13 changes: 7 additions & 6 deletions gui/pages/Content/Knowledge/KnowledgeDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {deleteCustomKnowledge, deleteMarketplaceKnowledge, getKnowledgeDetails}
import {removeTab} from "@/utils/utils";
import {EventBus} from "@/utils/eventBus";

export default function KnowledgeDetails({internalId, knowledgeId}) {
export default function KnowledgeDetails({internalId, knowledgeId, sendDatabaseData}) {
const [showDescription, setShowDescription] = useState(false);
const [dropdown, setDropdown] = useState(false);
const [isEditing, setIsEditing] = useState(false);
Expand All @@ -33,8 +33,8 @@ export default function KnowledgeDetails({internalId, knowledgeId}) {
.then((response) => {
console.log(response)
toast.success("Knowledge uninstalled successfully", {autoClose: 1800});
removeTab(knowledgeId, knowledgeName, "Knowledge", internalId);
EventBus.emit('reFetchKnowledge', {});
removeTab(knowledgeId, knowledgeName, "Knowledge", internalId);
EventBus.emit('reFetchKnowledge', {});
})
.catch((error) => {
toast.error("Unable to uninstall knowledge", {autoClose: 1800});
Expand All @@ -43,9 +43,9 @@ export default function KnowledgeDetails({internalId, knowledgeId}) {
} else {
deleteCustomKnowledge(knowledgeId)
.then((response) => {
toast.success("Knowledge uninstalled successfully", {autoClose: 1800});
removeTab(knowledgeId, knowledgeName, "Knowledge", internalId);
EventBus.emit('reFetchKnowledge', {});
toast.success("Knowledge uninstalled successfully", {autoClose: 1800});
removeTab(knowledgeId, knowledgeName, "Knowledge", internalId);
EventBus.emit('reFetchKnowledge', {});
})
.catch((error) => {
toast.error("Unable to uninstall knowledge", {autoClose: 1800});
Expand Down Expand Up @@ -103,6 +103,7 @@ export default function KnowledgeDetails({internalId, knowledgeId}) {
isEditing={true}
setIsEditing={setIsEditing}
sendKnowledgeData={null}
sendDatabaseData={sendDatabaseData}
/> :
<div>
<div className={styles.tools_container}>
Expand Down
26 changes: 23 additions & 3 deletions gui/pages/Content/Knowledge/KnowledgeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function KnowledgeForm({
setSelectedIndex,
isEditing,
setIsEditing,
sendDatabaseData,
sendKnowledgeData
}) {
const [addClickable, setAddClickable] = useState(true);
Expand Down Expand Up @@ -135,8 +136,13 @@ export default function KnowledgeForm({
}

const handleIndexSelect = (index) => {
setLocalStorageArray("knowledge_index_" + String(internalId), index, setSelectedIndex);
setIndexDropdown(false);

if (!checkIndexValidity(index.is_valid_state)[0]) {
return;
}

setLocalStorageArray("knowledge_index_" + String(internalId), index, setSelectedIndex);
}

const checkIndexValidity = (validState) => {
Expand Down Expand Up @@ -197,7 +203,7 @@ export default function KnowledgeForm({
<div style={!checkIndexValidity(index.is_valid_state)[0] ? {
color: '#888888',
textDecoration: 'line-through',
pointerEvents : 'none',
pointerEvents: 'none',
} : {}}>{index.name}</div>
{!checkIndexValidity(index.is_valid_state)[0] &&
<div>
Expand All @@ -214,7 +220,7 @@ export default function KnowledgeForm({
<div style={!checkIndexValidity(index.is_valid_state)[0] ? {
color: '#888888',
textDecoration: 'line-through',
pointerEvents : 'none',
pointerEvents: 'none',
} : {}}>{index.name}</div>
{!checkIndexValidity(index.is_valid_state)[0] &&
<div>
Expand All @@ -223,6 +229,20 @@ export default function KnowledgeForm({
</div>}
</div>))}
</div>}
<div className={styles1.knowledge_db}
style={{maxWidth: '100%', borderTop: '1px solid #3F3A4E'}}>
<div className="custom_select_option"
style={{padding: '12px 14px', maxWidth: '100%', borderRadius: '0'}}
onClick={() => sendDatabaseData({
id: -7,
name: "new database",
contentType: "Add_Database",
internalId: createInternalId()
})}>
<Image width={15} height={15} src="/images/plus_symbol.svg" alt="add-icon"/>&nbsp;&nbsp;Add
vector database
</div>
</div>
</div>}
</div>
</div>
Expand Down
48 changes: 33 additions & 15 deletions gui/pages/Content/Marketplace/KnowledgeTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
getValidMarketplaceIndices,
installKnowledgeTemplate
} from "@/pages/api/DashboardService";
import {loadingTextEffect} from "@/utils/utils";
import {createInternalId} from "@/utils/utils";

export default function KnowledgeTemplate({template, env}) {
export default function KnowledgeTemplate({template, env, sendDatabaseData}) {
const [installed, setInstalled] = useState('');
const [dropdown, setDropdown] = useState(false);
const [templateData, setTemplateData] = useState([]);
Expand Down Expand Up @@ -86,12 +86,18 @@ export default function KnowledgeTemplate({template, env}) {
}
}, []);

const handleInstallClick = (indexId) => {
const handleInstallClick = (index) => {
setIndexDropdown(false);

if (!checkIndexValidity(index.is_valid_state, index.is_valid_dimension)[0]) {
return;
}

setInstalled("Installing");

if (window.location.href.toLowerCase().includes('marketplace')) {
localStorage.setItem('knowledge_to_install', template.name);
localStorage.setItem('knowledge_index_to_install', indexId);
localStorage.setItem('knowledge_index_to_install', index.id);

if (env === 'PROD') {
window.open(`https://app.superagi.com/`, '_self');
Expand All @@ -106,13 +112,11 @@ export default function KnowledgeTemplate({template, env}) {
return;
}

setIndexDropdown(false);

installKnowledgeTemplate(template.name, indexId)
installKnowledgeTemplate(template.name, index.id)
.then((response) => {
toast.success("Knowledge installed", {autoClose: 1800});
setInstalled('Installed');
EventBus.emit('reFetchKnowledge', {});
toast.success("Knowledge installed", {autoClose: 1800});
setInstalled('Installed');
EventBus.emit('reFetchKnowledge', {});
})
.catch((error) => {
toast.error("Error installing Knowledge: ", {autoClose: 1800});
Expand Down Expand Up @@ -187,7 +191,7 @@ export default function KnowledgeTemplate({template, env}) {
<div className={styles3.knowledge_db} style={{maxWidth: '100%'}}>
<div className={styles3.knowledge_db_name}>Pinecone</div>
{pinconeIndices.map((index) => (<div key={index.id} className="custom_select_option"
onClick={() => handleInstallClick(index.id)} style={{
onClick={() => handleInstallClick(index)} style={{
padding: '12px 14px',
maxWidth: '100%',
display: 'flex',
Expand All @@ -196,7 +200,7 @@ export default function KnowledgeTemplate({template, env}) {
<div style={!checkIndexValidity(index.is_valid_state, index.is_valid_dimension)[0] ? {
color: '#888888',
textDecoration: 'line-through',
pointerEvents : 'none',
pointerEvents: 'none',
} : {}}>{index.name}</div>
{!checkIndexValidity(index.is_valid_state, index.is_valid_dimension)[0] &&
<div>
Expand All @@ -209,7 +213,7 @@ export default function KnowledgeTemplate({template, env}) {
<div className={styles3.knowledge_db} style={{maxWidth: '100%'}}>
<div className={styles3.knowledge_db_name}>Qdrant</div>
{qdrantIndices.map((index) => (<div key={index.id} className="custom_select_option"
onClick={() => handleInstallClick(index.id)} style={{
onClick={() => handleInstallClick(index)} style={{
padding: '12px 14px',
maxWidth: '100%',
display: 'flex',
Expand All @@ -218,7 +222,7 @@ export default function KnowledgeTemplate({template, env}) {
<div style={!checkIndexValidity(index.is_valid_state, index.is_valid_dimension)[0] ? {
color: '#888888',
textDecoration: 'line-through',
pointerEvents : 'none',
pointerEvents: 'none',
} : {}}>{index.name}</div>
{!checkIndexValidity(index.is_valid_state, index.is_valid_dimension)[0] &&
<div>
Expand All @@ -227,6 +231,20 @@ export default function KnowledgeTemplate({template, env}) {
</div>}
</div>))}
</div>}
<div className={styles3.knowledge_db}
style={{maxWidth: '100%', borderTop: '1px solid #3F3A4E'}}>
<div className="custom_select_option"
style={{padding: '12px 14px', maxWidth: '100%', borderRadius: '0'}}
onClick={() => sendDatabaseData({
id: -7,
name: "new database",
contentType: "Add_Database",
internalId: createInternalId()
})}>
<Image width={15} height={15} src="/images/plus_symbol.svg" alt="add-icon"/>&nbsp;&nbsp;Add
vector database
</div>
</div>
</div>}
</div>
</div>}
Expand Down Expand Up @@ -306,7 +324,7 @@ export default function KnowledgeTemplate({template, env}) {
<div style={{overflowY: 'scroll', height: '84vh'}}>
<div className={styles2.left_container}
style={{marginBottom: '5px', color: 'white', padding: '16px'}}>
<span className={styles2.description_text}>Overview</span><br/>
<span className="text_20_bold">Overview</span><br/>
{/*{templateData?.overview.map((item, index) => (<div key={index} style={{marginTop: '0'}}>*/}
{/* <div className={styles2.description_text}>{index + 1}. {item || ''}</div>*/}
{/* {index !== item.length - 1}*/}
Expand Down
5 changes: 3 additions & 2 deletions gui/pages/Content/Marketplace/Market.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import AgentTemplate from "./AgentTemplate";
import KnowledgeTemplate from "./KnowledgeTemplate";
import {setLocalStorageValue, setLocalStorageArray} from "@/utils/utils";

export default function Market({env}) {
export default function Market({env, sendDatabaseData}) {
const [activeTab, setActiveTab] = useState('market_tools');
const [itemClicked, setItemClicked] = useState(false);
const [templateData, setTemplateData] = useState([]);
Expand Down Expand Up @@ -104,7 +104,8 @@ export default function Market({env}) {
</div>
</div> : <div style={{padding: '0 3px'}}>
{detailType === 'agent_template' && <AgentTemplate env={env} template={templateData}/>}
{detailType === 'knowledge_template' && <KnowledgeTemplate env={env} template={templateData}/>}
{detailType === 'knowledge_template' &&
<KnowledgeTemplate env={env} template={templateData} sendDatabaseData={sendDatabaseData}/>}
{detailType === 'tool_template' && <ToolkitTemplate env={env} template={templateData}/>}
</div>}
</div>
Expand Down
14 changes: 9 additions & 5 deletions gui/pages/Dashboard/Content.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,29 +414,33 @@ export default function Content({env, selectedView, selectedProjectId, organisat
<div key={index}>
{selectedTab === index && <div>
{tab.contentType === 'Agents' &&
<AgentWorkspace env={env} internalId={tab.internalId || index} agentId={tab.id} agentName={tab.name}
<AgentWorkspace env={env} internalId={tab.internalId || index} agentId={tab.id}
agentName={tab.name}
selectedView={selectedView}
agents={agents} fetchAgents={getAgentList}/>}
{tab.contentType === 'Toolkits' &&
<ToolkitWorkspace env={env} internalId={tab.internalId || index}
toolkitDetails={toolkitDetails}/>}
{tab.contentType === 'Knowledge' &&
<KnowledgeDetails internalId={tab.internalId || index} knowledgeId={tab.id}/>}
<KnowledgeDetails internalId={tab.internalId || index} knowledgeId={tab.id}
sendDatabaseData={addTab}/>}
{tab.contentType === 'Database' &&
<DatabaseDetails internalId={tab.internalId || index} databaseId={tab.id}/>}
{tab.contentType === 'Settings' &&
<Settings organisationId={organisationId} sendDatabaseData={addTab}/>}
{tab.contentType === 'Marketplace' && <Market env={env} selectedView={selectedView}/>}
{tab.contentType === 'Marketplace' &&
<Market env={env} selectedView={selectedView} sendDatabaseData={addTab}/>}
{tab.contentType === 'Add_Toolkit' && <AddTool internalId={tab.internalId || index}/>}
{tab.contentType === 'Add_Knowledge' &&
<AddKnowledge internalId={tab.internalId || index} sendKnowledgeData={addTab}/>}
<AddKnowledge internalId={tab.internalId || index} sendKnowledgeData={addTab}
sendDatabaseData={addTab}/>}
{tab.contentType === 'Add_Database' &&
<AddDatabase internalId={tab.internalId || index} sendDatabaseDetailsData={addTab}/>}
{tab.contentType === 'Create_Agent' &&
<AgentTemplatesList knowledge={knowledge} internalId={tab.internalId || index}
organisationId={organisationId} sendKnowledgeData={addTab}
sendAgentData={addTab} selectedProjectId={selectedProjectId}
fetchAgents={getAgentList} toolkits={toolkits} env={env} />}
fetchAgents={getAgentList} toolkits={toolkits} env={env}/>}
{isApmOpened && tab.contentType === 'APM' && <ApmDashboard key={prevView}/>}
</div>}
</div>
Expand Down
1 change: 0 additions & 1 deletion superagi/tools/file/read_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ def _execute(self, file_name: str):
max_length = len(' '.join(file_content.split(" ")[:1000]))
return file_content[:max_length] + "\n File " + file_name + " read successfully."


0 comments on commit 90f6ede

Please sign in to comment.