Qwen-Agent هو إطار عمل لتطوير الوكلاء الأذكياء يعتمد على نموذج اللغة الكبير Qwen، وهو متخصص في تطوير تطبيقات LLM التي تتمتع بقدرات اتباع التعليمات واستخدام الأدوات والتخطيط والذاكرة. تم تطوير هذا المشروع وصيانته بواسطة فريق Qwen في Alibaba، وهو حاليًا بمثابة الدعم الخلفي لخدمة الدردشة Qwen (Qwen Chat).
reasoning_content
، وتعديل قالب استدعاء الوظائف الافتراضيpip install -U "qwen-agent[gui,rag,code_interpreter,mcp]"
# أو التثبيت الأدنى
pip install -U qwen-agent
git clone https://github.com/QwenLM/Qwen-Agent.git
cd Qwen-Agent
pip install -e ./"[gui,rag,code_interpreter,mcp]"
[gui]
: دعم واجهة المستخدم الرسومية Gradio[rag]
: وظيفة استرجاع معزز RAG[code_interpreter]
: وظيفة مفسر التعليمات البرمجية[mcp]
: دعم بروتوكول MCPllm_cfg = {
'model': 'qwen-max-latest',
'model_server': 'dashscope',
# 'api_key': 'YOUR_DASHSCOPE_API_KEY',
'generate_cfg': {
'top_p': 0.8
}
}
llm_cfg = {
'model': 'Qwen2.5-7B-Instruct',
'model_server': 'http://localhost:8000/v1',
'api_key': 'EMPTY',
}
import pprint
import urllib.parse
import json5
from qwen_agent.agents import Assistant
from qwen_agent.tools.base import BaseTool, register_tool
from qwen_agent.utils.output_beautify import typewriter_print
# الخطوة 1: إضافة أداة مخصصة
@register_tool('my_image_gen')
class MyImageGen(BaseTool):
description = 'خدمة الرسم بالذكاء الاصطناعي (توليد الصور)، أدخل وصفًا نصيًا، وأرجع عنوان URL للصورة المرسومة بناءً على المعلومات النصية.'
parameters = [{
'name': 'prompt',
'type': 'string',
'description': 'وصف تفصيلي لمحتوى الصورة المطلوب، باللغة الإنجليزية',
'required': True
}]
def call(self, params: str, **kwargs) -> str:
prompt = json5.loads(params)['prompt']
prompt = urllib.parse.quote(prompt)
return json5.dumps(
{'image_url': f'https://image.pollinations.ai/prompt/{prompt}'},
ensure_ascii=False)
# الخطوة 2: تكوين LLM
llm_cfg = {
'model': 'qwen-max-latest',
'model_server': 'dashscope',
'generate_cfg': {
'top_p': 0.8
}
}
# الخطوة 3: إنشاء وكيل ذكي
system_instruction = '''بعد تلقي طلب المستخدم، يجب عليك:
- أولاً رسم صورة والحصول على عنوان URL للصورة،
- ثم تشغيل الكود `request.get(image_url)` لتنزيل الصورة،
- وأخيرًا تحديد عملية صورة من المستند المحدد لمعالجة الصورة.
يرجى عرض الصورة باستخدام `plt.show()`.'''
tools = ['my_image_gen', 'code_interpreter']
files = ['./examples/resource/doc.pdf']
bot = Assistant(llm=llm_cfg,
system_message=system_instruction,
function_list=tools,
files=files)
# الخطوة 4: تشغيل دردشة الوكيل الذكي
messages = []
while True:
query = input('\nuser query: ')
messages.append({'role': 'user', 'content': query})
response = []
response_plain_text = ''
print('bot response:')
for response in bot.run(messages=messages):
response_plain_text = typewriter_print(response, response_plain_text)
messages.extend(response)
from qwen_agent.gui import WebUI
WebUI(bot).run()
{
"mcpServers": {
"memory": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"]
},
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/files"]
},
"sqlite": {
"command": "uvx",
"args": [
"mcp-server-sqlite",
"--db-path",
"test.db"
]
}
}
}
يوفر المشروع حلول RAG سريعة، بالإضافة إلى وكيل ذكي تنافسي للمستندات الطويلة جدًا، ويتفوق على نماذج سياق النمو الأصلية في اثنين من المعايير الصعبة، ويحقق أداءً مثاليًا في اختبار الإجهاد "البحث عن إبرة في كومة قش" أحادي الطلقة الذي يتضمن سياقًا يبلغ 1 مليون رمز.
BrowserQwen هو مساعد متصفح مبني على Qwen-Agent، ويوفر تصفح الويب والتعامل معه واستخراج المعلومات.
Qwen-Agent هو إطار عمل لتطوير الوكلاء الأذكياء قوي وسهل الاستخدام، ويوفر للمطورين سلسلة أدوات كاملة لبناء تطبيقات LLM معقدة. سواء كان روبوت محادثة بسيطًا أو مساعدًا ذكيًا متعدد الوظائف معقدًا، يمكن تحقيقه ونشره بسرعة من خلال هذا الإطار.