remove /knowledge query command

This commit is contained in:
tsukasa
2023-09-28 11:05:24 +08:00
parent 7f81e25e3b
commit ecda804ca8
2 changed files with 12 additions and 18 deletions
+10 -7
View File
@@ -163,9 +163,9 @@ class KnowledgeBase:
self.store.get_object_store().put_object(object.calculate_id(), object.encode()) self.store.get_object_store().put_object(object.calculate_id(), object.encode())
await self.__do_embedding(object) await self.__do_embedding(object)
async def query_objects(self, tokens: str) -> [ObjectID]: async def query_objects(self, tokens: str, topk: int) -> [ObjectID]:
vector = await self.compute_kernel.do_text_embedding(tokens, self._default_text_model) vector = await self.compute_kernel.do_text_embedding(tokens, self._default_text_model)
return await self.store.get_vector_store(self._default_text_model).query(vector, 10) return await self.store.get_vector_store(self._default_text_model).query(vector, topk)
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:
@@ -193,8 +193,7 @@ class KnowledgeBase:
results[str(root_object_id)].append(object_id) results[str(root_object_id)].append(object_id)
else: else:
results[str(root_object_id)] = [root_object_id, object_id] results[str(root_object_id)] = [root_object_id, object_id]
content = ""
content = "*** I have provided the following known information for your reference with json format:\n"
result_desc = [] result_desc = []
for result in results.values(): for result in results.values():
# first element in result is the root object # first element in result is the root object
@@ -244,6 +243,10 @@ class KnowledgeEnvironment(Environment):
self._query, self._query,
query_param)) query_param))
async def _query(tokens: str, index: int): async def _query(self, tokens: str, index: int=0):
object_ids = await KnowledgeBase().query_objects(tokens) object_ids = await KnowledgeBase().query_objects(tokens, 4)
KnowledgeBase().tokens_from_objects(object_ids) if len(object_ids) <= index:
return "*** I have no more information for your reference.\n"
else:
content = "*** I have provided the following known information for your reference with json format:\n"
return content + KnowledgeBase().tokens_from_objects(object_ids[index:index + 1])
+1 -10
View File
@@ -320,8 +320,7 @@ 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 $query\n")])
if len(args) < 1: if len(args) < 1:
return show_text return show_text
sub_cmd = args[0] sub_cmd = args[0]
@@ -358,13 +357,6 @@ 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
prompt = AgentPrompt()
prompt.messages.append({"role": "user", "content":" ".join(args[1:])})
result = await KnowledgeBase().query_prompt(prompt)
print_formatted_text(result.as_str())
async def call_func(self,func_name, args): async def call_func(self,func_name, args):
match func_name: match func_name:
@@ -675,7 +667,6 @@ async def main():
'/contact $name', '/contact $name',
'/knowledge add email | dir', '/knowledge add email | dir',
'/knowledge journal [$topn]', '/knowledge journal [$topn]',
'/knowledge query $query'
'/set_config $key', '/set_config $key',
'/enable $feature', '/enable $feature',
'/disable $feature', '/disable $feature',