XMWAI 0.1.6__py3-none-any.whl → 0.1.8__py3-none-any.whl

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.

XMWAI/__init__.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from .core import story, photo, reply, poem, get_access_token # 从子模块导入函数到顶层
2
2
  from .magic_core import birthday # 从子模块导入函数到顶层
3
3
  from .bomb_core import bomb # 从子模块导入函数到顶层
4
+ from .idiom_core import idiom,searchIdiom # 从子模块导入函数到顶层
4
5
 
5
- __all__ = ["story", "photo", "reply", "poem", "get_access_token", 'birthday', 'bomb'] # 可选:明确导出的内容
6
+ __all__ = ["story", "photo", "reply", "poem", "get_access_token", 'birthday', 'bomb', "idiom", "searchIdiom"] # 可选:明确导出的内容
XMWAI/core.py CHANGED
@@ -184,24 +184,34 @@ def poem(title, key=""):
184
184
  elif key != "CaJQ":
185
185
  print("秘钥错误!请重新输入!")
186
186
  return "秘钥错误!请重新输入!"
187
- key = "ZZC"
188
- access_token = get_access_token(key)
189
- if access_token:
190
- url = f"https://aip.baidubce.com/rpc/2.0/nlp/v1/poem?access_token={access_token}"
191
- payload = {
192
- "text": title, # 直接使用普通字符串
193
- }
194
- headers = {
195
- 'Content-Type': 'application/json',
196
- 'Accept': 'application/json'
197
- }
187
+ messagesList = [
188
+ {
189
+ "role": "system",
190
+ "content": "唐代诗人"
191
+ },
192
+ {
193
+ "role": "user",
194
+ "content": f"请以《{title}》为题,创作一首七言绝句,每句7个字,一共4句,符合古诗韵律规范,内容积极乐观向上,适合中小学生阅读,不要解析,不要题目,不要标点符号,所有文字放在一行"
195
+ }
196
+ ]
198
197
 
199
- # 直接发送JSON对象,不转换为字符串
200
- response = requests.post(url, headers=headers, json=payload)
201
- if response.status_code == 200:
202
- return response.json()['poem'][0]['content'] # 使用response.json()直接解析JSON响应
203
- else:
204
- print("Failed with status code:", response.status_code)
205
- print("Response:", response.text)
206
- else:
207
- print("Failed to get access token.")
198
+ url = "https://qianfan.baidubce.com/v2/chat/completions"
199
+
200
+ payload = json.dumps({
201
+ "model": "ernie-4.5-turbo-32k",
202
+ "messages": messagesList
203
+ }, ensure_ascii=False)
204
+ headers = {
205
+ 'Content-Type': 'application/json',
206
+ 'appid': '',
207
+ 'Authorization': 'Bearer bce-v3/ALTAK-cGbxpVA5AbSz6h8nbLaFh/b539762075d55c76d93dc78bcf0a91beeaf0490a'
208
+ }
209
+
210
+ response = requests.request("POST", url, headers=headers, data=payload.encode("utf-8"))
211
+
212
+ response_data = json.loads(response.text)
213
+ content = response_data["choices"][0]["message"]["content"]
214
+ content.replace(" ", "")
215
+ content.replace("\n", "")
216
+ content.replace(" ", "")
217
+ return content
XMWAI/idiom_core.py CHANGED
@@ -1,6 +1,12 @@
1
1
  import random
2
-
3
2
  import json
3
+ from importlib.resources import files
4
+ from pathlib import Path
5
+
6
+
7
+ def get_json_path():
8
+ """获取 idiom.json 的正确路径(兼容 PyPI 安装后的包内资源)"""
9
+ return Path(files("XMWAI").joinpath("idiom.json"))
4
10
 
5
11
 
6
12
  def idiom(word, mode=0):
@@ -14,51 +20,35 @@ def idiom(word, mode=0):
14
20
  3 - 返回出处
15
21
  :return: 查询结果或 None
16
22
  """
17
- if mode == 0:
18
- with open("idiom.json", "r", encoding="utf-8") as f:
19
- data = json.load(f)
20
- for i in data:
21
- if word == i["word"]:
23
+ with open(get_json_path(), "r", encoding="utf-8") as f:
24
+ data = json.load(f)
25
+ for i in data:
26
+ if word == i["word"]:
27
+ if mode == 0:
22
28
  return True
23
- return False
24
- elif mode == 1:
25
- with open("idiom.json", "r", encoding="utf-8") as f:
26
- data = json.load(f)
27
- for i in data:
28
- if word == i["word"]:
29
+ elif mode == 1:
29
30
  return i["pinyin"]
30
- return None
31
-
32
- elif mode == 2:
33
- with open("idiom.json", "r", encoding="utf-8") as f:
34
- data = json.load(f)
35
- for i in data:
36
- if word == i["word"]:
31
+ elif mode == 2:
37
32
  return i["explanation"]
38
- return None
39
- elif mode == 3:
40
- with open("idiom.json", "r", encoding="utf-8") as f:
41
- data = json.load(f)
42
- for i in data:
43
- if word == i["word"]:
33
+ elif mode == 3:
44
34
  return i["derivation"]
45
- return None
35
+ return False if mode == 0 else None
46
36
 
47
37
 
48
38
  def searchIdiom(text, num=1):
49
39
  """
50
40
  模糊查询成语
51
41
  :param text: 要查询的字
52
- :param mode: 第几个字
53
- :return: 查询结果None
42
+ :param num: 第几个字(1~4)
43
+ :return: 匹配的成语False
54
44
  """
55
45
  wordList = []
56
- with open("idiom.json", "r", encoding="utf-8") as f:
46
+ with open(get_json_path(), "r", encoding="utf-8") as f:
57
47
  data = json.load(f)
58
48
  for i in data:
59
- if text == i["word"][num-1]:
60
- wordList.append(i["word"])
61
- if wordList:
62
- return random.choice(wordList)
63
- else:
64
- return False
49
+ try:
50
+ if text == i["word"][num - 1]:
51
+ wordList.append(i["word"])
52
+ except:
53
+ pass
54
+ return random.choice(wordList) if wordList else False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: XMWAI
3
- Version: 0.1.6
3
+ Version: 0.1.8
4
4
  Summary: Small code King AI related library
5
5
  Home-page: https://github.com/Tonykai88/XMWAI.git
6
6
  Author: pydevelopment
@@ -1,7 +1,7 @@
1
- XMWAI/__init__.py,sha256=22xWIf68Fub64LGW_EB7WBvhuc5DWyzusEm3I2EjBFA,360
1
+ XMWAI/__init__.py,sha256=GuNnfM345TTSZW45YiwEt1dM6Ay0biP1bQBrGpqqmEg,464
2
2
  XMWAI/bomb_core.py,sha256=dRORqAyhItkFuMUHAN0vwQcvrvb3C5X18hmaUMJ0hhE,1708
3
- XMWAI/core.py,sha256=C4pntTFPOpMuFhJCEVoAlrJEizNSHOWZcB1dwCdkl6w,7396
4
- XMWAI/idiom_core.py,sha256=PPBBXYj_jJV1SnU5NROHiFkukmZDpZJgjZyuTiZondA,1774
3
+ XMWAI/core.py,sha256=KrtdKXvSGKAHlOYF1-v2iSxpfjpHoGeGVOBIxH1Ez4E,7759
4
+ XMWAI/idiom_core.py,sha256=0Uu9GxVwEvFAhjj0M2Orw-E9FjKT05jKQDbUvg0wAXE,1577
5
5
  XMWAI/magic_core.py,sha256=XU7K4Ta7EAvwBLk20_Hlu18E6Kz8B0HxUBq0YsawikE,3441
6
6
  XMWAI/gif/0.gif,sha256=LGpAReVTyZEb1J-bWYTpxxHbIxmLJ-3wA0lw4cBqdsY,303
7
7
  XMWAI/gif/1.gif,sha256=nsysRjMkNBQJy91SOY284gnnD_DlhLrgyIOgcJ_ZOHI,3554
@@ -90,8 +90,8 @@ XMWAI/gif/84.gif,sha256=6Ip_uQmvrr2fagLXu1YqWyI_DL2PVVtKCPtmNtzt3P4,38767
90
90
  XMWAI/gif/85.gif,sha256=6Ip_uQmvrr2fagLXu1YqWyI_DL2PVVtKCPtmNtzt3P4,38767
91
91
  XMWAI/gif/9.gif,sha256=cPouth-xwc3QPcg2m6HMP2OD1ZCeRBD_-RPImvvKAA0,9485
92
92
  XMWAI/gif/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
93
- xmwai-0.1.6.dist-info/licenses/LICENSE.txt,sha256=bcaIQMrIhdQ3O-PoZlexjmW6h-wLGvHxh5Oksl4ohtc,1066
94
- xmwai-0.1.6.dist-info/METADATA,sha256=El-wSx7NCt6i27P4brabPLUWkOHeyMk4-4nYk__8y9k,1033
95
- xmwai-0.1.6.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
96
- xmwai-0.1.6.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
97
- xmwai-0.1.6.dist-info/RECORD,,
93
+ xmwai-0.1.8.dist-info/licenses/LICENSE.txt,sha256=bcaIQMrIhdQ3O-PoZlexjmW6h-wLGvHxh5Oksl4ohtc,1066
94
+ xmwai-0.1.8.dist-info/METADATA,sha256=CJgI9oxFUvO-a7Ax4XNIQ5AOEz-t_O-p2doxPSDIIIk,1033
95
+ xmwai-0.1.8.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
96
+ xmwai-0.1.8.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
97
+ xmwai-0.1.8.dist-info/RECORD,,
File without changes