Created
April 9, 2026 09:17
-
-
Save wooparadog/e5598141cabedd078809881493c5476e 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 logging | |
| logging.basicConfig(level="DEBUG") | |
| from openai import OpenAI | |
| import os | |
| client = OpenAI( | |
| # 如果没有配置环境变量,请用阿里云百炼API Key替换:api_key="sk-xxx" | |
| api_key="sk-", | |
| base_url="https://dashscope-us.aliyuncs.com/compatible-mode/v1", | |
| ) | |
| messages = [{"role": "user", "content": "recite the gettsburg speech"}] | |
| import time | |
| begin = time.time() | |
| print("start", begin) | |
| completion = client.chat.completions.create( | |
| model="qwen3.5-flash", # 您可以按需更换为其它深度思考模型 | |
| temperature=1.0, | |
| messages=messages, | |
| stream=True, | |
| max_tokens=4096, | |
| stream_options= {'include_usage': True}, | |
| extra_body=dict( | |
| enable_thinking=False | |
| ), | |
| ) | |
| is_answering = False # 是否进入回复阶段 | |
| print("\n" + "=" * 20 + "思考过程" + "=" * 20) | |
| for chunk in completion: | |
| print("chunk time", time.time() - begin) | |
| #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) | |
| print("============", time.time() - begin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment