From 2be2ef3f604e24f524435fd7d6699207080fba34 Mon Sep 17 00:00:00 2001 From: Song Date: Sat, 23 Sep 2023 13:19:18 +0800 Subject: [PATCH] Update code & pass test --- rootfs/agents/David/agent.toml | 1 + src/aios_kernel/agent.py | 4 ++-- src/aios_kernel/local_stability_node.py | 19 +++++++++++++------ src/aios_kernel/open_ai_node.py | 4 ++-- src/service/aios_shell/aios_shell.py | 6 ++---- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/rootfs/agents/David/agent.toml b/rootfs/agents/David/agent.toml index 47687f3..92cfcf1 100644 --- a/rootfs/agents/David/agent.toml +++ b/rootfs/agents/David/agent.toml @@ -2,6 +2,7 @@ instance_id = "David" fullname = "David" max_token_size = 16000 llm_model_name = "gpt-3.5-turbo-16k-0613" +owner_env = "calender" [[prompt]] role = "system" diff --git a/src/aios_kernel/agent.py b/src/aios_kernel/agent.py index 7681798..79e67e6 100644 --- a/src/aios_kernel/agent.py +++ b/src/aios_kernel/agent.py @@ -123,7 +123,7 @@ class AIAgent: self.unread_msg = Queue() # msg from other agent self.owner_env : Environment = None self.owenr_bus = None - self.enable_function_list = [] + self.enable_function_list = None @classmethod def create_from_templete(cls,templete:AIAgentTemplete, fullname:str): @@ -392,7 +392,7 @@ class AIAgent: prompt.append(msg_prompt) - logger.debug(f"Agent {self.agent_id} do llm token static system:{system_prompt_len},function:{function_token_len},history:{history_token_len},input:{input_len},totoal prompt:{system_prompt_len + function_token_len + history_token_len} ") + logger.debug(f"Agent {self.agent_id} do llm token static system:{system_prompt_len},function:{function_token_len},history:{history_token_len},input:{input_len}, totoal prompt:{system_prompt_len + function_token_len + history_token_len} ") task_result:ComputeTaskResult = await ComputeKernel.get_instance().do_llm_completion(prompt,self.llm_model_name,self.max_token_size,inner_functions) final_result = task_result.result_str diff --git a/src/aios_kernel/local_stability_node.py b/src/aios_kernel/local_stability_node.py index 8ee165a..77971b8 100644 --- a/src/aios_kernel/local_stability_node.py +++ b/src/aios_kernel/local_stability_node.py @@ -7,6 +7,7 @@ import base64 from PIL import Image import requests from typing import Tuple +from pathlib import Path from .compute_task import ComputeTask, ComputeTaskResult, ComputeTaskState, ComputeTaskType from .compute_node import ComputeNode @@ -27,12 +28,18 @@ class Local_Stability_ComputeNode(ComputeNode): @classmethod def declare_user_config(cls): user_config = AIStorage.get_instance().get_user_config() - user_config.add_user_config( - "local_stability_url", "local stability url", False, None) - user_config.add_user_config( - "text2img_output_dir", "output dir", True, "./") - user_config.add_user_config( - "text2img_default_model", "text2img default model", True, "v1-5-pruned-emaonly") + if os.getenv("LOCAL_STABILITY_URL") is None: + user_config.add_user_config( + "local_stability_url", "local stability url", False, None) + if os.getenv("TEXT2IMG_OUTPUT_DIR") is None: + home_dir = Path.home() + output_dir = Path.joinpath(home_dir, "text2img_output") + Path.mkdir(output_dir, exist_ok=True) + user_config.add_user_config( + "text2img_output_dir", "text2image output dir", True, output_dir) + if os.getenv("TEXT2IMG_DEFAULT_MODEL") is None: + user_config.add_user_config( + "text2img_default_model", "text2img default model", True, "v1-5-pruned-emaonly") def __init__(self) -> None: super().__init__() diff --git a/src/aios_kernel/open_ai_node.py b/src/aios_kernel/open_ai_node.py index e610be7..bf226df 100644 --- a/src/aios_kernel/open_ai_node.py +++ b/src/aios_kernel/open_ai_node.py @@ -106,14 +106,14 @@ class OpenAI_ComputeNode(ComputeNode): logger.info(f"call openai {mode_name} prompts: {prompts}") resp = openai.ChatCompletion.create(model=mode_name, messages=prompts, - max_tokens=result_token, + #max_tokens=result_token, temperature=0.7) else: logger.info(f"call openai {mode_name} prompts: {prompts} functions: {json.dumps(llm_inner_functions)}") resp = openai.ChatCompletion.create(model=mode_name, messages=prompts, functions=llm_inner_functions, - max_tokens=result_token, + #max_tokens=result_token, temperature=0.7) # TODO: add temperature to task params? diff --git a/src/service/aios_shell/aios_shell.py b/src/service/aios_shell/aios_shell.py index a7a003e..69d9b54 100644 --- a/src/service/aios_shell/aios_shell.py +++ b/src/service/aios_shell/aios_shell.py @@ -63,6 +63,8 @@ class AIOS_Shell: google_text_to_speech = GoogleTextToSpeechNode.get_instance() google_text_to_speech.declare_user_config() + Local_Stability_ComputeNode.declare_user_config() + async def _handle_no_target_msg(self,bus:AIBus,msg:AgentMsg) -> bool: target_id = msg.target.split(".")[0] @@ -86,10 +88,6 @@ class AIOS_Shell: return False async def initial(self) -> bool: - os.environ["LOCAL_STABILITY_URL"] = "http://192.168.100.79:7866" - os.environ["TEXT2IMG_DEFAULT_MODEL"] = "v1-5-pruned-emaonly" - os.environ["TEXT2IMG_OUTPUT_DIR"] = "./" - cal_env = CalenderEnvironment("calender") await cal_env.start() Environment.set_env_by_id("calender",cal_env)