ci: make ci happy lint the code, delete unused imports

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
yihong0618
2023-05-24 18:42:55 +08:00
parent 562d5a98cc
commit b098a48898
75 changed files with 1110 additions and 824 deletions

View File

@@ -1,15 +1,14 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from pilot.prompts.generator import PromptGenerator
from typing import Dict, List, NoReturn, Union
from pilot.configs.config import Config
from pilot.speech import say_text
import json
from typing import Dict
from pilot.agent.json_fix_llm import fix_json_using_multiple_techniques
from pilot.commands.exception_not_commands import NotCommands
import json
from pilot.configs.config import Config
from pilot.prompts.generator import PromptGenerator
from pilot.speech import say_text
def _resolve_pathlike_command_args(command_args):
@@ -25,9 +24,9 @@ def _resolve_pathlike_command_args(command_args):
def execute_ai_response_json(
prompt: PromptGenerator,
ai_response: str,
user_input: str = None,
prompt: PromptGenerator,
ai_response: str,
user_input: str = None,
) -> str:
"""
@@ -52,18 +51,14 @@ def execute_ai_response_json(
arguments = _resolve_pathlike_command_args(arguments)
# Execute command
if command_name is not None and command_name.lower().startswith("error"):
result = (
f"Command {command_name} threw the following error: {arguments}"
)
result = f"Command {command_name} threw the following error: {arguments}"
elif command_name == "human_feedback":
result = f"Human feedback: {user_input}"
else:
for plugin in cfg.plugins:
if not plugin.can_handle_pre_command():
continue
command_name, arguments = plugin.pre_command(
command_name, arguments
)
command_name, arguments = plugin.pre_command(command_name, arguments)
command_result = execute_command(
command_name,
arguments,
@@ -74,9 +69,9 @@ def execute_ai_response_json(
def execute_command(
command_name: str,
arguments,
prompt: PromptGenerator,
command_name: str,
arguments,
prompt: PromptGenerator,
):
"""Execute the command and return the result
@@ -102,13 +97,15 @@ def execute_command(
else:
for command in prompt.commands:
if (
command_name == command["label"].lower()
or command_name == command["name"].lower()
command_name == command["label"].lower()
or command_name == command["name"].lower()
):
try:
# 删除非定义参数
diff_ags = list(set(arguments.keys()).difference(set(command['args'].keys())))
for arg_name in diff_ags:
diff_ags = list(
set(arguments.keys()).difference(set(command["args"].keys()))
)
for arg_name in diff_ags:
del arguments[arg_name]
print(str(arguments))
return command["function"](**arguments)

View File

@@ -1,19 +1,21 @@
from typing import Optional
from pilot.configs.config import Config
from pilot.prompts.generator import PromptGenerator
from typing import Any, Optional, Type
from pilot.prompts.prompt import build_default_prompt_generator
class CommandsLoad:
"""
Load Plugins Commands Info , help build system prompt!
Load Plugins Commands Info , help build system prompt!
"""
def __init__(self)->None:
def __init__(self) -> None:
self.command_registry = None
def getCommandInfos(self, prompt_generator: Optional[PromptGenerator] = None)-> str:
def getCommandInfos(
self, prompt_generator: Optional[PromptGenerator] = None
) -> str:
cfg = Config()
if prompt_generator is None:
prompt_generator = build_default_prompt_generator()
@@ -24,4 +26,4 @@ class CommandsLoad:
self.prompt_generator = prompt_generator
command_infos = ""
command_infos += f"\n\n{prompt_generator.commands()}"
return command_infos
return command_infos

View File

@@ -1,5 +1,4 @@
class NotCommands(Exception):
def __init__(self, message):
super().__init__(message)
self.message = message
self.message = message

View File

@@ -25,7 +25,7 @@ def generate_image(prompt: str, size: int = 256) -> str:
str: The filename of the image
"""
filename = f"{CFG.workspace_path}/{str(uuid.uuid4())}.jpg"
# HuggingFace
if CFG.image_provider == "huggingface":
return generate_image_with_hf(prompt, filename)
@@ -72,6 +72,7 @@ def generate_image_with_hf(prompt: str, filename: str) -> str:
return f"Saved to disk:{filename}"
def generate_image_with_sd_webui(
prompt: str,
filename: str,