From 8d0a539263b23ce45c07feb9902c39de9c3d7df2 Mon Sep 17 00:00:00 2001 From: "tujianhong.tjh" Date: Wed, 17 Apr 2024 13:58:19 +0800 Subject: [PATCH] add the project description to setup.py --- .pre-commit-config.yaml | 1 + README.md | 27 ++++++++++++------------- README_CN.md | 22 ++++++++++---------- benchmark/models/__init__.py | 2 +- benchmark/models/dashscope.py | 1 + qwen_agent/__init__.py | 1 + qwen_agent/llm/oai.py | 1 - qwen_agent/memory/memory.py | 5 +++++ run_server.py | 12 ++++------- setup.py | 37 +++++++++++++++++++++++++++++----- tests/agents/test_assistant.py | 3 +-- 11 files changed, 70 insertions(+), 42 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 32fdb92..eb7c9cc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,6 +12,7 @@ repos: rev: v0.32.0 hooks: - id: yapf + args: ["--style={based_on_style: google, column_limit: 300, indent_width: 4}"] - repo: https://github.com/pre-commit/pre-commit-hooks.git rev: v4.3.0 hooks: diff --git a/README.md b/README.md index d199539..a13b60c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[中文](./README_CN.md) | English +[中文](https://github.com/QwenLM/Qwen-Agent/blob/main/README_CN.md) | English

@@ -13,8 +13,13 @@ It also comes with example applications such as Browser Assistant, Code Interpre ## Installation +- Install the stable version from PyPI: +```bash +pip install -U qwen-agent +``` + +- Alternatively, you can install the latest development version from the source: ```bash -# Install dependencies. git clone https://github.com/QwenLM/Qwen-Agent.git cd Qwen-Agent pip install -e ./ @@ -26,10 +31,10 @@ You can either use the model service provided by Alibaba Cloud's [DashScope](https://help.aliyun.com/zh/dashscope/developer-reference/quick-start), or deploy and use your own model service using the open-source Qwen models. -If you choose to use the model service offered by DashScope, please ensure that you set the environment +- If you choose to use the model service offered by DashScope, please ensure that you set the environment variable `DASHSCOPE_API_KEY` to your unique DashScope API key. -Alternatively, if you prefer to deploy and use your own model service, please follow the instructions provided in the README of Qwen1.5 for deploying an OpenAI-compatible API service. +- Alternatively, if you prefer to deploy and use your own model service, please follow the instructions provided in the README of Qwen1.5 for deploying an OpenAI-compatible API service. Specifically, consult the [vLLM](https://github.com/QwenLM/Qwen1.5?tab=readme-ov-file#vllm) section for high-throughput GPU deployment or the [Ollama](https://github.com/QwenLM/Qwen1.5?tab=readme-ov-file#ollama) section for local CPU (+GPU) deployment. ## Developing Your Own Agent @@ -120,18 +125,12 @@ while True: ``` In addition to using built-in agent implentations such as `class Assistant`, you can also develop your own agent implemetation by inheriting from `class Agent`. -Please refer to the [examples](./examples) directory for more usage examples. +Please refer to the [examples](https://github.com/QwenLM/Qwen-Agent/blob/main/examples) directory for more usage examples. -# BrowserQwen +# Application: BrowserQwen -BrowserQwen is a browser assistant application built upon Qwen-Agent. Please refer to its [documentation](browser_qwen.md) for more -details. +BrowserQwen is a browser assistant built upon Qwen-Agent. Please refer to its [documentation](https://github.com/QwenLM/Qwen-Agent/blob/main/browser_qwen.md) for details. # Disclaimer -This project is currently under active development, and backward compatibility may occasionally be broken. - -> [!Warning] ->

-> The code interpreter is not sandboxed, and it executes code in your own environment. Please do not ask Qwen to perform dangerous tasks, and do not directly use the code interpreter for production purposes. ->
+The code interpreter is not sandboxed, and it executes code in your own environment. Please do not ask Qwen to perform dangerous tasks, and do not directly use the code interpreter for production purposes. diff --git a/README_CN.md b/README_CN.md index 82fa740..f8c6a12 100644 --- a/README_CN.md +++ b/README_CN.md @@ -11,8 +11,13 @@ Qwen-Agent是一个开发框架。开发者可基于本框架开发Agent应用 ## 安装 +- 安装稳定的版本: +```bash +pip install -U qwen-agent +``` + +- 或者,直接从源代码安装最新的版本: ```bash -# 安装依赖 git clone https://github.com/QwenLM/Qwen-Agent.git cd Qwen-Agent pip install -e ./ @@ -22,9 +27,9 @@ pip install -e ./ Qwen-Agent支持接入阿里云[DashScope](https://help.aliyun.com/zh/dashscope/developer-reference/quick-start)服务提供的Qwen模型服务,也支持通过OpenAI API方式接入开源的Qwen模型服务。 -如果希望接入DashScope提供的模型服务,只需配置相应的环境变量`DASHSCOPE_API_KEY`为您的DashScope API Key。 +- 如果希望接入DashScope提供的模型服务,只需配置相应的环境变量`DASHSCOPE_API_KEY`为您的DashScope API Key。 -但如果您希望部署并使用您自己的模型服务,请按照Qwen1.5的README中提供的指导进行操作,以部署一个兼容OpenAI接口协议的API服务。 +- 或者,如果您希望部署并使用您自己的模型服务,请按照Qwen1.5的README中提供的指导进行操作,以部署一个兼容OpenAI接口协议的API服务。 具体来说,请参阅[vLLM](https://github.com/QwenLM/Qwen1.5?tab=readme-ov-file#vllm)一节了解高并发的GPU部署方式,或者查看[Ollama](https://github.com/QwenLM/Qwen1.5?tab=readme-ov-file#ollama)一节了解本地CPU(+GPU)部署。 ## 快速开发 @@ -115,15 +120,10 @@ while True: 除了使用框架自带的智能体实现(如`class Assistant`),您也可以通过继承`class Agent`来自行开发您的智能体实现。更多使用示例,请参阅[examples](./examples)目录。 -# BrowserQwen +# 应用:BrowserQwen -BrowserQwen 是一款基于 Qwen-Agent 构建的浏览器助手应用程序。如需了解更多详情,请参阅其[文档](browser_qwen_cn.md)。 +BrowserQwen 是一款基于 Qwen-Agent 构建的浏览器助手。如需了解详情,请参阅其[文档](browser_qwen_cn.md)。 # 免责声明 -本项目正处于快速迭代中,可能会偶尔出现不兼容旧版本的情况。 - -> [!Warning] ->
-> 代码解释器未进行沙盒隔离,会在部署环境中执行代码。请避免向Qwen发出危险指令,切勿将该代码解释器直接用于生产目的。 ->
+代码解释器未进行沙盒隔离,会在部署环境中执行代码。请避免向Qwen发出危险指令,切勿将该代码解释器直接用于生产目的。 diff --git a/benchmark/models/__init__.py b/benchmark/models/__init__.py index b124c21..9bd87ff 100644 --- a/benchmark/models/__init__.py +++ b/benchmark/models/__init__.py @@ -1,4 +1,4 @@ from models.base import HFModel # noqa -from models.dashscope import QwenDashscopeVLModel +from models.dashscope import QwenDashscopeVLModel # noqa from models.llm import LLM # noqa from models.qwen import Qwen, QwenVL # noqa diff --git a/benchmark/models/dashscope.py b/benchmark/models/dashscope.py index 5e4b496..d001ea3 100644 --- a/benchmark/models/dashscope.py +++ b/benchmark/models/dashscope.py @@ -1,4 +1,5 @@ import logging +import os import time from http import HTTPStatus diff --git a/qwen_agent/__init__.py b/qwen_agent/__init__.py index be1ac3e..ef06910 100644 --- a/qwen_agent/__init__.py +++ b/qwen_agent/__init__.py @@ -1,3 +1,4 @@ +__version__ = '0.0.2' from .agent import Agent __all__ = ['Agent'] diff --git a/qwen_agent/llm/oai.py b/qwen_agent/llm/oai.py index 9b224ed..55e6b7f 100644 --- a/qwen_agent/llm/oai.py +++ b/qwen_agent/llm/oai.py @@ -1,4 +1,3 @@ -import copy import os from pprint import pformat from typing import Dict, Iterator, List, Optional diff --git a/qwen_agent/memory/memory.py b/qwen_agent/memory/memory.py index da74899..f009305 100644 --- a/qwen_agent/memory/memory.py +++ b/qwen_agent/memory/memory.py @@ -80,6 +80,11 @@ def _run(self, # Gen keyword *_, last = self.keygen.run([Message(USER, query)]) keyword = last[-1].content + keyword = keyword.strip() + if keyword.startswith('```json'): + keyword = keyword[len('```json'):] + if keyword.endswith('```'): + keyword = keyword[:-3] try: logger.info(keyword) keyword_dict = json5.loads(keyword) diff --git a/run_server.py b/run_server.py index dab19c3..414da04 100644 --- a/run_server.py +++ b/run_server.py @@ -16,8 +16,7 @@ def parse_args(): '--model_server', type=str, default='dashscope', - help= - 'Set it to `dashscope` if you are using the model service provided by DashScope.' + help='Set it to `dashscope` if you are using the model service provided by DashScope.' ' Set it to the base_url (aka api_base) if using an OpenAI API-compatible service such as vLLM or Ollama.' ' Default: dashscope', ) @@ -33,8 +32,7 @@ def parse_args(): '--llm', type=str, default='qwen-plus', - help= - 'Set it to one of {"qwen-max", "qwen-plus", "qwen-turbo"} if using DashScope.' + help='Set it to one of {"qwen-max", "qwen-plus", "qwen-turbo"} if using DashScope.' ' Set it to the model name using an OpenAI API-compatible model service.' ' Default: qwen-plus', ) @@ -44,16 +42,14 @@ def parse_args(): type=str, default='127.0.0.1', choices=['127.0.0.1', '0.0.0.0'], - help= - 'Set to 0.0.0.0 if you want to allow other machines to access the server. Default: 127.0.0.1', + help='Set to 0.0.0.0 if you want to allow other machines to access the server. Default: 127.0.0.1', ) parser.add_argument( '-t', '--max_ref_token', type=int, default=4000, - help= - 'The number of tokens reserved for the reference materials when doing retrieval-augmanted generation (RAG). Default: 4000', + help='The number of tokens reserved for the reference materials when doing retrieval-augmanted generation (RAG). Default: 4000', ) parser.add_argument( '-w', diff --git a/setup.py b/setup.py index 1fab55e..258215d 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,18 @@ +import re + from setuptools import find_packages, setup +def get_version() -> str: + with open('qwen_agent/__init__.py', encoding='utf-8') as f: + version = re.search( + r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', + f.read(), + re.MULTILINE, + ).group(1) + return version + + def read_requirements(): with open('requirements.txt') as req: content = req.read() @@ -8,14 +20,29 @@ def read_requirements(): return requirements +def read_description() -> str: + with open('README.md', 'r', encoding='UTF-8') as f: + long_description = f.read() + return long_description + + setup( - name='qwen_agent', - version='0.0.1', + name='qwen-agent', + version=get_version(), + author='Qwen Team', + author_email='tujianhong.tjh@alibaba-inc.com', + description='Qwen-Agent: Enhancing LLMs with Agent Workflows, RAG, Function Calling, and Code Interpreter.', + long_description=read_description(), + long_description_content_type='text/markdown', + keywords=['LLM', 'Agent', 'Function Calling', 'RAG', 'Code Interpreter'], packages=find_packages( exclude=['examples', 'examples.*', 'qwen_server', 'qwen_server.*']), package_data={ - 'qwen_agent': - ['utils/qwen.tiktoken', 'tools/resource/*.ttf', 'tools/resource/*.py'], + 'qwen_agent': [ + 'utils/qwen.tiktoken', 'tools/resource/*.ttf', + 'tools/resource/*.py', 'gui/assets/*.css', 'gui/assets/*.jpeg' + ], }, install_requires=read_requirements(), - url='https://github.com/QwenLM/Qwen-Agent') + url='https://github.com/QwenLM/Qwen-Agent', +) diff --git a/tests/agents/test_assistant.py b/tests/agents/test_assistant.py index c135371..4a89938 100644 --- a/tests/agents/test_assistant.py +++ b/tests/agents/test_assistant.py @@ -27,8 +27,7 @@ def test_assistant_files(): Message('user', [ ContentItem(text='总结一个文章标题'), ContentItem( - file= - 'https://help.aliyun.com/zh/dashscope/developer-reference/api-details?disableWebsiteRedirect=true' + file='https://help.aliyun.com/zh/dashscope/developer-reference/api-details?disableWebsiteRedirect=true' ) ]) ]