hjxdl 0.0.15__py3-none-any.whl → 0.0.17__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.
- hdl/_version.py +2 -2
- hdl/utils/llm/chat.py +141 -24
- {hjxdl-0.0.15.dist-info → hjxdl-0.0.17.dist-info}/METADATA +1 -1
- {hjxdl-0.0.15.dist-info → hjxdl-0.0.17.dist-info}/RECORD +6 -6
- {hjxdl-0.0.15.dist-info → hjxdl-0.0.17.dist-info}/WHEEL +0 -0
- {hjxdl-0.0.15.dist-info → hjxdl-0.0.17.dist-info}/top_level.txt +0 -0
hdl/_version.py
CHANGED
hdl/utils/llm/chat.py
CHANGED
@@ -7,7 +7,7 @@ from jupyfuncs.llm.openapi import (
|
|
7
7
|
)
|
8
8
|
|
9
9
|
|
10
|
-
class GGUF_M():
|
10
|
+
class GGUF_M(Llama):
|
11
11
|
def __init__(
|
12
12
|
self,
|
13
13
|
model_path :str,
|
@@ -15,38 +15,43 @@ class GGUF_M():
|
|
15
15
|
generation_kwargs: dict = {},
|
16
16
|
server_ip: str = "127.0.0.1",
|
17
17
|
server_port: int = 8000,
|
18
|
+
*args,
|
19
|
+
**kwargs
|
18
20
|
):
|
19
|
-
"""Initialize the model with the
|
21
|
+
"""Initialize the model with the specified parameters.
|
20
22
|
|
21
23
|
Args:
|
22
24
|
model_path (str): The path to the model.
|
23
|
-
device (str, optional): The device to use
|
24
|
-
generation_kwargs (dict, optional): Additional keyword arguments
|
25
|
+
device (str, optional): The device to use, either 'gpu' or 'cpu'. Defaults to 'gpu'.
|
26
|
+
generation_kwargs (dict, optional): Additional generation keyword arguments. Defaults to {}.
|
25
27
|
server_ip (str, optional): The IP address of the server. Defaults to "127.0.0.1".
|
26
28
|
server_port (int, optional): The port of the server. Defaults to 8000.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
*args: Variable length argument list.
|
30
|
+
**kwargs: Arbitrary keyword arguments.
|
31
|
+
|
32
|
+
Raises:
|
33
|
+
KeyError: If 'num_threads' or 'max_context_length' is missing in generation_kwargs.
|
34
|
+
"""
|
33
35
|
print("正在从本地加载模型...")
|
34
|
-
if device == 'cpu':
|
35
|
-
|
36
|
+
if device.lower() == 'cpu':
|
37
|
+
super().__init__(
|
36
38
|
model_path=model_path,
|
37
|
-
n_threads=
|
38
|
-
n_ctx=
|
39
|
+
n_threads=generation_kwargs['num_threads'],
|
40
|
+
n_ctx=generation_kwargs['max_context_length'],
|
41
|
+
*args,
|
42
|
+
**kwargs
|
39
43
|
)
|
40
44
|
else:
|
41
|
-
|
45
|
+
super().__init__(
|
42
46
|
model_path=model_path,
|
43
|
-
n_threads=
|
44
|
-
n_ctx=
|
47
|
+
n_threads=generation_kwargs['num_threads'],
|
48
|
+
n_ctx=generation_kwargs['max_context_length'],
|
45
49
|
n_gpu_layers=-1,
|
46
|
-
flash_attn=True
|
50
|
+
flash_attn=True,
|
51
|
+
*args,
|
52
|
+
**kwargs
|
47
53
|
)
|
48
|
-
|
49
|
-
print("完成本地模型的加载")
|
54
|
+
self.generation_kwargs = generation_kwargs
|
50
55
|
|
51
56
|
def invoke(
|
52
57
|
self,
|
@@ -67,7 +72,7 @@ class GGUF_M():
|
|
67
72
|
"""
|
68
73
|
prompt_final = f"USER:\n{prompt}\nASSISTANT:\n"
|
69
74
|
|
70
|
-
result = self.
|
75
|
+
result = self.create_completion(
|
71
76
|
prompt_final,
|
72
77
|
repeat_penalty=self.generation_kwargs["repetition_penalty"],
|
73
78
|
max_tokens=self.generation_kwargs["max_new_tokens"],
|
@@ -83,7 +88,7 @@ class GGUF_M():
|
|
83
88
|
# [prompt, resp]
|
84
89
|
# )
|
85
90
|
return resp
|
86
|
-
|
91
|
+
|
87
92
|
def stream(
|
88
93
|
self,
|
89
94
|
prompt: str,
|
@@ -101,9 +106,8 @@ class GGUF_M():
|
|
101
106
|
Yields:
|
102
107
|
str: Text responses generated by the model based on the prompt.
|
103
108
|
"""
|
104
|
-
self.questions.append(prompt)
|
105
109
|
prompt = f"USER:\n{prompt}\nASSISTANT:\n"
|
106
|
-
output = self.
|
110
|
+
output = self.create_completion(
|
107
111
|
prompt,
|
108
112
|
stream=True,
|
109
113
|
repeat_penalty=self.generation_kwargs["repetition_penalty"],
|
@@ -123,6 +127,119 @@ class GGUF_M():
|
|
123
127
|
# self.resps[-1] = "".join(self.resps[-1])
|
124
128
|
|
125
129
|
|
130
|
+
# class GGUF_M():
|
131
|
+
# def __init__(
|
132
|
+
# self,
|
133
|
+
# model_path :str,
|
134
|
+
# device: str='gpu',
|
135
|
+
# generation_kwargs: dict = {},
|
136
|
+
# server_ip: str = "127.0.0.1",
|
137
|
+
# server_port: int = 8000,
|
138
|
+
# ):
|
139
|
+
# """Initialize the model with the provided model path and optional parameters.
|
140
|
+
|
141
|
+
# Args:
|
142
|
+
# model_path (str): The path to the model.
|
143
|
+
# device (str, optional): The device to use for model initialization. Defaults to 'gpu'.
|
144
|
+
# generation_kwargs (dict, optional): Additional keyword arguments for model generation. Defaults to {}.
|
145
|
+
# server_ip (str, optional): The IP address of the server. Defaults to "127.0.0.1".
|
146
|
+
# server_port (int, optional): The port of the server. Defaults to 8000.
|
147
|
+
# """
|
148
|
+
# # 从本地初始化模型
|
149
|
+
# # super().__init__()
|
150
|
+
# self.generation_kwargs = generation_kwargs
|
151
|
+
# print("正在从本地加载模型...")
|
152
|
+
# if device == 'cpu':
|
153
|
+
# self.model = Llama(
|
154
|
+
# model_path=model_path,
|
155
|
+
# n_threads=self.generation_kwargs['num_threads'],
|
156
|
+
# n_ctx=self.generation_kwargs['max_context_length'],
|
157
|
+
# )
|
158
|
+
# else:
|
159
|
+
# self.model = Llama(
|
160
|
+
# model_path=model_path,
|
161
|
+
# n_threads=self.generation_kwargs['num_threads'],
|
162
|
+
# n_ctx=self.generation_kwargs['max_context_length'],
|
163
|
+
# n_gpu_layers=-1,
|
164
|
+
# flash_attn=True
|
165
|
+
# )
|
166
|
+
|
167
|
+
# print("完成本地模型的加载")
|
168
|
+
|
169
|
+
# def invoke(
|
170
|
+
# self,
|
171
|
+
# prompt : str,
|
172
|
+
# stop: list[str] | None = ["USER:", "ASSISTANT:"],
|
173
|
+
# # history: list = [],
|
174
|
+
# **kwargs: t.Any,
|
175
|
+
# ) -> str:
|
176
|
+
# """Invoke the model to generate a response based on the given prompt.
|
177
|
+
|
178
|
+
# Args:
|
179
|
+
# prompt (str): The prompt to be used for generating the response.
|
180
|
+
# stop (list[str], optional): List of strings that indicate when the model should stop generating the response. Defaults to ["USER:", "ASSISTANT:"].
|
181
|
+
# **kwargs: Additional keyword arguments to be passed to the model.
|
182
|
+
|
183
|
+
# Returns:
|
184
|
+
# str: The generated response based on the prompt.
|
185
|
+
# """
|
186
|
+
# prompt_final = f"USER:\n{prompt}\nASSISTANT:\n"
|
187
|
+
|
188
|
+
# result = self.model.create_completion(
|
189
|
+
# prompt_final,
|
190
|
+
# repeat_penalty=self.generation_kwargs["repetition_penalty"],
|
191
|
+
# max_tokens=self.generation_kwargs["max_new_tokens"],
|
192
|
+
# stop=stop,
|
193
|
+
# echo=False,
|
194
|
+
# temperature=self.generation_kwargs["temperature"],
|
195
|
+
# mirostat_mode = 2,
|
196
|
+
# mirostat_tau=4.0,
|
197
|
+
# mirostat_eta=1.1
|
198
|
+
# )
|
199
|
+
# resp = result['choices'][0]['text']
|
200
|
+
# # history.append(
|
201
|
+
# # [prompt, resp]
|
202
|
+
# # )
|
203
|
+
# return resp
|
204
|
+
|
205
|
+
# def stream(
|
206
|
+
# self,
|
207
|
+
# prompt: str,
|
208
|
+
# stop: list[str] | None = ["USER:", "ASSISTANT:"],
|
209
|
+
# # history: list = [],
|
210
|
+
# **kwargs: t.Any,
|
211
|
+
# ):
|
212
|
+
# """Generate text responses based on the given prompt using the model.
|
213
|
+
|
214
|
+
# Args:
|
215
|
+
# prompt (str): The prompt to generate text responses.
|
216
|
+
# stop (list[str], optional): List of strings to stop the generation. Defaults to ["USER:", "ASSISTANT:"].
|
217
|
+
# **kwargs: Additional keyword arguments for the model.
|
218
|
+
|
219
|
+
# Yields:
|
220
|
+
# str: Text responses generated by the model based on the prompt.
|
221
|
+
# """
|
222
|
+
# prompt = f"USER:\n{prompt}\nASSISTANT:\n"
|
223
|
+
# output = self.model.create_completion(
|
224
|
+
# prompt,
|
225
|
+
# stream=True,
|
226
|
+
# repeat_penalty=self.generation_kwargs["repetition_penalty"],
|
227
|
+
# max_tokens=self.generation_kwargs["max_new_tokens"],
|
228
|
+
# stop=stop,
|
229
|
+
# echo=False,
|
230
|
+
# temperature=self.generation_kwargs["temperature"],
|
231
|
+
# mirostat_mode = 2,
|
232
|
+
# mirostat_tau=4.0,
|
233
|
+
# mirostat_eta=1.1
|
234
|
+
# )
|
235
|
+
# # history.append([])
|
236
|
+
# for chunk in output:
|
237
|
+
# item = chunk['choices'][0]['text']
|
238
|
+
# # self.resps[-1].append(item)
|
239
|
+
# yield chunk['choices'][0]['text']
|
240
|
+
# # self.resps[-1] = "".join(self.resps[-1])
|
241
|
+
|
242
|
+
|
126
243
|
class OpenAI_M():
|
127
244
|
def __init__(
|
128
245
|
self,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
hdl/__init__.py,sha256=5sZZNySv08wwfzJcSDssGTqUn9wlmDsR6R4XB8J8mFM,70
|
2
|
-
hdl/_version.py,sha256=
|
2
|
+
hdl/_version.py,sha256=OXG6jb6QQz55miFHOqfJx8zqIQYlPcgtvsnb6XEE5Fs,413
|
3
3
|
hdl/args/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
hdl/args/loss_args.py,sha256=s7YzSdd7IjD24rZvvOrxLLFqMZQb9YylxKeyelSdrTk,70
|
5
5
|
hdl/controllers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -84,11 +84,11 @@ hdl/utils/database_tools/connect.py,sha256=KUnVG-8raifEJ_N0b3c8LkTTIfn9NIyw8LX6q
|
|
84
84
|
hdl/utils/general/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
85
85
|
hdl/utils/general/glob.py,sha256=8-RCnt6L297wMIfn34ZAMCsGCZUjHG3MGglGZI1cX0g,491
|
86
86
|
hdl/utils/llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
87
|
-
hdl/utils/llm/chat.py,sha256=
|
87
|
+
hdl/utils/llm/chat.py,sha256=H2c8assJlSdZQKIfPkYrVZHqv66TsdsxtaLXv0kNe1w,11565
|
88
88
|
hdl/utils/llm/embs.py,sha256=yCFtc25gUFas6kwgOGBFydeaHNyQMq5y1Chxl8TNEUQ,2190
|
89
89
|
hdl/utils/schedulers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
90
90
|
hdl/utils/schedulers/norm_lr.py,sha256=bDwCmdEK-WkgxQMFBiMuchv8Mm7C0-GZJ6usm-PQk14,4461
|
91
|
-
hjxdl-0.0.
|
92
|
-
hjxdl-0.0.
|
93
|
-
hjxdl-0.0.
|
94
|
-
hjxdl-0.0.
|
91
|
+
hjxdl-0.0.17.dist-info/METADATA,sha256=MBuoruFG8xTqFc-epdvuhZWoQwbpo28-fTfi7QJPijc,543
|
92
|
+
hjxdl-0.0.17.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
93
|
+
hjxdl-0.0.17.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
|
94
|
+
hjxdl-0.0.17.dist-info/RECORD,,
|
File without changes
|
File without changes
|