Qwen3 definiert offene LLMs mit dynamischen Thinking-Modi neu und glänzt bei Code, Mathematik und mehrsprachigem Reasoning. Angetrieben von sparsamen 22B aktiven Parametern, vereint es rasante Geschwindigkeit mit tiefer Intelligenz – vollständig Open Source, von leichtgewichtig bis hin zu 235B-Giganten.1. Grundlegende Verwendung: Forwarding im OpenAI-kompatiblen Format. 2. Tool-Aufrufe: Reguläre Tools unterstützen das OpenAI-kompatible Format, während MCP-Tools auf qwen-agent angewiesen sind und vorab die Installation der Abhängigkeiten erfordern:
pip install -U qwen-agent mcp.
Weitere Details finden Sie in der offiziellen Ali-Dokumentation
from openai import OpenAIclient = OpenAI( api_key="sk-***", # 🔑 Replace it by your AiHubMix Key base_url="https://aihubmix.com/v1",)completion = client.chat.completions.create( model="Qwen/Qwen3-30B-A3B", messages=[ { "role": "user", "content": "Explain the Occam's Razor concept and provide everyday examples of it" } ], stream=True)for chunk in completion: if hasattr(chunk.choices, '__len__') and len(chunk.choices) > 0: if hasattr(chunk.choices[0].delta, 'content') and chunk.choices[0].delta.content is not None: print(chunk.choices[0].delta.content, end="")
Verwenden Sie das OpenAI-kompatible Format zum Forwarden. Der Unterschied: Beim Streaming-Aufruf müssen Sie chunk.choices[0].delta.content extrahieren, siehe unten.1. QvQ, Qwen 2.5 VL: Bilderkennung. 2. QwQ: Text-Aufgabe.
from openai import OpenAIimport base64import osclient = OpenAI( api_key="sk-***", # 🔑 Replace it by your AiHubMix Key base_url="https://aihubmix.com/v1",)image_path = "yourpath/file.png"def encode_image(image_path): if not os.path.exists(image_path): raise FileNotFoundError(f"Image file does not exist: {image_path}") with open(image_path, "rb") as image_file: return base64.b64encode(image_file.read()).decode('utf-8')# Get the base64 encoding of the imagebase64_image = encode_image(image_path)completion = client.chat.completions.create( model="qwen2.5-vl-72b-instruct", #qwen2.5-vl-72b-instruct OR Qwen/QVQ-72B-Preview messages=[ { "role": "user", "content": [ {"type": "text", "text": "Please describe this image in detail"}, { "type": "image_url", "image_url": { "url": f"data:image/png;base64,{base64_image}" } } ] } ], stream=True)for chunk in completion: if hasattr(chunk.choices, '__len__') and len(chunk.choices) > 0: if hasattr(chunk.choices[0].delta, 'content') and chunk.choices[0].delta.content is not None: print(chunk.choices[0].delta.content, end="")