diff --git a/.gitignore b/.gitignore index 1630e27..ad62f70 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ config.yml gpt4_config.yml XAgentWeb/pnpm-lock.yaml XAgentWeb/pnpm-lock.yaml + +.venv/ +venv/ \ No newline at end of file diff --git a/XAgent/ai_functions/request/openai.py b/XAgent/ai_functions/request/openai.py index bdf22ae..f4e7805 100644 --- a/XAgent/ai_functions/request/openai.py +++ b/XAgent/ai_functions/request/openai.py @@ -175,6 +175,7 @@ def chatcompletion_request(**kwargs): ) try: completions = client.chat.completions.create(**chatcompletion_kwargs) + # response = json.loads(completions.model_dump_json()) response = completions.model_dump() if response["choices"][0]["finish_reason"] == "length": raise BadRequestError( @@ -204,6 +205,7 @@ def chatcompletion_request(**kwargs): chatcompletion_kwargs.update(kwargs) chatcompletion_kwargs.pop("schema_error_retry", None) completions = client.chat.completions.create(**chatcompletion_kwargs) + # response = json.loads(completions.model_dump_json()) response = completions.model_dump() else: raise e diff --git a/XAgent/function_handler.py b/XAgent/function_handler.py index 0e0b21b..0cd913f 100644 --- a/XAgent/function_handler.py +++ b/XAgent/function_handler.py @@ -164,14 +164,17 @@ def long_result_summary(self, command: dict, result): 'parse_web_text', webpage=result[:8096], prompt=command['arguments']['goals_to_browse']) result['useful_hyperlinks'] = result['useful_hyperlinks'][:3] if command['name'] == 'WebEnv_search_and_browse': - with ThreadPoolExecutor(max_workers=len(result)) as pool: - f = [] - for ret in result: - f.append(pool.submit(function_manager, 'parse_web_text', - webpage=ret['page'][:8096], prompt=command['arguments']['goals_to_browse'])) - for ret, thd in zip(result, f): - ret['page'] = thd.result() - ret['page']['useful_hyperlinks'] = ret['page']['useful_hyperlinks'][:3] + # --- START MODIFICATION --- + # Add a check to handle cases where the search returns no results. + if len(result) > 0: + with ThreadPoolExecutor(max_workers=len(result)) as pool: + f = [] + for ret in result: + f.append(pool.submit(function_manager, 'parse_web_text', + webpage=ret['page'][:8096], prompt=command['arguments']['goals_to_browse'])) + for ret, thd in zip(result, f): + ret['page'] = thd.result() + ret['page']['useful_hyperlinks'] = ret['page']['useful_hyperlinks'][:3] if isinstance(result, str) and len(result) > 2000: # need to summarize diff --git a/XAgent/workflow/plan_exec.py b/XAgent/workflow/plan_exec.py index 7f20cbb..c048bf1 100644 --- a/XAgent/workflow/plan_exec.py +++ b/XAgent/workflow/plan_exec.py @@ -175,7 +175,7 @@ def initial_plan_generation(self, agent_dispatcher): functions=[split_functions], ) - subtasks = json5.loads(new_message["function_call"]["arguments"]) + subtasks = new_message["function_call"]["arguments"] for subtask_item in subtasks["subtasks"]: subplan = plan_function_output_parser(subtask_item) diff --git a/XAgent/workflow/reflection.py b/XAgent/workflow/reflection.py index 7920ac0..8d1636c 100644 --- a/XAgent/workflow/reflection.py +++ b/XAgent/workflow/reflection.py @@ -57,6 +57,6 @@ def get_posterior_knowledge(all_plan: Plan, arguments=function_manager.get_function_schema('generate_posterior_knowledge')['parameters'] ) - data = json5.loads(new_message["arguments"]) + data = new_message["arguments"] return data \ No newline at end of file diff --git a/assets/config.yml b/assets/config.yml index a799e4c..ac18e7b 100644 --- a/assets/config.yml +++ b/assets/config.yml @@ -1,36 +1,26 @@ +# ==================================================================== +# THIS IS THE CORRECTED AND SIMPLIFIED CONFIG FILE +# ==================================================================== + api_keys: - gpt-3.5-turbo-16k: - - api_key: sk-xxxxx - api_base: https://example.com - api_type: azure - api_version: 2023-07-01-preview - engine: GPT-35-Turbo-16k - # you can use any kwargs supported by openai.ChatCompletion here - - api_key: sk-xxxxx - organization: org-xxxxxx - model: gpt-3.5-turbo-16k - gpt-4: - - api_key: sk-xxxxx - organization: org-xxxxx - model: gpt-4 - - api_key: sk-xxxxx - organization: org-xxxxxx - model: gpt-4 - gpt-4-32k: - - api_key: sk-xxxxx - organization: org-xxxxx - model: gpt-4-32k - - api_key: sk-xxxxx - organization: org-xxxxxx - model: gpt-4-32k - - -default_request_type: openai # or xagent + # We will only define the gpt-4 model, which your key should have access to. + gpt-4: + # PASTE YOUR FULL, VALID OPENAI API KEY IN THE LINE BELOW + - api_key: "sk-proj-8Hs" + model: "gpt-4" + +# Set the default request type to openai +default_request_type: openai + +# Set the default model to gpt-4, which we know you have access to. +# THIS IS THE MOST IMPORTANT FIX. default_completion_kwargs: - model: gpt-4-32k + model: "gpt-4" temperature: 0.2 request_timeout: 60 +# --- The rest of the settings are correct and can be left as is --- + enable_summary: true summary: single_action_max_length: 2048 diff --git a/docker-compose.yml b/docker-compose.yml index c0218ff..7366e94 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -63,24 +63,25 @@ services: xagent-redis: condition: service_healthy + # --- ADD THIS NEW, IMPROVED BLOCK --- xagent-mysql: - image: mysql - command: - - --default-authentication-plugin=caching_sha2_password - - --character-set-server=utf8mb4 - - --collation-server=utf8mb4_unicode_ci + image: mysql/mysql-server:latest + container_name: xagent-mysql + platform: linux/amd64 environment: MYSQL_ROOT_PASSWORD: xagent + MYSQL_DATABASE: xagent + MYSQL_ROOT_HOST: '%' ports: - "3306:3306" volumes: - ./XAgentServer/database/sql:/docker-entrypoint-initdb.d healthcheck: - # test: [ "CMD", "mysqladmin","ping", "-h", "localhost" ] - test: ["CMD-SHELL", "mysql -h localhost -u root -pxagent -e 'SELECT 1'"] - #interval: 10s - timeout: 20s - retries: 20 + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "-u", "root", "-pxagent"] + interval: 10s + timeout: 10s + retries: 10 + xagent-redis: image: redis diff --git a/dockerfiles/ToolServerNode/Dockerfile b/dockerfiles/ToolServerNode/Dockerfile index d3288bd..fe9fe86 100644 --- a/dockerfiles/ToolServerNode/Dockerfile +++ b/dockerfiles/ToolServerNode/Dockerfile @@ -8,11 +8,11 @@ WORKDIR /app RUN apt-get update -RUN apt update && apt install -y build-essential make openjdk-17-jdk-headless curl docker.io docker-compose psmisc sudo +RUN apt update && apt install -y build-essential make openjdk-21-jre-headless curl docker.io docker-compose psmisc sudo -RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple +# RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple -RUN pip install playwright && playwright install chromium && playwright install-deps +RUN pip install playwright && playwright install chromium && playwright install-deps || true COPY ToolServer/ToolServerNode/requirements.txt . diff --git a/requirements.txt b/requirements.txt index 388494a..ee0f57d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,6 @@ tiktoken tqdm uvicorn json5 -openai python-dotenv sqlalchemy tenacity @@ -28,4 +27,7 @@ pinecone-client websockets cryptography inputimeout -pytest \ No newline at end of file +pytest +pinecone +openai +httpx \ No newline at end of file