hjxdl 0.0.14__py3-none-any.whl → 0.0.16__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 CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.0.14'
16
- __version_tuple__ = version_tuple = (0, 0, 14)
15
+ __version__ = version = '0.0.16'
16
+ __version_tuple__ = version_tuple = (0, 0, 16)
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,29 @@ 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 provided model path and optional parameters.
20
-
21
- Args:
22
- model_path (str): The path to the model.
23
- device (str, optional): The device to use for model initialization. Defaults to 'gpu'.
24
- generation_kwargs (dict, optional): Additional keyword arguments for model generation. Defaults to {}.
25
- server_ip (str, optional): The IP address of the server. Defaults to "127.0.0.1".
26
- server_port (int, optional): The port of the server. Defaults to 8000.
27
- """
28
- # 从本地初始化模型
29
- super().__init__()
30
- self.generation_kwargs = generation_kwargs
31
- self.questions = []
32
- self.resps = []
33
21
  print("正在从本地加载模型...")
34
- if device == 'cpu':
35
- self.model = Llama(
22
+ if device.lower() == 'cpu':
23
+ super().__init__(
36
24
  model_path=model_path,
37
- n_threads=self.generation_kwargs['num_threads'],
38
- n_ctx=self.generation_kwargs['max_context_length'],
25
+ n_threads=generation_kwargs['num_threads'],
26
+ n_ctx=generation_kwargs['max_context_length'],
27
+ *args,
28
+ **kwargs
39
29
  )
40
30
  else:
41
- self.model = Llama(
31
+ super().__init__(
42
32
  model_path=model_path,
43
- n_threads=self.generation_kwargs['num_threads'],
44
- n_ctx=self.generation_kwargs['max_context_length'],
33
+ n_threads=generation_kwargs['num_threads'],
34
+ n_ctx=generation_kwargs['max_context_length'],
45
35
  n_gpu_layers=-1,
46
- flash_attn=True
36
+ flash_attn=True,
37
+ *args,
38
+ **kwargs
47
39
  )
48
-
49
- print("完成本地模型的加载")
40
+ self.generation_kwargs = generation_kwargs
50
41
 
51
42
  def invoke(
52
43
  self,
@@ -67,7 +58,7 @@ class GGUF_M():
67
58
  """
68
59
  prompt_final = f"USER:\n{prompt}\nASSISTANT:\n"
69
60
 
70
- result = self.model.create_completion(
61
+ result = self.create_completion(
71
62
  prompt_final,
72
63
  repeat_penalty=self.generation_kwargs["repetition_penalty"],
73
64
  max_tokens=self.generation_kwargs["max_new_tokens"],
@@ -83,7 +74,7 @@ class GGUF_M():
83
74
  # [prompt, resp]
84
75
  # )
85
76
  return resp
86
-
77
+
87
78
  def stream(
88
79
  self,
89
80
  prompt: str,
@@ -101,9 +92,8 @@ class GGUF_M():
101
92
  Yields:
102
93
  str: Text responses generated by the model based on the prompt.
103
94
  """
104
- self.questions.append(prompt)
105
95
  prompt = f"USER:\n{prompt}\nASSISTANT:\n"
106
- output = self.model.create_completion(
96
+ output = self.create_completion(
107
97
  prompt,
108
98
  stream=True,
109
99
  repeat_penalty=self.generation_kwargs["repetition_penalty"],
@@ -123,6 +113,119 @@ class GGUF_M():
123
113
  # self.resps[-1] = "".join(self.resps[-1])
124
114
 
125
115
 
116
+ # class GGUF_M():
117
+ # def __init__(
118
+ # self,
119
+ # model_path :str,
120
+ # device: str='gpu',
121
+ # generation_kwargs: dict = {},
122
+ # server_ip: str = "127.0.0.1",
123
+ # server_port: int = 8000,
124
+ # ):
125
+ # """Initialize the model with the provided model path and optional parameters.
126
+
127
+ # Args:
128
+ # model_path (str): The path to the model.
129
+ # device (str, optional): The device to use for model initialization. Defaults to 'gpu'.
130
+ # generation_kwargs (dict, optional): Additional keyword arguments for model generation. Defaults to {}.
131
+ # server_ip (str, optional): The IP address of the server. Defaults to "127.0.0.1".
132
+ # server_port (int, optional): The port of the server. Defaults to 8000.
133
+ # """
134
+ # # 从本地初始化模型
135
+ # # super().__init__()
136
+ # self.generation_kwargs = generation_kwargs
137
+ # print("正在从本地加载模型...")
138
+ # if device == 'cpu':
139
+ # self.model = Llama(
140
+ # model_path=model_path,
141
+ # n_threads=self.generation_kwargs['num_threads'],
142
+ # n_ctx=self.generation_kwargs['max_context_length'],
143
+ # )
144
+ # else:
145
+ # self.model = Llama(
146
+ # model_path=model_path,
147
+ # n_threads=self.generation_kwargs['num_threads'],
148
+ # n_ctx=self.generation_kwargs['max_context_length'],
149
+ # n_gpu_layers=-1,
150
+ # flash_attn=True
151
+ # )
152
+
153
+ # print("完成本地模型的加载")
154
+
155
+ # def invoke(
156
+ # self,
157
+ # prompt : str,
158
+ # stop: list[str] | None = ["USER:", "ASSISTANT:"],
159
+ # # history: list = [],
160
+ # **kwargs: t.Any,
161
+ # ) -> str:
162
+ # """Invoke the model to generate a response based on the given prompt.
163
+
164
+ # Args:
165
+ # prompt (str): The prompt to be used for generating the response.
166
+ # stop (list[str], optional): List of strings that indicate when the model should stop generating the response. Defaults to ["USER:", "ASSISTANT:"].
167
+ # **kwargs: Additional keyword arguments to be passed to the model.
168
+
169
+ # Returns:
170
+ # str: The generated response based on the prompt.
171
+ # """
172
+ # prompt_final = f"USER:\n{prompt}\nASSISTANT:\n"
173
+
174
+ # result = self.model.create_completion(
175
+ # prompt_final,
176
+ # repeat_penalty=self.generation_kwargs["repetition_penalty"],
177
+ # max_tokens=self.generation_kwargs["max_new_tokens"],
178
+ # stop=stop,
179
+ # echo=False,
180
+ # temperature=self.generation_kwargs["temperature"],
181
+ # mirostat_mode = 2,
182
+ # mirostat_tau=4.0,
183
+ # mirostat_eta=1.1
184
+ # )
185
+ # resp = result['choices'][0]['text']
186
+ # # history.append(
187
+ # # [prompt, resp]
188
+ # # )
189
+ # return resp
190
+
191
+ # def stream(
192
+ # self,
193
+ # prompt: str,
194
+ # stop: list[str] | None = ["USER:", "ASSISTANT:"],
195
+ # # history: list = [],
196
+ # **kwargs: t.Any,
197
+ # ):
198
+ # """Generate text responses based on the given prompt using the model.
199
+
200
+ # Args:
201
+ # prompt (str): The prompt to generate text responses.
202
+ # stop (list[str], optional): List of strings to stop the generation. Defaults to ["USER:", "ASSISTANT:"].
203
+ # **kwargs: Additional keyword arguments for the model.
204
+
205
+ # Yields:
206
+ # str: Text responses generated by the model based on the prompt.
207
+ # """
208
+ # prompt = f"USER:\n{prompt}\nASSISTANT:\n"
209
+ # output = self.model.create_completion(
210
+ # prompt,
211
+ # stream=True,
212
+ # repeat_penalty=self.generation_kwargs["repetition_penalty"],
213
+ # max_tokens=self.generation_kwargs["max_new_tokens"],
214
+ # stop=stop,
215
+ # echo=False,
216
+ # temperature=self.generation_kwargs["temperature"],
217
+ # mirostat_mode = 2,
218
+ # mirostat_tau=4.0,
219
+ # mirostat_eta=1.1
220
+ # )
221
+ # # history.append([])
222
+ # for chunk in output:
223
+ # item = chunk['choices'][0]['text']
224
+ # # self.resps[-1].append(item)
225
+ # yield chunk['choices'][0]['text']
226
+ # # self.resps[-1] = "".join(self.resps[-1])
227
+
228
+
126
229
  class OpenAI_M():
127
230
  def __init__(
128
231
  self,
hdl/utils/llm/embs.py CHANGED
@@ -1,4 +1,4 @@
1
- class FlagEmbedder():
1
+ class HFEmbedder():
2
2
  def __init__(
3
3
  self,
4
4
  emb_name: str = "bge",
@@ -41,6 +41,8 @@ class FlagEmbedder():
41
41
  Returns:
42
42
  numpy.ndarray: Encoded representation of the input sentences.
43
43
  """
44
+ if isinstance(sentences, str):
45
+ sentences = [sentences]
44
46
  output = self.model.encode(
45
47
  sentences,
46
48
  return_dense=True,
@@ -68,4 +70,4 @@ class FlagEmbedder():
68
70
  output_1 = self.encode(sentences_1)
69
71
  output_2 = self.encode(sentences_2)
70
72
  similarity = output_1 @ output_2.T
71
- return similarity.item()
73
+ return similarity
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hjxdl
3
- Version: 0.0.14
3
+ Version: 0.0.16
4
4
  Summary: A collection of functions for Jupyter notebooks
5
5
  Home-page: https://github.com/huluxiaohuowa/hdl
6
6
  Author: Jianxing Hu
@@ -1,5 +1,5 @@
1
1
  hdl/__init__.py,sha256=5sZZNySv08wwfzJcSDssGTqUn9wlmDsR6R4XB8J8mFM,70
2
- hdl/_version.py,sha256=Z5KVh4ecKbPlzksuEdQrX-Mm8ihZCLuudKr2xk8fqgc,413
2
+ hdl/_version.py,sha256=C1uSJtiL3eBiXPR4mc0kyqGBqfZj8NitaI9frAY9h7I,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=NEbWdrPpQqS5ArU7ghA6xuam8wwvWXk3LL_CiNEEuIg,7055
88
- hdl/utils/llm/embs.py,sha256=rkMDaQIVX7cmTEtOhTBzqZYwouOzO3ox0DpJ493BXrs,2124
87
+ hdl/utils/llm/chat.py,sha256=q5644lQ-oGoCZVMMVJp4qPUe4oGf7XZ-nuLItC8CeSw,10813
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.14.dist-info/METADATA,sha256=0mn1FFKnA5m5jqrIqlh-XioiqkonZ3DXD6I770Q62Xc,543
92
- hjxdl-0.0.14.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
93
- hjxdl-0.0.14.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
94
- hjxdl-0.0.14.dist-info/RECORD,,
91
+ hjxdl-0.0.16.dist-info/METADATA,sha256=_xC63dyfzZes4vmGeFZbRM0bDBxAmLWcc_BzcsFqB40,543
92
+ hjxdl-0.0.16.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
93
+ hjxdl-0.0.16.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
94
+ hjxdl-0.0.16.dist-info/RECORD,,
File without changes