pycoze 0.1.292__py3-none-any.whl → 0.1.294__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.
- pycoze/ai/llm/chat.py +46 -1
- {pycoze-0.1.292.dist-info → pycoze-0.1.294.dist-info}/METADATA +1 -1
- {pycoze-0.1.292.dist-info → pycoze-0.1.294.dist-info}/RECORD +6 -6
- {pycoze-0.1.292.dist-info → pycoze-0.1.294.dist-info}/LICENSE +0 -0
- {pycoze-0.1.292.dist-info → pycoze-0.1.294.dist-info}/WHEEL +0 -0
- {pycoze-0.1.292.dist-info → pycoze-0.1.294.dist-info}/top_level.txt +0 -0
pycoze/ai/llm/chat.py
CHANGED
@@ -2,7 +2,7 @@ from pycoze import utils
|
|
2
2
|
import json5
|
3
3
|
import re
|
4
4
|
from retrying import retry
|
5
|
-
from openai import OpenAI
|
5
|
+
from openai import OpenAI, AsyncOpenAI
|
6
6
|
import openai
|
7
7
|
|
8
8
|
|
@@ -56,6 +56,51 @@ def chat_stream(messages, temperature=0.2, stop=None, **kwargs):
|
|
56
56
|
yield chunk.choices[0].delta.content or ""
|
57
57
|
|
58
58
|
|
59
|
+
@retry(
|
60
|
+
retry_on_exception=never_retry_on_rate_limit_error,
|
61
|
+
wait_exponential_multiplier=500,
|
62
|
+
stop_max_attempt_number=5,
|
63
|
+
)
|
64
|
+
async def chat_async(messages, temperature=0.2, stop=None, **kwargs):
|
65
|
+
cfg = utils.read_json_file("llm.json")
|
66
|
+
|
67
|
+
base_url = cfg["baseURL"]
|
68
|
+
api_key = cfg["apiKey"]
|
69
|
+
model = cfg["model"]
|
70
|
+
|
71
|
+
base_url = base_url.replace("/chat/completions", "")
|
72
|
+
|
73
|
+
client = AsyncOpenAI(api_key=api_key, base_url=base_url)
|
74
|
+
|
75
|
+
response = await client.chat.completions.create(
|
76
|
+
model=model, messages=messages, temperature=temperature, stop=stop
|
77
|
+
)
|
78
|
+
return response.choices[0].message.content
|
79
|
+
|
80
|
+
|
81
|
+
@retry(
|
82
|
+
retry_on_exception=never_retry_on_rate_limit_error,
|
83
|
+
wait_exponential_multiplier=500,
|
84
|
+
stop_max_attempt_number=5,
|
85
|
+
)
|
86
|
+
async def chat_stream_async(messages, temperature=0.2, stop=None, **kwargs):
|
87
|
+
cfg = utils.read_json_file("llm.json")
|
88
|
+
|
89
|
+
base_url = cfg["baseURL"]
|
90
|
+
api_key = cfg["apiKey"]
|
91
|
+
model = cfg["model"]
|
92
|
+
|
93
|
+
base_url = base_url.replace("/chat/completions", "")
|
94
|
+
|
95
|
+
client = AsyncOpenAI(api_key=api_key, base_url=base_url)
|
96
|
+
|
97
|
+
stream = await client.chat.completions.create(
|
98
|
+
model=model, messages=messages, stream=True, temperature=temperature, stop=stop
|
99
|
+
)
|
100
|
+
async for chunk in stream:
|
101
|
+
yield chunk.choices[0].delta.content or ""
|
102
|
+
|
103
|
+
|
59
104
|
@retry(
|
60
105
|
retry_on_exception=never_retry_on_rate_limit_error,
|
61
106
|
wait_exponential_multiplier=500,
|
@@ -2,7 +2,7 @@ pycoze/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
pycoze/ai/__init__.py,sha256=amfVImcuiRRnGbmOjIqjXKiuH1H3zZPHOrJue2dEB8U,355
|
3
3
|
pycoze/ai/vram_reserve.py,sha256=DRxKzqf89fLAts0DzU8e19z9kecIF8OdMkQnJlCKZV0,4244
|
4
4
|
pycoze/ai/llm/__init__.py,sha256=5_AnOrzXI2V6ZZsLUWW1v5ATRWmJy53JLN9jfSZQXCg,249
|
5
|
-
pycoze/ai/llm/chat.py,sha256=
|
5
|
+
pycoze/ai/llm/chat.py,sha256=s3DvixWuInAXvHXDAlCL9lg2C_o2dj-BvoO8f-qXHp8,5951
|
6
6
|
pycoze/ai/llm/text_to_image_prompt.py,sha256=0bx2C_YRvjAo7iphHGp1-pmGKsKqwur7dM0t3SiA8kA,3398
|
7
7
|
pycoze/ai/llm/think.py,sha256=sUgTBdGzcZtL3r-Wx8M3lDuVUmDVz8g3qC0VU8uiKAI,5143
|
8
8
|
pycoze/api/__init__.py,sha256=GGRRRPop0ZxdXe5JRhg2XvHITGIWfNcHA25opJZ0f1w,313
|
@@ -35,8 +35,8 @@ pycoze/utils/arg.py,sha256=jop1tBfe5hYkHW1NSpCeaZBEznkgguBscj_7M2dWfrs,503
|
|
35
35
|
pycoze/utils/env.py,sha256=5pWlXfM1F5ZU9hhv1rHlDEanjEW5wf0nbyez9bNRqqA,559
|
36
36
|
pycoze/utils/socket.py,sha256=bZbFFRH4mfThzRqt55BAAGQ6eICx_ja4x8UGGrUdAm8,2428
|
37
37
|
pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
|
38
|
-
pycoze-0.1.
|
39
|
-
pycoze-0.1.
|
40
|
-
pycoze-0.1.
|
41
|
-
pycoze-0.1.
|
42
|
-
pycoze-0.1.
|
38
|
+
pycoze-0.1.294.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
|
39
|
+
pycoze-0.1.294.dist-info/METADATA,sha256=f9DZP6A0W-6w46Me-UupfpaHE3ffQUh_Ge3TSB2G80o,755
|
40
|
+
pycoze-0.1.294.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
|
41
|
+
pycoze-0.1.294.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
|
42
|
+
pycoze-0.1.294.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|