Skip to content

Commit

Permalink
provide a method for installation without code interpreter deps
Browse files Browse the repository at this point in the history
  • Loading branch information
JianxinMa committed Jun 26, 2024
1 parent 09f55d1 commit 9443170
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 23 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ cd Qwen-Agent
pip install -e ./
```

Optionally, please install the following optional dependencies if built-in GUI support is needed:
Optionally, please install the optional dependencies if built-in GUI support is needed via:
```bash
pip install -U "gradio>=4.0" "modelscope-studio>=0.2.1"
pip install -U qwen-agent[gui]
# Or install from the source via: pip install -e ./[gui]
```

## Preparation: Model Service
Expand Down
5 changes: 3 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ cd Qwen-Agent
pip install -e ./
```

如需使用内置GUI支持,请安装以下可选依赖项
如需使用内置GUI支持,请通过以下方式安装GUI相关的可选依赖项
```bash
pip install -U "gradio>=4.0" "modelscope-studio>=0.2.1"
pip install -U qwen-agent[gui]
# 或,从源代码安装最新版本: pip install -e ./[gui]
```

## 准备:模型服务
Expand Down
2 changes: 1 addition & 1 deletion qwen_agent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.0.5'
__version__ = '0.0.6'
from .agent import Agent
from .multi_agent_hub import MultiAgentHub

Expand Down
3 changes: 2 additions & 1 deletion qwen_agent/tools/amap_weather.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from typing import Dict, Optional, Union

import pandas as pd
import requests

from qwen_agent.tools.base import BaseTool, register_tool
Expand All @@ -22,6 +21,8 @@ def __init__(self, cfg: Optional[Dict] = None):

# remote call
self.url = 'https://restapi.amap.com/v3/weather/weatherInfo?city={city}&key={key}'

import pandas as pd
self.city_df = pd.read_excel(
'https://modelscope.oss-cn-beijing.aliyuncs.com/resource/agent/AMap_adcode_citycode.xlsx')

Expand Down
17 changes: 10 additions & 7 deletions qwen_agent/tools/code_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
import time
import uuid
from pathlib import Path
from typing import Dict, List, Optional, Tuple, Union
from typing import Dict, List, Optional, Union

import json5
import matplotlib
import PIL.Image
from jupyter_client import BlockingKernelClient

from qwen_agent.log import logger
from qwen_agent.settings import DEFAULT_WORKSPACE
Expand All @@ -36,7 +33,7 @@
INIT_CODE_FILE = str(Path(__file__).absolute().parent / 'resource' / 'code_interpreter_init_kernel.py')
ALIB_FONT_FILE = str(Path(__file__).absolute().parent / 'resource' / 'AlibabaPuHuiTi-3-45-Light.ttf')

_KERNEL_CLIENTS: Dict[str, BlockingKernelClient] = {}
_KERNEL_CLIENTS: dict = {}
_MISC_SUBPROCESSES: Dict[str, subprocess.Popen] = {}


Expand Down Expand Up @@ -158,7 +155,7 @@ def _fix_secure_write_for_code_interpreter(self):
if os.path.exists(fname):
os.remove(fname)

def _start_kernel(self, kernel_id: str) -> Tuple[BlockingKernelClient, subprocess.Popen]:
def _start_kernel(self, kernel_id: str):
connection_file = os.path.join(self.work_dir, f'kernel_connection_file_{kernel_id}.json')
launch_kernel_script = os.path.join(self.work_dir, f'launch_kernel_{kernel_id}.py')
for f in [connection_file, launch_kernel_script]:
Expand Down Expand Up @@ -197,14 +194,16 @@ def _start_kernel(self, kernel_id: str) -> Tuple[BlockingKernelClient, subproces
pass

# Client
from jupyter_client import BlockingKernelClient

kc = BlockingKernelClient(connection_file=connection_file)
asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
kc.load_connection_file()
kc.start_channels()
kc.wait_for_ready()
return kc, kernel_process

def _execute_code(self, kc: BlockingKernelClient, code: str) -> str:
def _execute_code(self, kc, code: str) -> str:
kc.wait_for_ready()
kc.execute(code)
result = ''
Expand Down Expand Up @@ -259,6 +258,8 @@ def _execute_code(self, kc: BlockingKernelClient, code: str) -> str:
return result

def _serve_image(self, image_base64: str) -> str:
import PIL.Image

image_file = f'{uuid.uuid4()}.png'
local_image_file = os.path.join(self.work_dir, image_file)

Expand All @@ -274,6 +275,8 @@ def _serve_image(self, image_base64: str) -> str:


def _fix_matplotlib_cjk_font_issue():
import matplotlib

ttf_name = os.path.basename(ALIB_FONT_FILE)
local_ttf = os.path.join(os.path.abspath(os.path.join(matplotlib.matplotlib_fname(), os.path.pardir)), 'fonts',
'ttf', ttf_name)
Expand Down
10 changes: 0 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
anyio>=3.7.1
beautifulsoup4
dashscope>=1.11.0
eval_type_backport
fastapi>=0.103.1
html2text
jieba
json5
jsonlines
jupyter>=1.0.0
matplotlib
numpy
openai
pandas
pdfminer.six
pdfplumber
pillow
pydantic>=2.3.0
python-docx
python-pptx
rank_bm25
requests
seaborn
snowballstemmer
sympy
tiktoken
uvicorn>=0.23.2
28 changes: 28 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ def read_requirements():
with open('requirements.txt') as req:
content = req.read()
requirements = content.split('\n')

# Note: `pip install qwen-agent` by default installs the following deps for code_interpreter.
# However, if you do not want these optional deps, you can install qwen-agent via the following:
# ```bash
# curl -O https://raw.githubusercontent.com/QwenLM/Qwen-Agent/main/requirements.txt;
# pip install -r requirements.txt;
# pip install -U --no-deps qwen-agent;
# ```
code_interpreter_deps = [
'anyio>=3.7.1',
'fastapi>=0.103.1',
'jupyter>=1.0.0',
'matplotlib',
'numpy',
'pandas',
'pillow',
'seaborn',
'sympy',
'uvicorn>=0.23.2',
]
requirements.extend(code_interpreter_deps)

return requirements


Expand All @@ -43,5 +65,11 @@ def read_description() -> str:
],
},
install_requires=read_requirements(),
extras_require={
'gui': [
'gradio==4.21.0',
'modelscope-studio>=0.4.0',
],
},
url='https://github.com/QwenLM/Qwen-Agent',
)

0 comments on commit 9443170

Please sign in to comment.