xiaothink 1.0.0__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 xiaothink might be problematic. Click here for more details.

xiaothink/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ import xiaothink.openapi
2
+ import xiaothink.openapi.chatbot_old
3
+ import xiaothink.openapi.drawer
4
+ import xiaothink.openapi.writer
5
+ import xiaothink.openapi.yanzhi
6
+ import xiaothink.llm.inference.test_formal
7
+ import xiaothink.llm.inference.test
File without changes
@@ -0,0 +1,29 @@
1
+ import requests
2
+ import os
3
+ #import set_conf
4
+ def get_key(key):
5
+ p='C:'+os.environ['HOMEPATH']
6
+ try:
7
+ #open(os.path.join(p,'xiaothink_conf.conf','rb'))
8
+ with open(os.path.join(p,'xiaothink_conf.conf'),'r',encoding='utf-8')as f:
9
+ data=eval(f.read())
10
+ except FileNotFoundError:
11
+
12
+ data={}
13
+ if key in list(data.keys()):
14
+ return data[key]
15
+ else:
16
+ return None
17
+
18
+
19
+
20
+ def chat(text,usern=None):
21
+ """
22
+ text: 聊天内容
23
+ usern:你的用户名(暂时不需要注册,直接起一个就行)
24
+ """
25
+ if not usern:
26
+ usern=get_key('XIAOTHINK_USERNAME')
27
+ #print(usern)
28
+ r = requests.get(f'https://4147093qp2.imdo.co/openapi/user-chat?inp={text}&user={usern}')
29
+ return r.json()['data']['result'].split('\n')[0]
@@ -0,0 +1,63 @@
1
+ import requests
2
+ import urllib.parse
3
+
4
+
5
+ class Drawer():
6
+ def __init__(self,return_type='bytes'):
7
+ self.return_type=return_type
8
+
9
+ def draw(self,description,style,filename=None):
10
+
11
+
12
+ """
13
+ 根据给定的艺术图像描述和风格编号,调用清韵AI艺术图创作API,并返回生成的图像内容。
14
+
15
+ :param description: str 艺术图像描述
16
+ :param style: int 图像风格编号(1-8)
17
+ :return: bytes 图像二进制数据
18
+ """
19
+
20
+ # 对描述进行URL编码
21
+ encoded_description = urllib.parse.quote(description)
22
+
23
+ # 构造请求URL
24
+ url = f"https://4147093qp2.imdo.co/aidrawnew?text={encoded_description}&syle={style}"#注意这里是syle,别问为什么
25
+
26
+ try:
27
+ # 发送GET请求
28
+ response = requests.get(url)
29
+
30
+ # 检查请求是否成功
31
+ if response.status_code == 200:
32
+ # 获取并返回图像二进制数据
33
+ if self.return_type=='bytes':
34
+ return response.content
35
+ elif self.return_type=='file':
36
+ with open(filename, "wb") as f:
37
+ f.write(response.content)
38
+ return None
39
+
40
+ else:
41
+ print(f"请求失败,状态码:{response.status_code}")
42
+ return None
43
+
44
+ except requests.exceptions.RequestException as e:
45
+ print(f"请求过程中发生错误:{e}")
46
+ return None
47
+
48
+ def help(self):
49
+ print('''风格编号(1-8):
50
+ 风格1 - 糖果 (candy)
51
+ 风格2 - 组成vii(composition vii)
52
+ 风格3 - 羽毛 (feathers)
53
+ 风格4 - la muse
54
+ 风格5 - 马赛克(mosaic)
55
+ 风格6 - 梵高·星空(starry_night)
56
+ 风格7 - 奶油(the_scream)
57
+ 风格8 - 波形(the_wave)
58
+ ——————————————————————————————————
59
+ 支持的return_type:1.'bytes'——返回为图像的二进制数据
60
+ 2.'file'——直接保存为filename
61
+
62
+ ''')
63
+
@@ -0,0 +1,30 @@
1
+ import os
2
+ def set_user(name):
3
+ p='C:'+os.environ['HOMEPATH']
4
+ try:
5
+ open(os.path.join(p,'xiaothink_conf.conf','rb'))
6
+ with open(os.path.join(p,'xiaothink_conf.conf'),'r',encoding='utf-8')as f:
7
+ data=eval(f.read())
8
+ except FileNotFoundError:
9
+
10
+ data={}
11
+
12
+ data['XIAOTHINK_USERNAME']=name
13
+ with open(os.path.join(p,'xiaothink_conf.conf'),'w',encoding='utf-8')as f:
14
+ f.write(str(data))
15
+
16
+ def get_key(key):
17
+ p='C:'+os.environ['HOMEPATH']
18
+ try:
19
+ #open(os.path.join(p,'xiaothink_conf.conf','rb'))
20
+ with open(os.path.join(p,'xiaothink_conf.conf'),'r',encoding='utf-8')as f:
21
+ data=eval(f.read())
22
+ except FileNotFoundError:
23
+
24
+ data={}
25
+ if key in list(data.keys()):
26
+ return data[key]
27
+ else:
28
+ return None
29
+
30
+
@@ -0,0 +1,23 @@
1
+ import requests
2
+ import urllib.parse
3
+
4
+
5
+ def write(original_text):
6
+ # 对原文内容进行URL编码
7
+ encoded_text = urllib.parse.quote(original_text)
8
+
9
+ # 构造API请求URL
10
+ api_url = f"https://4147093qp2.imdo.co/zhxxapi?inp={encoded_text}"
11
+
12
+ # 发送GET请求并获取响应
13
+ response = requests.get(api_url)
14
+
15
+ # 解析返回结果
16
+ result = response.json()
17
+
18
+ if result["Error"] == "None":
19
+ return original_text + result["text"]
20
+ else:
21
+ print("错误信息:", result["Error"])
22
+ return None
23
+
@@ -0,0 +1,19 @@
1
+ import requests
2
+
3
+ def get_score(image_url="https://4147093qp2.imdo.co/yanzhi/54.jpg"):
4
+ # API接口
5
+ api_url = f"https://4147093qp2.imdo.co/yanzhi?url={image_url}"
6
+
7
+
8
+ # 发送请求
9
+ response = requests.get(api_url)
10
+
11
+ # 检查请求是否成功
12
+ if response.status_code == 200:
13
+ # 从响应中获取颜值分数
14
+ beauty_score = float(response.json()['ret'])
15
+ return beauty_score
16
+ else:
17
+ print("Request failed with status code:", response.status_code)
18
+ return None
19
+
@@ -0,0 +1,16 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+ Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ of this software and associated documentation files (the "Software"), to deal
4
+ in the Software without restriction, including without limitation the rights
5
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6
+ copies of the Software, and to permit persons to whom the Software is
7
+ furnished to do so, subject to the following conditions:
8
+ The above copyright notice and this permission notice shall be included in all
9
+ copies or substantial portions of the Software.
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16
+ SOFTWARE.
@@ -0,0 +1,186 @@
1
+ Metadata-Version: 2.1
2
+ Name: xiaothink
3
+ Version: 1.0.0
4
+ Summary: 一个AI工具包,帮助用户快速调用小思框架(Xiaothink)相关接口。
5
+ Home-page: UNKNOWN
6
+ Author: Ericsjq
7
+ Author-email: xiaothink@foxmail.com
8
+ License: UNKNOWN
9
+ Platform: UNKNOWN
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: tensorflow
17
+ Requires-Dist: requests
18
+
19
+ # Xiaothink Python 模块使用文档
20
+
21
+ Xiaothink 是一个以自然语言处理(NLP)为核心的AI研究组织,致力于提供高效、灵活的工具来满足各种应用场景的需求。Xiaothink Python 模块是该组织提供的核心工具包,涵盖了图像生成、文本续写、颜值评分以及对话模型等多种功能。以下是详细的使用指南和代码示例。
22
+
23
+ ## 目录
24
+ 1. [安装](#安装)
25
+ 2. [图像生成](#图像生成)
26
+ 3. [文本续写](#文本续写)
27
+ 4. [颜值评分](#颜值评分)
28
+ 5. [在线AI对话](#在线ai对话)
29
+ 6. [本地对话模型](#本地对话模型)
30
+
31
+ ---
32
+
33
+ ## 安装
34
+
35
+ 首先,您需要通过 pip 安装 Xiaothink 模块:
36
+
37
+ ```bash
38
+ pip install xiaothink
39
+ ```
40
+
41
+ ---
42
+
43
+ ## 图像生成
44
+
45
+ Xiaothink 提供了强大的图像生成功能,可以通过简单的 API 调用来生成高质量的图像。
46
+
47
+ ### 示例代码
48
+
49
+ ```python
50
+ import xiaothink as xt
51
+
52
+ drawer = xt.openapi.drawer.Drawer(return_type='bytes')
53
+ with open('a.jpg', 'wb') as f:
54
+ f.write(drawer.draw('两只猫', style=6))
55
+ ```
56
+
57
+ ---
58
+
59
+ ## 文本续写
60
+
61
+ 您可以使用 Xiaothink 的文本续写功能来生成连贯且有意义的文本内容。
62
+
63
+ ### 示例代码
64
+
65
+ ```python
66
+ import xiaothink as xt
67
+
68
+ text = '从前,由一位老人,'
69
+ out_ = xt.openapi.writer.write(text)
70
+ print('续写内容:', out_)
71
+ ```
72
+
73
+ ---
74
+
75
+ ## 颜值评分
76
+
77
+ Xiaothink 提供了基于 Web URL 的颜值评分服务。请注意,该服务仅支持传入网络图片 URL,不支持本地路径。
78
+
79
+ ### 示例代码
80
+
81
+ ```python
82
+ import xiaothink as xt
83
+
84
+ image_url = "https://example.com/image.jpg"
85
+ num = xt.openapi.yanzhi.get_score(image_url)
86
+ print('颜值得分:', num)
87
+ ```
88
+
89
+ **重要提示**:`xt.openapi.yanzhi.get_score` 函数只支持传入 Web URL,不支持传入本地路径。
90
+
91
+ ---
92
+
93
+ ## 在线AI对话
94
+
95
+ Xiaothink 提供了一个简便易用的在线 AI 对话接口。设置用户名后即可进行多轮对话。
96
+
97
+
98
+ ### 示例代码
99
+
100
+ ```python
101
+ import xiaothink as xt
102
+
103
+ xt.openapi.set_conf.set_user('YOUR_USERNAME')
104
+
105
+ while True:
106
+ inp = input('【问】:')
107
+ re = xt.openapi.chatbot_old.chat(inp)
108
+ print('\n【答】:', re, '\n')
109
+ ```
110
+
111
+ **重要提示**:在线 AI 对话与本地模型对话是两个完全不同的系统,毫无关系。`xt.openapi.chatbot_old.chat` 函数设置用户名后便支持多轮对话。
112
+
113
+ ---
114
+
115
+ ## 本地对话模型
116
+
117
+ 对于本地加载的对话模型,根据模型类型的不同,应调用相应的函数来进行对话。
118
+
119
+ ### 单轮对话
120
+
121
+ 适用于单轮对话场景。
122
+
123
+ ### 示例代码
124
+
125
+ ```python
126
+ import xiaothink.llm.inference.test_formal as tf
127
+
128
+ model = tf.QianyanModel(
129
+ ckpt_dir=r'E:\小思框架\论文\ganskchat\ckpt_test_40_2_3_1_formal_open',
130
+ MT=40.231,
131
+ vocab=r'E:\小思框架\论文\ganskchat\vocab_lx3.txt'
132
+ )
133
+
134
+ while True:
135
+ inp = input('【问】:')
136
+ if inp == '[CLEAN]':
137
+ print('【清空上下文】\n\n')
138
+ model.clean_his()
139
+ continue
140
+ re = model.chat_SingleTurn(inp) # 使用 chat_SingleTurn 进行单轮对话
141
+ print('\n【答】:', re, '\n')
142
+ ```
143
+
144
+ ### 多轮对话
145
+
146
+ 适用于多轮对话场景。
147
+
148
+ ### 示例代码
149
+
150
+ ```python
151
+ import xiaothink.llm.inference.test as test
152
+
153
+ MT = 40.231
154
+ m, d = test.load(
155
+ ckpt_dir=r'E:\小思框架\论文\ganskchat\ckpt_test_40_2_3_1_qas',
156
+ model_type=MT,
157
+ vocab=r'E:\小思框架\论文\ganskchat\vocab_lx3.txt',
158
+ )
159
+
160
+ b_chat = {
161
+ 1: '给定一个数字列表,找出其中的最大值和最小值。\n数字列表:[3, 9, 2, 7, 5, 1, 8, 4, 6, 0]',
162
+ 2: '请生成一段关于“春风”为主题的短故事,提供完整的答案。\n',
163
+ 3: '请回答下列问题:“什么是全球变暖?”\n',
164
+ 4: '请创建一个简单的Python程序,用于计算两数乘积\n',
165
+ 5: '创建一个简单的计算器,并提供任何必需的数学原理。\n',
166
+ 6: '根据给定的单词,生成与该单词相关的五个同义词。\n单词:友谊\n',
167
+ }[6]
168
+
169
+ belle_chat = '{"instruction": "{b_chat}", "input": "", "output": "'.replace('{b_chat}', b_chat)
170
+ inp_m = belle_chat
171
+
172
+ ret = test.generate_texts_loop(m, d, inp_m,
173
+ num_generate=100,
174
+ every=lambda a: print(a, end='', flush=True),
175
+ temperature=0.55,
176
+ pass_char=['▩'])
177
+ ```
178
+
179
+ **重要提示**:对于本地模型,单论对话模型应调用 `model.chat_SingleTurn` 函数,多轮对话模型应调用 `model.chat` 函数。
180
+
181
+ ---
182
+
183
+ 以上就是 Xiaothink Python 模块的主要功能及使用方法。
184
+
185
+ 如有任何疑问或建议,请随时联系我们:xiaothink@foxmail.com。
186
+
@@ -0,0 +1,12 @@
1
+ xiaothink/__init__.py,sha256=Txr_4qpdb_LCW0PhWcJ-NCvuZ2kirL9BHSBjJFnShNA,242
2
+ xiaothink/openapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ xiaothink/openapi/chatbot_old.py,sha256=qgpN-Yxzj1h-zxt5tS44nKz7vfYp8f_QU5KjRcZL74Y,830
4
+ xiaothink/openapi/drawer.py,sha256=gVHJIIRWZ1CNwPvqgd--2NWaPd9U7K9hlOc11dp06jY,2238
5
+ xiaothink/openapi/set_conf.py,sha256=AY6CbPz4rIcVi3k1Km1MUQYPEQmuFjRNu__rNUERIms,881
6
+ xiaothink/openapi/writer.py,sha256=yLIq1hoP_UFOsLbD9T8_95by4XfO4U3Ly1XFACd7j94,570
7
+ xiaothink/openapi/yanzhi.py,sha256=-1NdT5fd2WesbKNCJ0V5-t_fSvXlcIUA4z5T_6yKhcg,547
8
+ xiaothink-1.0.0.dist-info/LICENSE,sha256=GzHS9pi6vw_oGwKIGxAPch8iuVrHazOilEsYL7AlPK0,1085
9
+ xiaothink-1.0.0.dist-info/METADATA,sha256=hz-B4o1Ov0GXclSRsqk3DxIh0GgpO3pc-JC71IzF9Bo,5151
10
+ xiaothink-1.0.0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
11
+ xiaothink-1.0.0.dist-info/top_level.txt,sha256=2Dpv6MYJdOSpU2IK6tlPtmzt28b11pOV72BPRH4tRpE,10
12
+ xiaothink-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.37.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ xiaothink