add proxy in config
This commit is contained in:
@@ -22,6 +22,14 @@ class UserConfigItem:
|
|||||||
self.value = None
|
self.value = None
|
||||||
self.user_set = False
|
self.user_set = False
|
||||||
|
|
||||||
|
def clone(self):
|
||||||
|
new_config_item = UserConfigItem()
|
||||||
|
new_config_item.default_value = self.default_value
|
||||||
|
new_config_item.is_optional = self.is_optional
|
||||||
|
new_config_item.desc = self.desc
|
||||||
|
new_config_item.item_type = self.item_type
|
||||||
|
new_config_item.value = self.value
|
||||||
|
return new_config_item
|
||||||
|
|
||||||
class UserConfig:
|
class UserConfig:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
@@ -89,7 +97,9 @@ class UserConfig:
|
|||||||
raise Exception("user config key %s not exist",key)
|
raise Exception("user config key %s not exist",key)
|
||||||
|
|
||||||
if config_item.value is None:
|
if config_item.value is None:
|
||||||
return config_item.default_value
|
default_config_item = config_item.clone()
|
||||||
|
default_config_item.value = config_item.default_value
|
||||||
|
return default_config_item
|
||||||
|
|
||||||
return config_item.value
|
return config_item.value
|
||||||
|
|
||||||
|
|||||||
@@ -20,3 +20,4 @@ google-cloud-texttospeech
|
|||||||
openai
|
openai
|
||||||
Pillow
|
Pillow
|
||||||
aiosqlite
|
aiosqlite
|
||||||
|
PySocks==1.7.1
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ directory = os.path.dirname(__file__)
|
|||||||
sys.path.append(directory + '/../../')
|
sys.path.append(directory + '/../../')
|
||||||
|
|
||||||
from aios_kernel import AIOS_Version,UserConfigItem,AIStorage,Workflow,AIAgent,AgentMsg,AgentMsgStatus,ComputeKernel,OpenAI_ComputeNode,AIBus,AIChatSession,AgentTunnel,TelegramTunnel,CalenderEnvironment,Environment,EmailTunnel,LocalLlama_ComputeNode
|
from aios_kernel import AIOS_Version,UserConfigItem,AIStorage,Workflow,AIAgent,AgentMsg,AgentMsgStatus,ComputeKernel,OpenAI_ComputeNode,AIBus,AIChatSession,AgentTunnel,TelegramTunnel,CalenderEnvironment,Environment,EmailTunnel,LocalLlama_ComputeNode
|
||||||
|
import proxy
|
||||||
|
|
||||||
sys.path.append(directory + '/../../component/')
|
sys.path.append(directory + '/../../component/')
|
||||||
from agent_manager import AgentManager
|
from agent_manager import AgentManager
|
||||||
@@ -55,6 +55,7 @@ class AIOS_Shell:
|
|||||||
openai_node.declare_user_config()
|
openai_node.declare_user_config()
|
||||||
|
|
||||||
user_config.add_user_config("shell.current","last opened target and topic",True,"default@Jarvis")
|
user_config.add_user_config("shell.current","last opened target and topic",True,"default@Jarvis")
|
||||||
|
proxy.declare_user_config()
|
||||||
|
|
||||||
|
|
||||||
async def _handle_no_target_msg(self,bus:AIBus,msg:AgentMsg) -> bool:
|
async def _handle_no_target_msg(self,bus:AIBus,msg:AgentMsg) -> bool:
|
||||||
@@ -95,7 +96,7 @@ class AIOS_Shell:
|
|||||||
|
|
||||||
llama_ai_node = LocalLlama_ComputeNode()
|
llama_ai_node = LocalLlama_ComputeNode()
|
||||||
await llama_ai_node.start()
|
await llama_ai_node.start()
|
||||||
#ComputeKernel.get_instance().add_compute_node(llama_ai_node)
|
# ComputeKernel.get_instance().add_compute_node(llama_ai_node)
|
||||||
|
|
||||||
await ComputeKernel.get_instance().start()
|
await ComputeKernel.get_instance().start()
|
||||||
|
|
||||||
@@ -192,12 +193,15 @@ class AIOS_Shell:
|
|||||||
show_text = FormattedText([("class:title", f"set config failed!")])
|
show_text = FormattedText([("class:title", f"set config failed!")])
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
key = args[0]
|
key = args[0]
|
||||||
config_item = AIStorage.get_instance().get_user_config().get_config_item(key)
|
config_item = AIStorage.get_instance().get_user_config().get_user_config(key)
|
||||||
old_value = AIStorage.get_instance().get_user_config().get_value(key)
|
|
||||||
|
old_value = None
|
||||||
if config_item is not None:
|
if config_item is not None:
|
||||||
|
old_value = config_item.value
|
||||||
|
|
||||||
value = await session.prompt_async(f"{key} : {config_item.desc} \nCurrent : {old_value}\nPlease input new value:",style=shell_style)
|
value = await session.prompt_async(f"{key} : {config_item.desc} \nCurrent : {old_value}\nPlease input new value:",style=shell_style)
|
||||||
AIStorage.get_instance().get_user_config().set_value(key,value)
|
AIStorage.get_instance().get_user_config().set_user_config(key,value)
|
||||||
await AIStorage.get_instance().get_user_config().save_to_user_config()
|
await AIStorage.get_instance().get_user_config().save_value_to_user_config()
|
||||||
show_text = FormattedText([("class:title", f"set {key} to {value} success!")])
|
show_text = FormattedText([("class:title", f"set {key} to {value} success!")])
|
||||||
|
|
||||||
return show_text
|
return show_text
|
||||||
@@ -390,6 +394,8 @@ async def main():
|
|||||||
if is_daemon:
|
if is_daemon:
|
||||||
return await main_daemon_loop(shell)
|
return await main_daemon_loop(shell)
|
||||||
|
|
||||||
|
proxy.apply_storage()
|
||||||
|
|
||||||
#TODO: read last input config
|
#TODO: read last input config
|
||||||
completer = WordCompleter(['/send $target $msg $topic',
|
completer = WordCompleter(['/send $target $msg $topic',
|
||||||
'/open $target $topic',
|
'/open $target $topic',
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
import socket
|
||||||
|
import socks
|
||||||
|
|
||||||
|
directory = os.path.dirname(__file__)
|
||||||
|
sys.path.append(directory + '/../../')
|
||||||
|
|
||||||
|
from aios_kernel import AIStorage
|
||||||
|
|
||||||
|
def apply_storage():
|
||||||
|
proxy_cfg = AIStorage.get_instance().get_user_config().get_user_config("proxy")
|
||||||
|
if proxy_cfg is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
host_url = proxy_cfg.value
|
||||||
|
if host_url is not None:
|
||||||
|
(proxy_type, host) = host_url.split("@")
|
||||||
|
match proxy_type:
|
||||||
|
case "socks5":
|
||||||
|
(host, port) = host.split(":")
|
||||||
|
socks.set_default_proxy(socks.SOCKS5, host, int(port))
|
||||||
|
socket.socket = socks.socksocket
|
||||||
|
print("proxy {host_url} will be used.")
|
||||||
|
case _:
|
||||||
|
print("the proxy type ({proxy_type}) has not support.")
|
||||||
|
|
||||||
|
def declare_user_config():
|
||||||
|
user_config = AIStorage.get_instance().get_user_config()
|
||||||
|
user_config.add_user_config("proxy", "set your proxy service as 'proxy_type@host:port', 'proxy_type' = 'socks5'", True, None)
|
||||||
Reference in New Issue
Block a user