pycoze 0.1.222__py3-none-any.whl → 0.1.224__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pycoze/ai/__init__.py +1 -1
- pycoze/ai/llm/{think.py → chat.py} +8 -8
- pycoze/ai/llm/text_to_image_prompt.py +1 -1
- {pycoze-0.1.222.dist-info → pycoze-0.1.224.dist-info}/METADATA +1 -1
- {pycoze-0.1.222.dist-info → pycoze-0.1.224.dist-info}/RECORD +8 -8
- {pycoze-0.1.222.dist-info → pycoze-0.1.224.dist-info}/LICENSE +0 -0
- {pycoze-0.1.222.dist-info → pycoze-0.1.224.dist-info}/WHEEL +0 -0
- {pycoze-0.1.222.dist-info → pycoze-0.1.224.dist-info}/top_level.txt +0 -0
pycoze/ai/__init__.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
from .vram_reserve import reserve_vram, reserve_vram_retry, unreserve_vram
|
2
|
-
from .llm import
|
2
|
+
from .llm import chat, chat_stream, extract, yes_or_no, extract_code
|
@@ -13,7 +13,7 @@ def never_retry_on_rate_limit_error(exception):
|
|
13
13
|
return not isinstance(exception, openai.RateLimitError)
|
14
14
|
|
15
15
|
@retry(retry_on_exception=never_retry_on_rate_limit_error, wait_exponential_multiplier=500, stop_max_attempt_number=5)
|
16
|
-
def
|
16
|
+
def chat(user_text, history, temperature=0.2, stop=None, **kwargs):
|
17
17
|
user_msg = {"role": "user", "content": user_text}
|
18
18
|
cfg = utils.read_json_file("llm.json")
|
19
19
|
|
@@ -33,7 +33,7 @@ def think(user_text, history, temperature=0.2, stop=None, **kwargs):
|
|
33
33
|
|
34
34
|
|
35
35
|
@retry(retry_on_exception=never_retry_on_rate_limit_error, wait_exponential_multiplier=500, stop_max_attempt_number=5)
|
36
|
-
def
|
36
|
+
def chat_stream(user_text, history, temperature=0.2, stop=None, **kwargs):
|
37
37
|
user_msg = {"role": "user", "content": user_text}
|
38
38
|
cfg = utils.read_json_file("llm.json")
|
39
39
|
|
@@ -73,7 +73,7 @@ def extract(response_data, text: str, temperature=0, **kwargs):
|
|
73
73
|
json_text += f' "{res[0]}": {res[1]}{comma}\n'
|
74
74
|
|
75
75
|
# Combine the provided text with the formatted JSON schema
|
76
|
-
|
76
|
+
chat_text = f"""
|
77
77
|
The output should be a markdown code snippet formatted in the following schema, including the leading and trailing "```json" and "```" tags:
|
78
78
|
```json
|
79
79
|
{{
|
@@ -85,7 +85,7 @@ Request:
|
|
85
85
|
{text}
|
86
86
|
"""
|
87
87
|
# text放后面,当翻译等情况时,不会把"The output should"之类翻译了,导致错误
|
88
|
-
markdown =
|
88
|
+
markdown = chat(chat_text, [], temperature=temperature, **kwargs)
|
89
89
|
pattern = r'```json(.*?)```'
|
90
90
|
matches = re.findall(pattern, markdown, re.DOTALL)
|
91
91
|
if matches:
|
@@ -109,10 +109,10 @@ def yes_or_no(question, temperature=0, **kwargs):
|
|
109
109
|
@retry(retry_on_exception=never_retry_on_rate_limit_error, wait_exponential_multiplier=500, stop_max_attempt_number=3)
|
110
110
|
def extract_code(text: str, temperature=0, language="python", markdown_word='python', **kwargs):
|
111
111
|
"""print(extract_code("sum 1~100"))"""
|
112
|
-
|
112
|
+
chat_text = text + f"""
|
113
113
|
The output should be a complete and usable {language} code snippet, including the leading and trailing "```{markdown_word}" and "```":
|
114
114
|
"""
|
115
|
-
markdown =
|
115
|
+
markdown = chat(chat_text, [], temperature=temperature, **kwargs)
|
116
116
|
# 使用正则表达式匹配围绕在```{markdown_word} 和 ```之间的文本
|
117
117
|
pattern = rf'```{markdown_word}(.*?)```'
|
118
118
|
matches = re.findall(pattern, markdown, re.DOTALL)
|
@@ -124,8 +124,8 @@ The output should be a complete and usable {language} code snippet, including th
|
|
124
124
|
|
125
125
|
|
126
126
|
if __name__ == "__main__":
|
127
|
-
print(
|
128
|
-
for chunk in
|
127
|
+
print(chat("你好", []))
|
128
|
+
for chunk in chat_stream("你好", []):
|
129
129
|
print(chunk)
|
130
130
|
print(extract({"name": "lowercase"}, "hello XiaoMing"))
|
131
131
|
print(extract_code("sum 1~100"))
|
@@ -1,9 +1,9 @@
|
|
1
1
|
pycoze/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
pycoze/ai/__init__.py,sha256=
|
2
|
+
pycoze/ai/__init__.py,sha256=NXuVbrGq--anVWC5v9gWbv6PwJgAcY5cigmYUtR4_TY,143
|
3
3
|
pycoze/ai/vram_reserve.py,sha256=brgXP42yj3yaZRgW8pfgc4Jg9EivAhcbp5W4igVHcow,4256
|
4
4
|
pycoze/ai/llm/__init__.py,sha256=Pc7eYhrzkZqNXNPKkbd1tyoizdlGm9a60J9NGr1v3RQ,128
|
5
|
-
pycoze/ai/llm/
|
6
|
-
pycoze/ai/llm/
|
5
|
+
pycoze/ai/llm/chat.py,sha256=izriC7nCp5qeJRqcUVQBVqTHiH6MJS77ROzGBJufdNI,5133
|
6
|
+
pycoze/ai/llm/text_to_image_prompt.py,sha256=NdfhPTOTSR4whGgd10UtyQjzQCat0wdcX94OLSt4gUU,3333
|
7
7
|
pycoze/automation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
8
|
pycoze/automation/browser/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
9
|
pycoze/automation/browser/edge_driver_manager.py,sha256=gpgseunph5owZH6EskSYthuhey2SU3UP204gY0yIcuI,3022
|
@@ -31,8 +31,8 @@ pycoze/utils/__init__.py,sha256=Gi5EnrWZGMD2JRejgV4c_VLCXyvA2wwBFI_niDF5MUE,110
|
|
31
31
|
pycoze/utils/arg.py,sha256=GtfGbMTMdaK75Fwh6MpUe1pCA5X6Ep4LFG7a72YrzjI,525
|
32
32
|
pycoze/utils/env.py,sha256=W04lhvTHhAAC6EldP6kk2xrctqtu8K6kl1vDLZDNeh8,561
|
33
33
|
pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
|
34
|
-
pycoze-0.1.
|
35
|
-
pycoze-0.1.
|
36
|
-
pycoze-0.1.
|
37
|
-
pycoze-0.1.
|
38
|
-
pycoze-0.1.
|
34
|
+
pycoze-0.1.224.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
35
|
+
pycoze-0.1.224.dist-info/METADATA,sha256=ob_lZ2FP3Je8D8C6RJJSBxRhEa36nTHBtwOiuYWpsKk,726
|
36
|
+
pycoze-0.1.224.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
|
37
|
+
pycoze-0.1.224.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
38
|
+
pycoze-0.1.224.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|