From b35e44f27dc285398abda3ab16f357e17420d5f2 Mon Sep 17 00:00:00 2001 From: kexsh <769014005@qq.com> Date: Fri, 22 Aug 2025 23:56:59 +0800 Subject: [PATCH] init --- .gitignore | 2 ++ requirements.txt | 2 ++ setup.py | 38 ++++++++++++++++++++++++++++++++++++++ test/compatible/qwen.py | 21 +++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 .gitignore create mode 100644 requirements.txt create mode 100644 setup.py create mode 100644 test/compatible/qwen.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0675eb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +knightutils.egg-info \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..45153ff --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +openai +dashscope \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..46638a9 --- /dev/null +++ b/setup.py @@ -0,0 +1,38 @@ +from setuptools import setup, find_packages + +with open("README.md", "r", encoding="utf-8") as fh: + long_description = fh.read() + +with open("requirements.txt", "r", encoding="utf-8") as fh: + requirements = [line.strip() for line in fh if line.strip() and not line.startswith("#")] + +setup( + name="knightutils", + version="0.1.0", + author="Unknown", + author_email="unknown@example.com", + description="A utility package for sharing code", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/yourusername/knightutils", + packages=find_packages(), + classifiers=[ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + ], + python_requires=">=3.7", + install_requires=requirements, + extras_require={ + "dev": [ + "pytest>=6.0", + "pytest-cov>=2.0", + ], + }, +) \ No newline at end of file diff --git a/test/compatible/qwen.py b/test/compatible/qwen.py new file mode 100644 index 0000000..be5de9a --- /dev/null +++ b/test/compatible/qwen.py @@ -0,0 +1,21 @@ +import os +from openai import OpenAI + +client = OpenAI( + # 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx", + api_key=os.getenv("DASHSCOPE_API_KEY"), + base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", +) + +completion = client.chat.completions.create( + # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models + model="qwen-plus", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "你是谁?"}, + ], + # Qwen3模型通过enable_thinking参数控制思考过程(开源版默认True,商业版默认False) + # 使用Qwen3开源版模型时,若未启用流式输出,请将下行取消注释,否则会报错 + # extra_body={"enable_thinking": False}, +) +print(completion.model_dump_json())