autogen改变屏幕亮度
import tempfile
from autogen import ConversableAgent,config_list_from_json
from autogen.coding import LocalCommandLineCodeExecutor
from autogen import register_function
import screen_brightness_control as sbc
from typing import Annotated,Literal
Operator = Literal["change"]
def change_brightness(value:int,operator: Annotated[Operator, "operator"]) ->str:
sbc.set_brightness(value)
return 'change successfully'
def main():
config_list = config_list_from_json(env_or_file='OAI_CONFIG_LIST')
temp_dir = tempfile.TemporaryDirectory()
#定义assistant
assistant_agent_system_message = "You are a helpful AI assistant. "
"You can help with change brightness on my device. "
"Return 'TERMINATE' when the task is done."
assistant_agent = ConversableAgent(
"assisant",
llm_config={'config_list':config_list},
system_message=assistant_agent_system_message,
code_execution_config=False,
)
executor = LocalCommandLineCodeExecutor(
timeout=10,
work_dir=temp_dir.name,
)
user_proxy_agent = ConversableAgent(
"user-proxy",
code_execution_config={
'executor': executor,
},
human_input_mode="ALWAYS",
)
#注册工具
# Register the tool signature with the assistant agent.
assistant_agent.register_for_llm(name="changeScreenbrightness", description="A tool to change screen brightness")(change_brightness)
# Register the tool function with the user proxy agent.
user_proxy_agent.register_for_execution(name="changeScreenbrightness")(change_brightness)
chat_result = user_proxy_agent.initiate_chat(
assistant_agent,
message='Change brightness to 50'
)
if __name__ == '__main__':
main()