Merge pull request #106 from glen0125/MVP

Fix the dall e invocation process
This commit is contained in:
Liu Zhicong
2023-12-03 21:06:44 -08:00
committed by GitHub
7 changed files with 20 additions and 9 deletions
+2
View File
@@ -19,4 +19,6 @@ For example, if a user says, "I want a painting that depicts a sunset on a summe
Then you will combine these pieces of information into an accurate prompt to pass to the "paint" function, for example: "During a summer sunset, children play on the beach with sailboats visible in the distance, and the sky displays a gradient of orange and purple." Then you will combine these pieces of information into an accurate prompt to pass to the "paint" function, for example: "During a summer sunset, children play on the beach with sailboats visible in the distance, and the sky displays a gradient of orange and purple."
After successfully creating the image, please clearly state the file path where the image is saved in your response. For instance, you might say, "The image has been successfully created and saved at the following path: /path/to/the/image.png."
Please always ensure that your creations respect the user's intentions and that you infuse your unique artistic style and creativity into your work.""" Please always ensure that your creations respect the user's intentions and that you infuse your unique artistic style and creativity into your work."""
+2
View File
@@ -477,6 +477,8 @@ class BaseAIAgent(abc.ABC):
org_msg:AgentMsg, org_msg:AgentMsg,
stack_limit = 5 stack_limit = 5
) -> ComputeTaskResult: ) -> ComputeTaskResult:
from ..frame.compute_kernel import ComputeKernel
arguments = None arguments = None
try: try:
func_name = inner_func_call_node.get("name") func_name = inner_func_call_node.get("name")
+3 -3
View File
@@ -319,9 +319,9 @@ class PaintEnvironment(Environment):
async def _paint(self, prompt, model_name = None, negative_prompt = None) -> str: async def _paint(self, prompt, model_name = None, negative_prompt = None) -> str:
err, result = await ComputeKernel.get_instance().do_text_2_image(prompt, model_name, negative_prompt) result = await ComputeKernel.get_instance().do_text_2_image(prompt, model_name, negative_prompt)
if err is not None: if result.result_code == ComputeTaskResultCode.ERROR:
return f"exec paint failed. err:{err}" return f"exec paint failed. err:{result.error_str}"
else: else:
return f'exec paint OK, saved as a local file, path is: {result.result["file"]}' return f'exec paint OK, saved as a local file, path is: {result.result["file"]}'
+2 -2
View File
@@ -240,9 +240,9 @@ class ComputeKernel:
async def do_text_2_image(self, prompt:str, model_name:Optional[str] = None, negative_prompt = None) -> ComputeTaskResult: async def do_text_2_image(self, prompt:str, model_name:Optional[str] = None, negative_prompt = None) -> ComputeTaskResult:
task = self.text_2_image(prompt,model_name, negative_prompt) task = self.text_2_image(prompt,model_name, negative_prompt)
task = await self._wait_task(task) task_result = await self._wait_task(task)
return task.result return task_result
# if task_req.state == ComputeTaskState.DONE: # if task_req.state == ComputeTaskState.DONE:
# return None, task_result # return None, task_result
@@ -14,13 +14,13 @@ from aios import ComputeTask, ComputeTaskResult, ComputeTaskState, ComputeTaskTy
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class DallE_ComputeNode(ComputeNode): class DallEComputeNode(ComputeNode):
_instance = None _instance = None
@classmethod @classmethod
def get_instance(cls): def get_instance(cls):
if cls._instance is None: if cls._instance is None:
cls._instance = DallE_ComputeNode() cls._instance = DallEComputeNode()
return cls._instance return cls._instance
@classmethod @classmethod
+7
View File
@@ -157,6 +157,13 @@ class AIOS_Shell:
openai_tts_node = OpenAITTSComputeNode.get_instance() openai_tts_node = OpenAITTSComputeNode.get_instance()
ComputeKernel.get_instance().add_compute_node(openai_tts_node) ComputeKernel.get_instance().add_compute_node(openai_tts_node)
dall_e_node = DallEComputeNode.get_instance()
if await dall_e_node.initial() is not True:
logger.error("dall-e node initial failed!")
else:
await dall_e_node.start()
ComputeKernel.get_instance().add_compute_node(dall_e_node)
llama_nodes = ComputeNodeConfig.get_instance().initial() llama_nodes = ComputeNodeConfig.get_instance().initial()
for llama_node in llama_nodes: for llama_node in llama_nodes:
llama_node.start() llama_node.start()
+2 -2
View File
@@ -8,7 +8,7 @@ import logging
import pytest import pytest
directory = os.path.dirname(__file__) directory = os.path.dirname(__file__)
sys.path.append(directory + '/../src') sys.path.append(directory + '/../src')
from aios_kernel.dall_e_compute_node import DallE_ComputeNode from aios_kernel.dall_e_compute_node import DallEComputeNode
from aios_kernel.compute_task import ComputeTaskType, ComputeTask, ComputeTaskState from aios_kernel.compute_task import ComputeTaskType, ComputeTask, ComputeTaskState
os.environ["TEXT2IMG_OUTPUT_DIR"] = "./" os.environ["TEXT2IMG_OUTPUT_DIR"] = "./"
@@ -16,7 +16,7 @@ os.environ["openai_api_key"] = ""
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_dall_e_node(propmt, model): async def test_dall_e_node(propmt, model):
node = DallE_ComputeNode.get_instance() node = DallEComputeNode.get_instance()
if await node.initial() is not True: if await node.initial() is not True:
print("node initial failed!") print("node initial failed!")
return return