-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Upsonic/knowledge-module
Added knowledge module
- Loading branch information
Showing
7 changed files
with
164 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ beautifulsoup4==4.12.3 | |
requests | ||
python-dotenv==1.0.0 | ||
duckduckgo-search==5.3.0 | ||
upsonic | ||
tinydb==4.8.0 | ||
upsonic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import inspect | ||
import os | ||
|
||
import upsonic | ||
from tinydb import Query | ||
from tinydb import TinyDB | ||
|
||
|
||
def delete(knowledge_name: str) -> bool: | ||
""" | ||
:param knowledge_name: str: | ||
""" | ||
folder = os.path.join(os.path.dirname(inspect.getfile(upsonic)), | ||
"upsonic_tiger_knowledge.json") | ||
db = TinyDB(folder) | ||
try: | ||
Knowledge = Query() | ||
db.remove(Knowledge.knowledge_name == knowledge_name) | ||
return True | ||
except: | ||
return False | ||
|
||
|
||
tool_name = "knowledge.delete" | ||
tool_obj = delete | ||
tool_requirements = ["tinydb==4.8.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import inspect | ||
import os | ||
|
||
import upsonic | ||
from tinydb import Query | ||
from tinydb import TinyDB | ||
|
||
|
||
def index() -> list: | ||
""" """ | ||
folder = os.path.join(os.path.dirname(inspect.getfile(upsonic)), | ||
"upsonic_tiger_knowledge.json") | ||
db = TinyDB(folder) | ||
return [knowledge["knowledge_name"] for knowledge in db.all()] | ||
|
||
|
||
tool_name = "knowledge.index" | ||
tool_obj = index | ||
tool_requirements = ["tinydb==4.8.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import inspect | ||
import os | ||
|
||
import upsonic | ||
from tinydb import Query | ||
from tinydb import TinyDB | ||
|
||
|
||
def pull(knowledge_name: str) -> str: | ||
""" | ||
:param knowledge_name: str: | ||
""" | ||
folder = os.path.join(os.path.dirname(inspect.getfile(upsonic)), | ||
"upsonic_tiger_knowledge.json") | ||
db = TinyDB(folder) | ||
Knowledge = Query() | ||
result = db.search(Knowledge.knowledge_name == knowledge_name) | ||
if result: | ||
return result[0]["description"] | ||
else: | ||
return None | ||
|
||
|
||
tool_name = "knowledge.pull" | ||
tool_obj = pull | ||
tool_requirements = ["tinydb==4.8.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import inspect | ||
import os | ||
|
||
import upsonic | ||
from tinydb import Query | ||
from tinydb import TinyDB | ||
|
||
|
||
def put(knowledge_name: str, description: str) -> bool: | ||
""" | ||
:param knowledge_name: str: | ||
:param description: str: | ||
""" | ||
folder = os.path.join(os.path.dirname(inspect.getfile(upsonic)), | ||
"upsonic_tiger_knowledge.json") | ||
db = TinyDB(folder) | ||
try: | ||
Knowledge = Query() | ||
if db.search(Knowledge.knowledge_name == knowledge_name): | ||
db.update({"description": description}, | ||
Knowledge.knowledge_name == knowledge_name) | ||
else: | ||
db.insert({ | ||
"knowledge_name": knowledge_name, | ||
"description": description | ||
}) | ||
return True | ||
except: | ||
return False | ||
|
||
|
||
tool_name = "knowledge.put" | ||
tool_obj = put | ||
tool_requirements = ["tinydb==4.8.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import inspect | ||
import os | ||
|
||
import upsonic | ||
from tinydb import Query | ||
from tinydb import TinyDB | ||
|
||
|
||
def reset() -> None: | ||
""" """ | ||
folder = os.path.join(os.path.dirname(inspect.getfile(upsonic)), | ||
"upsonic_tiger_knowledge.json") | ||
db = TinyDB(folder) | ||
try: | ||
# Empty the database | ||
db.truncate() | ||
except: | ||
print("Error occurred while resetting the knowledge database.") | ||
|
||
|
||
tool_name = "knowledge.reset" | ||
tool_obj = reset | ||
tool_requirements = ["tinydb==4.8.0"] |