Created
May 6, 2026 03:34
-
-
Save wooparadog/9bee5de0888271d6dd8b7b7fb4934b46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from openai import OpenAI | |
| client = OpenAI( | |
| # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx" | |
| api_key="sk-yes", | |
| base_url="https://dashscope-us.aliyuncs.com/compatible-mode/v1", | |
| ) | |
| messages = [{"role": "user", "content": "你是谁"}] | |
| completion = client.chat.completions.create( | |
| model="qwen3.6-flash", # 您可以按需更换为其它深度思考模型 | |
| messages=messages, | |
| extra_body={"enable_thinking": True}, | |
| stream=True, | |
| extra_headers={ | |
| "X-DashScope-DataInspection": json.dumps( | |
| {"input": "disable", "output": "disable"} | |
| ), | |
| }, | |
| ) | |
| is_answering = False # 是否进入回复阶段 | |
| print("\n" + "=" * 20 + "思考过程" + "=" * 20) | |
| for chunk in completion: | |
| delta = chunk.choices[0].delta | |
| if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None: | |
| if not is_answering: | |
| print(delta.reasoning_content, end="", flush=True) | |
| if hasattr(delta, "content") and delta.content: | |
| if not is_answering: | |
| print("\n" + "=" * 20 + "完整回复" + "=" * 20) | |
| is_answering = True | |
| print(delta.content, end="", flush=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment