xiaothink 1.0.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.
- xiaothink-1.0.0/LICENSE +16 -0
- xiaothink-1.0.0/PKG-INFO +184 -0
- xiaothink-1.0.0/README.md +167 -0
- xiaothink-1.0.0/setup.cfg +4 -0
- xiaothink-1.0.0/setup.py +28 -0
- xiaothink-1.0.0/xiaothink/__init__.py +7 -0
- xiaothink-1.0.0/xiaothink/openapi/__init__.py +0 -0
- xiaothink-1.0.0/xiaothink/openapi/chatbot_old.py +29 -0
- xiaothink-1.0.0/xiaothink/openapi/drawer.py +63 -0
- xiaothink-1.0.0/xiaothink/openapi/set_conf.py +30 -0
- xiaothink-1.0.0/xiaothink/openapi/writer.py +23 -0
- xiaothink-1.0.0/xiaothink/openapi/yanzhi.py +19 -0
- xiaothink-1.0.0/xiaothink.egg-info/PKG-INFO +184 -0
- xiaothink-1.0.0/xiaothink.egg-info/SOURCES.txt +15 -0
- xiaothink-1.0.0/xiaothink.egg-info/dependency_links.txt +1 -0
- xiaothink-1.0.0/xiaothink.egg-info/requires.txt +2 -0
- xiaothink-1.0.0/xiaothink.egg-info/top_level.txt +1 -0
xiaothink-1.0.0/LICENSE
ADDED
|
@@ -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.
|
xiaothink-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
|
|
17
|
+
# Xiaothink Python 模块使用文档
|
|
18
|
+
|
|
19
|
+
Xiaothink 是一个以自然语言处理(NLP)为核心的AI研究组织,致力于提供高效、灵活的工具来满足各种应用场景的需求。Xiaothink Python 模块是该组织提供的核心工具包,涵盖了图像生成、文本续写、颜值评分以及对话模型等多种功能。以下是详细的使用指南和代码示例。
|
|
20
|
+
|
|
21
|
+
## 目录
|
|
22
|
+
1. [安装](#安装)
|
|
23
|
+
2. [图像生成](#图像生成)
|
|
24
|
+
3. [文本续写](#文本续写)
|
|
25
|
+
4. [颜值评分](#颜值评分)
|
|
26
|
+
5. [在线AI对话](#在线ai对话)
|
|
27
|
+
6. [本地对话模型](#本地对话模型)
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 安装
|
|
32
|
+
|
|
33
|
+
首先,您需要通过 pip 安装 Xiaothink 模块:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install xiaothink
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 图像生成
|
|
42
|
+
|
|
43
|
+
Xiaothink 提供了强大的图像生成功能,可以通过简单的 API 调用来生成高质量的图像。
|
|
44
|
+
|
|
45
|
+
### 示例代码
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import xiaothink as xt
|
|
49
|
+
|
|
50
|
+
drawer = xt.openapi.drawer.Drawer(return_type='bytes')
|
|
51
|
+
with open('a.jpg', 'wb') as f:
|
|
52
|
+
f.write(drawer.draw('两只猫', style=6))
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 文本续写
|
|
58
|
+
|
|
59
|
+
您可以使用 Xiaothink 的文本续写功能来生成连贯且有意义的文本内容。
|
|
60
|
+
|
|
61
|
+
### 示例代码
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import xiaothink as xt
|
|
65
|
+
|
|
66
|
+
text = '从前,由一位老人,'
|
|
67
|
+
out_ = xt.openapi.writer.write(text)
|
|
68
|
+
print('续写内容:', out_)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 颜值评分
|
|
74
|
+
|
|
75
|
+
Xiaothink 提供了基于 Web URL 的颜值评分服务。请注意,该服务仅支持传入网络图片 URL,不支持本地路径。
|
|
76
|
+
|
|
77
|
+
### 示例代码
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import xiaothink as xt
|
|
81
|
+
|
|
82
|
+
image_url = "https://example.com/image.jpg"
|
|
83
|
+
num = xt.openapi.yanzhi.get_score(image_url)
|
|
84
|
+
print('颜值得分:', num)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**重要提示**:`xt.openapi.yanzhi.get_score` 函数只支持传入 Web URL,不支持传入本地路径。
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 在线AI对话
|
|
92
|
+
|
|
93
|
+
Xiaothink 提供了一个简便易用的在线 AI 对话接口。设置用户名后即可进行多轮对话。
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### 示例代码
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
import xiaothink as xt
|
|
100
|
+
|
|
101
|
+
xt.openapi.set_conf.set_user('YOUR_USERNAME')
|
|
102
|
+
|
|
103
|
+
while True:
|
|
104
|
+
inp = input('【问】:')
|
|
105
|
+
re = xt.openapi.chatbot_old.chat(inp)
|
|
106
|
+
print('\n【答】:', re, '\n')
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**重要提示**:在线 AI 对话与本地模型对话是两个完全不同的系统,毫无关系。`xt.openapi.chatbot_old.chat` 函数设置用户名后便支持多轮对话。
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 本地对话模型
|
|
114
|
+
|
|
115
|
+
对于本地加载的对话模型,根据模型类型的不同,应调用相应的函数来进行对话。
|
|
116
|
+
|
|
117
|
+
### 单轮对话
|
|
118
|
+
|
|
119
|
+
适用于单轮对话场景。
|
|
120
|
+
|
|
121
|
+
### 示例代码
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
import xiaothink.llm.inference.test_formal as tf
|
|
125
|
+
|
|
126
|
+
model = tf.QianyanModel(
|
|
127
|
+
ckpt_dir=r'E:\小思框架\论文\ganskchat\ckpt_test_40_2_3_1_formal_open',
|
|
128
|
+
MT=40.231,
|
|
129
|
+
vocab=r'E:\小思框架\论文\ganskchat\vocab_lx3.txt'
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
while True:
|
|
133
|
+
inp = input('【问】:')
|
|
134
|
+
if inp == '[CLEAN]':
|
|
135
|
+
print('【清空上下文】\n\n')
|
|
136
|
+
model.clean_his()
|
|
137
|
+
continue
|
|
138
|
+
re = model.chat_SingleTurn(inp) # 使用 chat_SingleTurn 进行单轮对话
|
|
139
|
+
print('\n【答】:', re, '\n')
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 多轮对话
|
|
143
|
+
|
|
144
|
+
适用于多轮对话场景。
|
|
145
|
+
|
|
146
|
+
### 示例代码
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
import xiaothink.llm.inference.test as test
|
|
150
|
+
|
|
151
|
+
MT = 40.231
|
|
152
|
+
m, d = test.load(
|
|
153
|
+
ckpt_dir=r'E:\小思框架\论文\ganskchat\ckpt_test_40_2_3_1_qas',
|
|
154
|
+
model_type=MT,
|
|
155
|
+
vocab=r'E:\小思框架\论文\ganskchat\vocab_lx3.txt',
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
b_chat = {
|
|
159
|
+
1: '给定一个数字列表,找出其中的最大值和最小值。\n数字列表:[3, 9, 2, 7, 5, 1, 8, 4, 6, 0]',
|
|
160
|
+
2: '请生成一段关于“春风”为主题的短故事,提供完整的答案。\n',
|
|
161
|
+
3: '请回答下列问题:“什么是全球变暖?”\n',
|
|
162
|
+
4: '请创建一个简单的Python程序,用于计算两数乘积\n',
|
|
163
|
+
5: '创建一个简单的计算器,并提供任何必需的数学原理。\n',
|
|
164
|
+
6: '根据给定的单词,生成与该单词相关的五个同义词。\n单词:友谊\n',
|
|
165
|
+
}[6]
|
|
166
|
+
|
|
167
|
+
belle_chat = '{"instruction": "{b_chat}", "input": "", "output": "'.replace('{b_chat}', b_chat)
|
|
168
|
+
inp_m = belle_chat
|
|
169
|
+
|
|
170
|
+
ret = test.generate_texts_loop(m, d, inp_m,
|
|
171
|
+
num_generate=100,
|
|
172
|
+
every=lambda a: print(a, end='', flush=True),
|
|
173
|
+
temperature=0.55,
|
|
174
|
+
pass_char=['▩'])
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**重要提示**:对于本地模型,单论对话模型应调用 `model.chat_SingleTurn` 函数,多轮对话模型应调用 `model.chat` 函数。
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
以上就是 Xiaothink Python 模块的主要功能及使用方法。
|
|
182
|
+
|
|
183
|
+
如有任何疑问或建议,请随时联系我们:xiaothink@foxmail.com。
|
|
184
|
+
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Xiaothink Python 模块使用文档
|
|
2
|
+
|
|
3
|
+
Xiaothink 是一个以自然语言处理(NLP)为核心的AI研究组织,致力于提供高效、灵活的工具来满足各种应用场景的需求。Xiaothink Python 模块是该组织提供的核心工具包,涵盖了图像生成、文本续写、颜值评分以及对话模型等多种功能。以下是详细的使用指南和代码示例。
|
|
4
|
+
|
|
5
|
+
## 目录
|
|
6
|
+
1. [安装](#安装)
|
|
7
|
+
2. [图像生成](#图像生成)
|
|
8
|
+
3. [文本续写](#文本续写)
|
|
9
|
+
4. [颜值评分](#颜值评分)
|
|
10
|
+
5. [在线AI对话](#在线ai对话)
|
|
11
|
+
6. [本地对话模型](#本地对话模型)
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
首先,您需要通过 pip 安装 Xiaothink 模块:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install xiaothink
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 图像生成
|
|
26
|
+
|
|
27
|
+
Xiaothink 提供了强大的图像生成功能,可以通过简单的 API 调用来生成高质量的图像。
|
|
28
|
+
|
|
29
|
+
### 示例代码
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import xiaothink as xt
|
|
33
|
+
|
|
34
|
+
drawer = xt.openapi.drawer.Drawer(return_type='bytes')
|
|
35
|
+
with open('a.jpg', 'wb') as f:
|
|
36
|
+
f.write(drawer.draw('两只猫', style=6))
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 文本续写
|
|
42
|
+
|
|
43
|
+
您可以使用 Xiaothink 的文本续写功能来生成连贯且有意义的文本内容。
|
|
44
|
+
|
|
45
|
+
### 示例代码
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import xiaothink as xt
|
|
49
|
+
|
|
50
|
+
text = '从前,由一位老人,'
|
|
51
|
+
out_ = xt.openapi.writer.write(text)
|
|
52
|
+
print('续写内容:', out_)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 颜值评分
|
|
58
|
+
|
|
59
|
+
Xiaothink 提供了基于 Web URL 的颜值评分服务。请注意,该服务仅支持传入网络图片 URL,不支持本地路径。
|
|
60
|
+
|
|
61
|
+
### 示例代码
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import xiaothink as xt
|
|
65
|
+
|
|
66
|
+
image_url = "https://example.com/image.jpg"
|
|
67
|
+
num = xt.openapi.yanzhi.get_score(image_url)
|
|
68
|
+
print('颜值得分:', num)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**重要提示**:`xt.openapi.yanzhi.get_score` 函数只支持传入 Web URL,不支持传入本地路径。
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 在线AI对话
|
|
76
|
+
|
|
77
|
+
Xiaothink 提供了一个简便易用的在线 AI 对话接口。设置用户名后即可进行多轮对话。
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
### 示例代码
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import xiaothink as xt
|
|
84
|
+
|
|
85
|
+
xt.openapi.set_conf.set_user('YOUR_USERNAME')
|
|
86
|
+
|
|
87
|
+
while True:
|
|
88
|
+
inp = input('【问】:')
|
|
89
|
+
re = xt.openapi.chatbot_old.chat(inp)
|
|
90
|
+
print('\n【答】:', re, '\n')
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**重要提示**:在线 AI 对话与本地模型对话是两个完全不同的系统,毫无关系。`xt.openapi.chatbot_old.chat` 函数设置用户名后便支持多轮对话。
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 本地对话模型
|
|
98
|
+
|
|
99
|
+
对于本地加载的对话模型,根据模型类型的不同,应调用相应的函数来进行对话。
|
|
100
|
+
|
|
101
|
+
### 单轮对话
|
|
102
|
+
|
|
103
|
+
适用于单轮对话场景。
|
|
104
|
+
|
|
105
|
+
### 示例代码
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
import xiaothink.llm.inference.test_formal as tf
|
|
109
|
+
|
|
110
|
+
model = tf.QianyanModel(
|
|
111
|
+
ckpt_dir=r'E:\小思框架\论文\ganskchat\ckpt_test_40_2_3_1_formal_open',
|
|
112
|
+
MT=40.231,
|
|
113
|
+
vocab=r'E:\小思框架\论文\ganskchat\vocab_lx3.txt'
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
while True:
|
|
117
|
+
inp = input('【问】:')
|
|
118
|
+
if inp == '[CLEAN]':
|
|
119
|
+
print('【清空上下文】\n\n')
|
|
120
|
+
model.clean_his()
|
|
121
|
+
continue
|
|
122
|
+
re = model.chat_SingleTurn(inp) # 使用 chat_SingleTurn 进行单轮对话
|
|
123
|
+
print('\n【答】:', re, '\n')
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 多轮对话
|
|
127
|
+
|
|
128
|
+
适用于多轮对话场景。
|
|
129
|
+
|
|
130
|
+
### 示例代码
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
import xiaothink.llm.inference.test as test
|
|
134
|
+
|
|
135
|
+
MT = 40.231
|
|
136
|
+
m, d = test.load(
|
|
137
|
+
ckpt_dir=r'E:\小思框架\论文\ganskchat\ckpt_test_40_2_3_1_qas',
|
|
138
|
+
model_type=MT,
|
|
139
|
+
vocab=r'E:\小思框架\论文\ganskchat\vocab_lx3.txt',
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
b_chat = {
|
|
143
|
+
1: '给定一个数字列表,找出其中的最大值和最小值。\n数字列表:[3, 9, 2, 7, 5, 1, 8, 4, 6, 0]',
|
|
144
|
+
2: '请生成一段关于“春风”为主题的短故事,提供完整的答案。\n',
|
|
145
|
+
3: '请回答下列问题:“什么是全球变暖?”\n',
|
|
146
|
+
4: '请创建一个简单的Python程序,用于计算两数乘积\n',
|
|
147
|
+
5: '创建一个简单的计算器,并提供任何必需的数学原理。\n',
|
|
148
|
+
6: '根据给定的单词,生成与该单词相关的五个同义词。\n单词:友谊\n',
|
|
149
|
+
}[6]
|
|
150
|
+
|
|
151
|
+
belle_chat = '{"instruction": "{b_chat}", "input": "", "output": "'.replace('{b_chat}', b_chat)
|
|
152
|
+
inp_m = belle_chat
|
|
153
|
+
|
|
154
|
+
ret = test.generate_texts_loop(m, d, inp_m,
|
|
155
|
+
num_generate=100,
|
|
156
|
+
every=lambda a: print(a, end='', flush=True),
|
|
157
|
+
temperature=0.55,
|
|
158
|
+
pass_char=['▩'])
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**重要提示**:对于本地模型,单论对话模型应调用 `model.chat_SingleTurn` 函数,多轮对话模型应调用 `model.chat` 函数。
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
以上就是 Xiaothink Python 模块的主要功能及使用方法。
|
|
166
|
+
|
|
167
|
+
如有任何疑问或建议,请随时联系我们:xiaothink@foxmail.com。
|
xiaothink-1.0.0/setup.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
import setuptools
|
|
3
|
+
with open("README.md", "r",encoding='utf-8') as fh:
|
|
4
|
+
long_description = fh.read()
|
|
5
|
+
|
|
6
|
+
setuptools.setup(
|
|
7
|
+
name="xiaothink", # 模块名称
|
|
8
|
+
version="1.0.0", # 当前版本
|
|
9
|
+
author="Ericsjq", # 作者
|
|
10
|
+
author_email="xiaothink@foxmail.com", # 作者邮箱
|
|
11
|
+
description="一个AI工具包,帮助用户快速调用小思框架(Xiaothink)相关接口。", # 模块简介
|
|
12
|
+
long_description=long_description, # 模块详细介绍
|
|
13
|
+
long_description_content_type="text/markdown", # 模块详细介绍格式
|
|
14
|
+
packages=setuptools.find_packages(), # 自动找到项目中导入的模块
|
|
15
|
+
# 模块相关的元数据
|
|
16
|
+
classifiers=[
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
],
|
|
21
|
+
# 依赖模块
|
|
22
|
+
install_requires=[
|
|
23
|
+
'tensorflow',
|
|
24
|
+
'requests',
|
|
25
|
+
],
|
|
26
|
+
python_requires='>=3',
|
|
27
|
+
|
|
28
|
+
)
|
|
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,184 @@
|
|
|
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
|
+
|
|
17
|
+
# Xiaothink Python 模块使用文档
|
|
18
|
+
|
|
19
|
+
Xiaothink 是一个以自然语言处理(NLP)为核心的AI研究组织,致力于提供高效、灵活的工具来满足各种应用场景的需求。Xiaothink Python 模块是该组织提供的核心工具包,涵盖了图像生成、文本续写、颜值评分以及对话模型等多种功能。以下是详细的使用指南和代码示例。
|
|
20
|
+
|
|
21
|
+
## 目录
|
|
22
|
+
1. [安装](#安装)
|
|
23
|
+
2. [图像生成](#图像生成)
|
|
24
|
+
3. [文本续写](#文本续写)
|
|
25
|
+
4. [颜值评分](#颜值评分)
|
|
26
|
+
5. [在线AI对话](#在线ai对话)
|
|
27
|
+
6. [本地对话模型](#本地对话模型)
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 安装
|
|
32
|
+
|
|
33
|
+
首先,您需要通过 pip 安装 Xiaothink 模块:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install xiaothink
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 图像生成
|
|
42
|
+
|
|
43
|
+
Xiaothink 提供了强大的图像生成功能,可以通过简单的 API 调用来生成高质量的图像。
|
|
44
|
+
|
|
45
|
+
### 示例代码
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import xiaothink as xt
|
|
49
|
+
|
|
50
|
+
drawer = xt.openapi.drawer.Drawer(return_type='bytes')
|
|
51
|
+
with open('a.jpg', 'wb') as f:
|
|
52
|
+
f.write(drawer.draw('两只猫', style=6))
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 文本续写
|
|
58
|
+
|
|
59
|
+
您可以使用 Xiaothink 的文本续写功能来生成连贯且有意义的文本内容。
|
|
60
|
+
|
|
61
|
+
### 示例代码
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import xiaothink as xt
|
|
65
|
+
|
|
66
|
+
text = '从前,由一位老人,'
|
|
67
|
+
out_ = xt.openapi.writer.write(text)
|
|
68
|
+
print('续写内容:', out_)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 颜值评分
|
|
74
|
+
|
|
75
|
+
Xiaothink 提供了基于 Web URL 的颜值评分服务。请注意,该服务仅支持传入网络图片 URL,不支持本地路径。
|
|
76
|
+
|
|
77
|
+
### 示例代码
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import xiaothink as xt
|
|
81
|
+
|
|
82
|
+
image_url = "https://example.com/image.jpg"
|
|
83
|
+
num = xt.openapi.yanzhi.get_score(image_url)
|
|
84
|
+
print('颜值得分:', num)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**重要提示**:`xt.openapi.yanzhi.get_score` 函数只支持传入 Web URL,不支持传入本地路径。
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 在线AI对话
|
|
92
|
+
|
|
93
|
+
Xiaothink 提供了一个简便易用的在线 AI 对话接口。设置用户名后即可进行多轮对话。
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### 示例代码
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
import xiaothink as xt
|
|
100
|
+
|
|
101
|
+
xt.openapi.set_conf.set_user('YOUR_USERNAME')
|
|
102
|
+
|
|
103
|
+
while True:
|
|
104
|
+
inp = input('【问】:')
|
|
105
|
+
re = xt.openapi.chatbot_old.chat(inp)
|
|
106
|
+
print('\n【答】:', re, '\n')
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**重要提示**:在线 AI 对话与本地模型对话是两个完全不同的系统,毫无关系。`xt.openapi.chatbot_old.chat` 函数设置用户名后便支持多轮对话。
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 本地对话模型
|
|
114
|
+
|
|
115
|
+
对于本地加载的对话模型,根据模型类型的不同,应调用相应的函数来进行对话。
|
|
116
|
+
|
|
117
|
+
### 单轮对话
|
|
118
|
+
|
|
119
|
+
适用于单轮对话场景。
|
|
120
|
+
|
|
121
|
+
### 示例代码
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
import xiaothink.llm.inference.test_formal as tf
|
|
125
|
+
|
|
126
|
+
model = tf.QianyanModel(
|
|
127
|
+
ckpt_dir=r'E:\小思框架\论文\ganskchat\ckpt_test_40_2_3_1_formal_open',
|
|
128
|
+
MT=40.231,
|
|
129
|
+
vocab=r'E:\小思框架\论文\ganskchat\vocab_lx3.txt'
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
while True:
|
|
133
|
+
inp = input('【问】:')
|
|
134
|
+
if inp == '[CLEAN]':
|
|
135
|
+
print('【清空上下文】\n\n')
|
|
136
|
+
model.clean_his()
|
|
137
|
+
continue
|
|
138
|
+
re = model.chat_SingleTurn(inp) # 使用 chat_SingleTurn 进行单轮对话
|
|
139
|
+
print('\n【答】:', re, '\n')
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 多轮对话
|
|
143
|
+
|
|
144
|
+
适用于多轮对话场景。
|
|
145
|
+
|
|
146
|
+
### 示例代码
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
import xiaothink.llm.inference.test as test
|
|
150
|
+
|
|
151
|
+
MT = 40.231
|
|
152
|
+
m, d = test.load(
|
|
153
|
+
ckpt_dir=r'E:\小思框架\论文\ganskchat\ckpt_test_40_2_3_1_qas',
|
|
154
|
+
model_type=MT,
|
|
155
|
+
vocab=r'E:\小思框架\论文\ganskchat\vocab_lx3.txt',
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
b_chat = {
|
|
159
|
+
1: '给定一个数字列表,找出其中的最大值和最小值。\n数字列表:[3, 9, 2, 7, 5, 1, 8, 4, 6, 0]',
|
|
160
|
+
2: '请生成一段关于“春风”为主题的短故事,提供完整的答案。\n',
|
|
161
|
+
3: '请回答下列问题:“什么是全球变暖?”\n',
|
|
162
|
+
4: '请创建一个简单的Python程序,用于计算两数乘积\n',
|
|
163
|
+
5: '创建一个简单的计算器,并提供任何必需的数学原理。\n',
|
|
164
|
+
6: '根据给定的单词,生成与该单词相关的五个同义词。\n单词:友谊\n',
|
|
165
|
+
}[6]
|
|
166
|
+
|
|
167
|
+
belle_chat = '{"instruction": "{b_chat}", "input": "", "output": "'.replace('{b_chat}', b_chat)
|
|
168
|
+
inp_m = belle_chat
|
|
169
|
+
|
|
170
|
+
ret = test.generate_texts_loop(m, d, inp_m,
|
|
171
|
+
num_generate=100,
|
|
172
|
+
every=lambda a: print(a, end='', flush=True),
|
|
173
|
+
temperature=0.55,
|
|
174
|
+
pass_char=['▩'])
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**重要提示**:对于本地模型,单论对话模型应调用 `model.chat_SingleTurn` 函数,多轮对话模型应调用 `model.chat` 函数。
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
以上就是 Xiaothink Python 模块的主要功能及使用方法。
|
|
182
|
+
|
|
183
|
+
如有任何疑问或建议,请随时联系我们:xiaothink@foxmail.com。
|
|
184
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
xiaothink/__init__.py
|
|
5
|
+
xiaothink.egg-info/PKG-INFO
|
|
6
|
+
xiaothink.egg-info/SOURCES.txt
|
|
7
|
+
xiaothink.egg-info/dependency_links.txt
|
|
8
|
+
xiaothink.egg-info/requires.txt
|
|
9
|
+
xiaothink.egg-info/top_level.txt
|
|
10
|
+
xiaothink/openapi/__init__.py
|
|
11
|
+
xiaothink/openapi/chatbot_old.py
|
|
12
|
+
xiaothink/openapi/drawer.py
|
|
13
|
+
xiaothink/openapi/set_conf.py
|
|
14
|
+
xiaothink/openapi/writer.py
|
|
15
|
+
xiaothink/openapi/yanzhi.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
xiaothink
|