XMWAI 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of XMWAI might be problematic. Click here for more details.

@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tonykai88
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
xmwai-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.2
2
+ Name: XMWAI
3
+ Version: 0.1.0
4
+ Summary: Small code King AI related library
5
+ Home-page: https://github.com/Tonykai88/XMWAI.git
6
+ Author: pydevelopment
7
+ Author-email: hekai@xiaoma.cn
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.7.0
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE.txt
14
+ Requires-Dist: requests>=2.32.3
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: requires-dist
22
+ Dynamic: requires-python
23
+ Dynamic: summary
24
+
25
+ # XMWAI
26
+
27
+ ## 简介
28
+ XMWAI 是一个小码王开源的第三方 Python 库,支持生文、生图、生诗句等多场景的内容。需要学员提供对应的api秘钥才能使用。
29
+
30
+ ## 安装
31
+ 使用 pip 安装:
32
+ ```bash
33
+ pip install XMWAI
34
+
35
+ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple XMWAI
36
+ ```
xmwai-0.1.0/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # XMWAI
2
+
3
+ ## 简介
4
+ XMWAI 是一个小码王开源的第三方 Python 库,支持生文、生图、生诗句等多场景的内容。需要学员提供对应的api秘钥才能使用。
5
+
6
+ ## 安装
7
+ 使用 pip 安装:
8
+ ```bash
9
+ pip install XMWAI
10
+
11
+ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple XMWAI
12
+ ```
@@ -0,0 +1,4 @@
1
+ from .core import story, photo, reply, poem, get_access_token # 从子模块导入函数到顶层
2
+ from .magic_core import birthday # 从子模块导入函数到顶层
3
+
4
+ __all__ = ["story", "photo", "reply", "poem", "get_access_token", 'birthday'] # 可选:明确导出的内容
@@ -0,0 +1,205 @@
1
+ import re
2
+ import requests
3
+ import json
4
+ import os
5
+
6
+
7
+ def story(role, time, address, event, key=""):
8
+ content = role+time+address+event
9
+ url = "https://spark-api-open.xf-yun.com/v1/chat/completions"
10
+ data = {
11
+ "max_tokens": 1000, # 回复长度限制
12
+ "top_k": 4, # 灵活度
13
+ "temperature": 0.5, # 随机性
14
+ "messages": [
15
+ {
16
+ # 设置对话背景或赋予模型角色,该设定会贯穿整轮对话,对全局的模型生成结果产生影响。对应作为'role'为'system'时,'content'的值
17
+ "role": "system",
18
+ "content": "我是一个非常会写童话的儿童写作作家,根据我写出的关键词,帮我生成一篇童话故事。"
19
+ },
20
+ {
21
+ # 对大模型发出的具体指令,用于描述需要大模型完成的目标任务和需求说明。会与角色设定中的内容拼接,共同作为'role'为'system'时,'content'的值
22
+ "role": "user",
23
+ "content": content
24
+ }
25
+ ],
26
+ "model": "4.0Ultra"
27
+ }
28
+ data["stream"] = True
29
+ if key == "":
30
+ print("没有秘钥!请提供秘钥!")
31
+ return "没有秘钥!请提供秘钥!"
32
+ elif key != "CaJQ":
33
+ print("秘钥错误!请重新输入!")
34
+ return "秘钥错误!请重新输入!"
35
+ header = {
36
+ "Authorization": "Bearer paNyL"+key+"OpyOBmflKZp:yhBhAlSFMwaqlVKAtDbv"
37
+ }
38
+ response = requests.post(url, headers=header, json=data, stream=True)
39
+
40
+ # 流式响应解析示例
41
+ response.encoding = "utf-8"
42
+ contents = ""
43
+ result = response.iter_lines(decode_unicode="utf-8")
44
+ result = str(list(result))
45
+
46
+ # 正则表达式模式
47
+ pattern = r'"content":"(.*?)"'
48
+
49
+ # 使用re.findall查找所有匹配的内容
50
+ contents = re.findall(pattern, result, re.DOTALL)
51
+ s = ""
52
+ for i in contents:
53
+ s += i
54
+ s = s.replace('\\', "")
55
+ s = s.replace("n", "")
56
+ return s
57
+
58
+
59
+ def photo(content, style, size, key=""):
60
+ # 图像生成的 API URL
61
+ if key == "":
62
+ print("没有秘钥!请提供秘钥!")
63
+ return "没有秘钥!请提供秘钥!"
64
+ elif key != "image":
65
+ print("秘钥错误!请重新输入!")
66
+ return "秘钥错误!请重新输入!"
67
+ url = "https://gateway.xiaomawang.com/pythonUILibApi/api/text2" + key
68
+
69
+ # 请求的头部
70
+ headers = {
71
+ "Content-Type": "application/json"
72
+ }
73
+ resolution = {"1024*1024":3, "1280*720":4, "720*1280":5}
74
+ if content == "":
75
+ return
76
+ if style == "":
77
+ style="默认"
78
+ if size == "":
79
+ size="1024*1024"
80
+
81
+ # 请求的主体内容
82
+ data = {
83
+ 'prompt': content, # 你想要生成的图像描述
84
+ 'imgStyle': style,
85
+ 'imgSize': resolution[size] # 图像的尺寸
86
+ }
87
+
88
+ # 发送 POST 请求
89
+ response = requests.post(url, headers=headers, json=data)
90
+
91
+ # 检查请求是否成功
92
+ if response.status_code == 200:
93
+ response_data = response.json()
94
+ _data = eval(str(response_data))
95
+ photo_url = _data["data"][0]["url"]
96
+
97
+ skin = requests.get(photo_url).content
98
+ with open("{}.png".format(content), 'wb') as s:
99
+ s.write(skin)
100
+
101
+
102
+ def reply(role, content, key=""):
103
+ url = "https://spark-api-open.xf-yun.com/v1/chat/completions"
104
+ data = {
105
+ "max_tokens": 60, # 回复长度限制
106
+ "top_k": 5, # 灵活度
107
+ "temperature": 0.6, # 随机性
108
+ "messages": [
109
+ {
110
+ # 设置对话背景或赋予模型角色,该设定会贯穿整轮对话,对全局的模型生成结果产生影响。对应作为'role'为'system'时,'content'的值
111
+ "role": "system",
112
+ "content": "你是一位非常优秀的" + role + ",请根据我的提问,非常科学、有趣和严谨的回答我。"
113
+ },
114
+ {
115
+ # 对大模型发出的具体指令,用于描述需要大模型完成的目标任务和需求说明。会与角色设定中的内容拼接,共同作为'role'为'system'时,'content'的值
116
+ "role": "user",
117
+ "content": content + "(一定要80个字左右,语句必须完整,语句必须完整,不准出现断句。)"
118
+ }
119
+ ],
120
+ "model": "4.0Ultra"
121
+ }
122
+ data["stream"] = True
123
+ if key == "":
124
+ print("没有秘钥!请提供秘钥!")
125
+ return "没有秘钥!请提供秘钥!"
126
+ elif key != "CaJQ":
127
+ print("秘钥错误!请重新输入!")
128
+ return "秘钥错误!请重新输入!"
129
+ header = {
130
+ "Authorization": "Bearer paNyL"+key+"OpyOBmflKZp:yhBhAlSFMwaqlVKAtDbv"
131
+ }
132
+ response = requests.post(url, headers=header, json=data, stream=True)
133
+
134
+ # 流式响应解析示例
135
+ response.encoding = "utf-8"
136
+ contents = ""
137
+ result = response.iter_lines(decode_unicode="utf-8")
138
+ result = str(list(result))
139
+
140
+ # 正则表达式模式
141
+ pattern = r'"content":"(.*?)"'
142
+
143
+ # 使用re.findall查找所有匹配的内容
144
+ contents = re.findall(pattern, result, re.DOTALL)
145
+ s = " "
146
+ for i in contents:
147
+ s += i
148
+ if '\\' in s:
149
+ s = s.replace('\\', "")
150
+ if '*' in s:
151
+ s = s.replace('*', "")
152
+ sum_ = """"""
153
+ for i in range(0,len(s),17):
154
+ sum_ = sum_ + s[i:i+17] + "\n"
155
+ return sum_
156
+
157
+
158
+ def get_access_token(key):
159
+ """
160
+ 使用 AK,SK 生成鉴权签名(Access Token)
161
+ :return: access_token,或是None(如果错误)
162
+ """
163
+ API_KEY = "Ox1CTF00wD50XmXF1hiPSqdh"
164
+ SECRET_KEY = "4ZQt4Zj"+ key +"zuT2XtBtRojdRZ3HgZOtrP"
165
+ url = "https://aip.baidubce.com/oauth/2.0/token"
166
+ params = {
167
+ "grant_type": "client_credentials",
168
+ "client_id": API_KEY,
169
+ "client_secret": SECRET_KEY
170
+ }
171
+ response = requests.post(url, params=params)
172
+ if response.status_code == 200:
173
+ return response.json().get("access_token")
174
+ else:
175
+ print("Error getting access token:", response.text)
176
+ return None
177
+
178
+
179
+ def poem(title, key=""):
180
+ if key == "":
181
+ print("没有秘钥!请提供秘钥!")
182
+ return "没有秘钥!请提供秘钥!"
183
+ elif key != "ZZC":
184
+ print("秘钥错误!请重新输入!")
185
+ return "秘钥错误!请重新输入!"
186
+ access_token = get_access_token(key)
187
+ if access_token:
188
+ url = f"https://aip.baidubce.com/rpc/2.0/nlp/v1/poem?access_token={access_token}"
189
+ payload = {
190
+ "text": title, # 直接使用普通字符串
191
+ }
192
+ headers = {
193
+ 'Content-Type': 'application/json',
194
+ 'Accept': 'application/json'
195
+ }
196
+
197
+ # 直接发送JSON对象,不转换为字符串
198
+ response = requests.post(url, headers=headers, json=payload)
199
+ if response.status_code == 200:
200
+ return response.json()['poem'][0]['content'] # 使用response.json()直接解析JSON响应
201
+ else:
202
+ print("Failed with status code:", response.status_code)
203
+ print("Response:", response.text)
204
+ else:
205
+ print("Failed to get access token.")
@@ -0,0 +1,62 @@
1
+ from datetime import date
2
+
3
+ def birthday():
4
+ while True:
5
+ try:
6
+ # 获取并验证生日计算结果
7
+ code = int(input("\n从上方选出你的生日日期\n将生日的月份乘以4,加上9,再乘以25,最后加上日期后的结果:"))
8
+ secret_number = code - 225
9
+ # 解析月份和日期
10
+ month = secret_number // 100
11
+ day = secret_number % 100
12
+
13
+ # 基础验证
14
+ if not (1 <= month <= 12 and 1 <= day <= 31):
15
+ raise ValueError("神秘数字解析失败,请确认计算正确!✨")
16
+
17
+ # 创建日期对象
18
+ today = date.today()
19
+ try:
20
+ current_year_bday = date(today.year, month, day)
21
+ except ValueError as e:
22
+ raise ValueError(f"🔮 魔法日历显示:{str(e)},请检查你的生日日期!")
23
+
24
+ # 计算时间差
25
+ if current_year_bday < today:
26
+ next_bday = date(today.year + 1, month, day)
27
+ days_passed = (today - current_year_bday).days
28
+ days_left = (next_bday - today).days
29
+ print(f"\n🎂 你的生日是 {month}月{day}日")
30
+ print(f"⏳ 今年生日已经过去了 {days_passed} 天")
31
+ print(f"⏳ 距离下次生日还有 {days_left} 天")
32
+ elif current_year_bday == today:
33
+ print("\n🎉🎉🎉 今天是你的生日!生日快乐! 🎉🎉🎉")
34
+ else:
35
+ days_left = (current_year_bday - today).days
36
+ print(f"\n🎂 你的生日是 {month}月{day}日")
37
+ print(f"⏳ 距离生日还有 {days_left} 天")
38
+
39
+ # 添加节日彩蛋
40
+ if (month, day) == (12, 25):
41
+ print("🎁 圣诞奇迹儿!你的到来就是最棒的圣诞礼物!")
42
+ print("🦌 愿你的善良像驯鹿传遍四方,热情如炉火温暖世界!")
43
+ elif (month, day) == (10, 31):
44
+ print("👻 魔法小精灵!糖果和惊喜永远伴随你!")
45
+ print("🕯️ 愿你的生活充满奇幻冒险,像南瓜灯一样照亮黑夜!")
46
+ elif (month, day) == (1, 1):
47
+ print("✨ 新年小天使!你的诞生就是世界收到的最好新年礼物!")
48
+ print("🎊 愿你的笑容像跨年烟火般灿烂,智慧随岁月与日俱增!")
49
+ elif (month, day) == (5, 1):
50
+ print("👷♀ 勤劳小蜜蜂!你的生日就是全世界的劳动庆典!")
51
+ print("🏆 愿你的努力都能开花结果,像春天播种秋天丰收!")
52
+ elif (month, day) == (10, 1):
53
+ print("🎇 国庆小英雄!你和祖国母亲同庆生辰!")
54
+ print("🚀 愿你的未来如火箭升空,人生像阅兵方阵般气势如虹!")
55
+ elif (month, day) == (6, 1):
56
+ print("🪅 双倍快乐王!全世界的孩子都在为你庆生!")
57
+ print("🎠 愿你的生活永远像游乐场,每天都有新发现!")
58
+ break # 退出循环
59
+
60
+ except ValueError as e:
61
+ print(f"\n⚠️ 魔法出错啦:{e}")
62
+ print("请重新输入正确的神秘数字!")
@@ -0,0 +1,36 @@
1
+ Metadata-Version: 2.2
2
+ Name: XMWAI
3
+ Version: 0.1.0
4
+ Summary: Small code King AI related library
5
+ Home-page: https://github.com/Tonykai88/XMWAI.git
6
+ Author: pydevelopment
7
+ Author-email: hekai@xiaoma.cn
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.7.0
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE.txt
14
+ Requires-Dist: requests>=2.32.3
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: requires-dist
22
+ Dynamic: requires-python
23
+ Dynamic: summary
24
+
25
+ # XMWAI
26
+
27
+ ## 简介
28
+ XMWAI 是一个小码王开源的第三方 Python 库,支持生文、生图、生诗句等多场景的内容。需要学员提供对应的api秘钥才能使用。
29
+
30
+ ## 安装
31
+ 使用 pip 安装:
32
+ ```bash
33
+ pip install XMWAI
34
+
35
+ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple XMWAI
36
+ ```
@@ -0,0 +1,11 @@
1
+ LICENSE.txt
2
+ README.md
3
+ setup.py
4
+ XMWAI/__init__.py
5
+ XMWAI/core.py
6
+ XMWAI/magic_core.py
7
+ XMWAI.egg-info/PKG-INFO
8
+ XMWAI.egg-info/SOURCES.txt
9
+ XMWAI.egg-info/dependency_links.txt
10
+ XMWAI.egg-info/requires.txt
11
+ XMWAI.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ requests>=2.32.3
@@ -0,0 +1 @@
1
+ XMWAI
xmwai-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
xmwai-0.1.0/setup.py ADDED
@@ -0,0 +1,22 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="XMWAI", # 包名(pip install XMWAI)
5
+ version="0.1.0", # 初始版本号
6
+ author="pydevelopment", # 作者
7
+ author_email="hekai@xiaoma.cn", # 邮箱
8
+ description="Small code King AI related library", # 简短描述
9
+ long_description=open("README.md", encoding="utf-8").read(), # 详细描述
10
+ long_description_content_type="text/markdown", # 描述格式
11
+ url="https://github.com/Tonykai88/XMWAI.git", # GitHub 链接
12
+ packages=find_packages(), # 自动找包
13
+ install_requires=[
14
+ "requests>=2.32.3", # 依赖包
15
+ ],
16
+ classifiers=[
17
+ "Programming Language :: Python :: 3",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ ],
21
+ python_requires='>=3.7.0', # 支持的 Python 版本
22
+ )