add query knowledge object in shell
This commit is contained in:
@@ -178,7 +178,7 @@ class KnowledgeBase:
|
|||||||
images = await self.store.get_vector_store(self._default_image_model).query(vector, topk)
|
images = await self.store.get_vector_store(self._default_image_model).query(vector, topk)
|
||||||
return texts + images
|
return texts + images
|
||||||
|
|
||||||
def __load_object(self, object_id: ObjectID) -> KnowledgeObject:
|
def load_object(self, object_id: ObjectID) -> KnowledgeObject:
|
||||||
if object_id.get_object_type() == ObjectType.Document:
|
if object_id.get_object_type() == ObjectType.Document:
|
||||||
return DocumentObject.decode(self.store.get_object_store().get_object(object_id))
|
return DocumentObject.decode(self.store.get_object_store().get_object(object_id))
|
||||||
if object_id.get_object_type() == ObjectType.Image:
|
if object_id.get_object_type() == ObjectType.Image:
|
||||||
@@ -210,7 +210,7 @@ class KnowledgeBase:
|
|||||||
# first element in result is the root object
|
# first element in result is the root object
|
||||||
root_object_id = result[0]
|
root_object_id = result[0]
|
||||||
if root_object_id.get_object_type() == ObjectType.Email:
|
if root_object_id.get_object_type() == ObjectType.Email:
|
||||||
email = self.__load_object(root_object_id)
|
email = self.load_object(root_object_id)
|
||||||
desc = email.get_desc()
|
desc = email.get_desc()
|
||||||
desc["type"] = "email"
|
desc["type"] = "email"
|
||||||
desc["contents"] = []
|
desc["contents"] = []
|
||||||
@@ -224,13 +224,13 @@ class KnowledgeBase:
|
|||||||
if object_id.get_object_type() == ObjectType.Chunk:
|
if object_id.get_object_type() == ObjectType.Chunk:
|
||||||
upper_list.append({"type": "text", "content": self.store.get_chunk_reader().get_chunk(object_id).read().decode("utf-8")})
|
upper_list.append({"type": "text", "content": self.store.get_chunk_reader().get_chunk(object_id).read().decode("utf-8")})
|
||||||
if object_id.get_object_type() == ObjectType.Image:
|
if object_id.get_object_type() == ObjectType.Image:
|
||||||
# image = self.__load_object(object_id)
|
# image = self.load_object(object_id)
|
||||||
desc = dict()
|
desc = dict()
|
||||||
desc["id"] = str(object_id)
|
desc["id"] = str(object_id)
|
||||||
desc["type"] = "image"
|
desc["type"] = "image"
|
||||||
upper_list.append(desc)
|
upper_list.append(desc)
|
||||||
if object_id.get_object_type() == ObjectType.Video:
|
if object_id.get_object_type() == ObjectType.Video:
|
||||||
video = self.__load_object(object_id)
|
video = self.load_object(object_id)
|
||||||
desc = video.get_desc()
|
desc = video.get_desc()
|
||||||
desc["type"] = "video"
|
desc["type"] = "video"
|
||||||
upper_list.append(desc)
|
upper_list.append(desc)
|
||||||
@@ -257,7 +257,7 @@ class KnowledgeBase:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if object_id is not None:
|
if object_id is not None:
|
||||||
return self.__load_object(ObjectID.from_base58(object_id))
|
return self.load_object(ObjectID.from_base58(object_id))
|
||||||
|
|
||||||
|
|
||||||
def bytes_from_object(self, object: KnowledgeObject) -> bytes:
|
def bytes_from_object(self, object: KnowledgeObject) -> bytes:
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class ObjectStore:
|
|||||||
self.blob = FileBlobStorage(blob_dir)
|
self.blob = FileBlobStorage(blob_dir)
|
||||||
|
|
||||||
def put_object(self, object_id: ObjectID, contents: bytes):
|
def put_object(self, object_id: ObjectID, contents: bytes):
|
||||||
|
logging.info(f"will put object: {object_id}")
|
||||||
self.blob.put(object_id, contents)
|
self.blob.put(object_id, contents)
|
||||||
|
|
||||||
def get_object(self, object_id: ObjectID) -> bytes:
|
def get_object(self, object_id: ObjectID) -> bytes:
|
||||||
|
|||||||
@@ -328,7 +328,8 @@ class AIOS_Shell:
|
|||||||
async def handle_knowledge_commands(self, args):
|
async def handle_knowledge_commands(self, args):
|
||||||
show_text = FormattedText([("class:title", "sub command not support!\n"
|
show_text = FormattedText([("class:title", "sub command not support!\n"
|
||||||
"/knowledge add email | dir\n"
|
"/knowledge add email | dir\n"
|
||||||
"/knowledge journal [$topn]\n")])
|
"/knowledge journal [$topn]\n"
|
||||||
|
"/knowledge query $object_id\n")])
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
return show_text
|
return show_text
|
||||||
sub_cmd = args[0]
|
sub_cmd = args[0]
|
||||||
@@ -365,6 +366,18 @@ class AIOS_Shell:
|
|||||||
topn = 10 if len(args) == 1 else int(args[1])
|
topn = 10 if len(args) == 1 else int(args[1])
|
||||||
journals = [str(journal) for journal in KnowledgePipline.get_instance().get_latest_journals(topn)]
|
journals = [str(journal) for journal in KnowledgePipline.get_instance().get_latest_journals(topn)]
|
||||||
print_formatted_text("\r\n".join(journals))
|
print_formatted_text("\r\n".join(journals))
|
||||||
|
if sub_cmd == "query":
|
||||||
|
if len(args) < 2:
|
||||||
|
return show_text
|
||||||
|
from knowledge import ObjectID, ObjectType
|
||||||
|
object_id = ObjectID.from_base58(args[1])
|
||||||
|
if object_id.get_object_type() == ObjectType.Image:
|
||||||
|
from PIL import Image
|
||||||
|
import io
|
||||||
|
image = KnowledgeBase().load_object(object_id)
|
||||||
|
image_data = KnowledgeBase().bytes_from_object(image)
|
||||||
|
image = Image.open(io.BytesIO(image_data))
|
||||||
|
image.show()
|
||||||
|
|
||||||
async def call_func(self,func_name, args):
|
async def call_func(self,func_name, args):
|
||||||
match func_name:
|
match func_name:
|
||||||
@@ -593,9 +606,10 @@ def print_welcome_screen():
|
|||||||
\033[1;94m\tGive your Agent a Telegram account :\033[0m /connect $agent_name
|
\033[1;94m\tGive your Agent a Telegram account :\033[0m /connect $agent_name
|
||||||
\033[1;94m\tAdd personal files to the AI Knowledge Base. \033[0m
|
\033[1;94m\tAdd personal files to the AI Knowledge Base. \033[0m
|
||||||
\t\t1) Copy your file to ~/myai/data
|
\t\t1) Copy your file to ~/myai/data
|
||||||
\t\t2) /knowlege add $dir
|
\t\t2) /knowlege add dir
|
||||||
\033[1;94m\tSearch your knowledge base :\033[0m /open Mia
|
\033[1;94m\tSearch your knowledge base :\033[0m /open Mia
|
||||||
\033[1;94m\tCheck the progress of AI reading personal data :\033[0m /knowledge journal
|
\033[1;94m\tCheck the progress of AI reading personal data :\033[0m /knowledge journal
|
||||||
|
\033[1;94m\tQuery object with ID in knowledge base :\033[0m /knowledge query $object_id
|
||||||
\033[1;94m\tOpen AI Bash (For Developer Only):\033[0m /open ai_bash
|
\033[1;94m\tOpen AI Bash (For Developer Only):\033[0m /open ai_bash
|
||||||
\033[1;94m\tEnable AIGC Feature :\033[0m /enable aigc
|
\033[1;94m\tEnable AIGC Feature :\033[0m /enable aigc
|
||||||
\033[1;94m\tEnable llama (Local LLM Kernel) :\033[0m /enable llama
|
\033[1;94m\tEnable llama (Local LLM Kernel) :\033[0m /enable llama
|
||||||
@@ -675,6 +689,7 @@ async def main():
|
|||||||
'/contact $name',
|
'/contact $name',
|
||||||
'/knowledge add email | dir',
|
'/knowledge add email | dir',
|
||||||
'/knowledge journal [$topn]',
|
'/knowledge journal [$topn]',
|
||||||
|
'/knowledge query $object_id',
|
||||||
'/set_config $key',
|
'/set_config $key',
|
||||||
'/enable $feature',
|
'/enable $feature',
|
||||||
'/disable $feature',
|
'/disable $feature',
|
||||||
|
|||||||
Reference in New Issue
Block a user