hjxdl 0.3.28__py3-none-any.whl → 0.3.30__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/decorators/llm.py +29 -0
- hdl/utils/llm/llm_wrapper.py +35 -0
- {hjxdl-0.3.28.dist-info → hjxdl-0.3.30.dist-info}/METADATA +1 -1
- {hjxdl-0.3.28.dist-info → hjxdl-0.3.30.dist-info}/RECORD +8 -8
- {hjxdl-0.3.28.dist-info → hjxdl-0.3.30.dist-info}/LICENSE +0 -0
- {hjxdl-0.3.28.dist-info → hjxdl-0.3.30.dist-info}/WHEEL +0 -0
- {hjxdl-0.3.28.dist-info → hjxdl-0.3.30.dist-info}/top_level.txt +0 -0
hdl/_version.py
CHANGED
hdl/utils/decorators/llm.py
CHANGED
@@ -2,6 +2,23 @@ import time
|
|
2
2
|
from functools import wraps
|
3
3
|
|
4
4
|
def measure_stream_performance(func):
|
5
|
+
"""
|
6
|
+
Measures the performance of a streaming function by tracking the time taken to output characters and the rate of character and token generation.
|
7
|
+
|
8
|
+
Args:
|
9
|
+
func (callable): The streaming function to be measured. It should return a generator that yields dictionaries containing 'type' and 'content' keys.
|
10
|
+
|
11
|
+
Returns:
|
12
|
+
callable: A wrapper function that performs the performance measurement and prints statistics related to the streaming output.
|
13
|
+
|
14
|
+
Statistics Printed:
|
15
|
+
- Time to first character (in seconds)
|
16
|
+
- Total time taken for the execution (in seconds)
|
17
|
+
- Total number of characters output
|
18
|
+
- Total number of tokens processed
|
19
|
+
- Characters output per second
|
20
|
+
- Tokens processed per second
|
21
|
+
"""
|
5
22
|
@wraps(func)
|
6
23
|
def wrapper(*args, **kwargs):
|
7
24
|
# 开始计时
|
@@ -54,6 +71,18 @@ def run_llm_stream(
|
|
54
71
|
prompt,
|
55
72
|
**kwargs
|
56
73
|
):
|
74
|
+
"""
|
75
|
+
Run a language model stream with the given parameters.
|
76
|
+
|
77
|
+
Args:
|
78
|
+
llm (object): The language model object used to generate responses.
|
79
|
+
client_id (str): The unique identifier for the client making the request.
|
80
|
+
prompt (str): The input prompt to which the language model should respond.
|
81
|
+
**kwargs: Additional keyword arguments to customize the request.
|
82
|
+
|
83
|
+
Returns:
|
84
|
+
iterable: An iterable response stream from the language model.
|
85
|
+
"""
|
57
86
|
resp = llm.stream(
|
58
87
|
client_id=client_id,
|
59
88
|
prompt=prompt,
|
hdl/utils/llm/llm_wrapper.py
CHANGED
@@ -56,6 +56,8 @@ class OpenAIWrapper(object):
|
|
56
56
|
*args,
|
57
57
|
**kwargs
|
58
58
|
)
|
59
|
+
if "client_type" not in conf:
|
60
|
+
conf["client_type"] = "chat"
|
59
61
|
|
60
62
|
def add_client(
|
61
63
|
self,
|
@@ -96,6 +98,7 @@ class OpenAIWrapper(object):
|
|
96
98
|
host = f"http://{host}:{port}/v1"
|
97
99
|
self.client_conf[client_id]['host'] = host
|
98
100
|
self.client_conf[client_id]['model'] = model
|
101
|
+
self.client_conf[client_id]['client_type'] = client_type
|
99
102
|
self.client_conf[client_id]['client'] = OpenAI(
|
100
103
|
base_url=host,
|
101
104
|
api_key=api_key,
|
@@ -347,3 +350,35 @@ class OpenAIWrapper(object):
|
|
347
350
|
return
|
348
351
|
|
349
352
|
return
|
353
|
+
|
354
|
+
def embedding(
|
355
|
+
self,
|
356
|
+
client_id: str,
|
357
|
+
texts: list[str],
|
358
|
+
model: str = None,
|
359
|
+
**kwargs
|
360
|
+
):
|
361
|
+
"""
|
362
|
+
Generates embeddings for a list of texts using a specified model.
|
363
|
+
|
364
|
+
Args:
|
365
|
+
client_id (str): The ID of the client to use for generating embeddings.
|
366
|
+
texts (list[str]): A list of texts for which to generate embeddings.
|
367
|
+
model (str, optional): The model to use for generating embeddings.
|
368
|
+
If not provided, the model specified in the client configuration will be used.
|
369
|
+
**kwargs: Additional keyword arguments to be passed to the client embedding creation method.
|
370
|
+
|
371
|
+
Returns:
|
372
|
+
list: A list of embeddings corresponding to the input texts.
|
373
|
+
"""
|
374
|
+
if not model:
|
375
|
+
model = self.client_conf[client_id]['model']
|
376
|
+
|
377
|
+
client = self.client_conf[client_id]['client']
|
378
|
+
response = client.embeddings.create(
|
379
|
+
input=texts,
|
380
|
+
model=model,
|
381
|
+
**kwargs
|
382
|
+
)
|
383
|
+
|
384
|
+
return [i.embedding for i in response.data]
|
@@ -1,5 +1,5 @@
|
|
1
1
|
hdl/__init__.py,sha256=GffnD0jLJdhkd-vo989v40N90sQbofkayRBwxc6TVhQ,72
|
2
|
-
hdl/_version.py,sha256=
|
2
|
+
hdl/_version.py,sha256=rwxxREOGVMpe267h030C9wYX9mgJaCw7aCCw2Mw13-w,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
|
@@ -122,7 +122,7 @@ hdl/utils/database_tools/connect.py,sha256=xCacGucKxlQUXs6AsNddpeECvdqT1180V1ZWq
|
|
122
122
|
hdl/utils/database_tools/datetime.py,sha256=xqE2xNiOpADzX-R8_bM0bioJRF3Ay9Jp1CAG6dy6uVI,1202
|
123
123
|
hdl/utils/database_tools/web.py,sha256=awJ8lafL-2KRjf3V1uuij8JIvX9U5fI8fLZKOkOvqtk,5771
|
124
124
|
hdl/utils/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
125
|
-
hdl/utils/decorators/llm.py,sha256=
|
125
|
+
hdl/utils/decorators/llm.py,sha256=zjAKaGTE4UuMdNbmCMKDrEgWDQ8o6oPYYQgHVeAF78M,3110
|
126
126
|
hdl/utils/desc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
127
127
|
hdl/utils/desc/func_desc.py,sha256=sHmVZZmV7Zgii--gnHqMs6fTb7HVkqTOf8Pl_0F6qlI,3808
|
128
128
|
hdl/utils/desc/template.py,sha256=Kf_tbL-XkDCKNQ3UncbCuYEeUgXEa7kRVCf9TD2b8og,2526
|
@@ -136,15 +136,15 @@ hdl/utils/llm/chatgr.py,sha256=5F5PJHe8vz3iCfi4TT54DCLRi1UeJshECdVtgvvvao0,3696
|
|
136
136
|
hdl/utils/llm/embs.py,sha256=Tf0FOYrOFZp7qQpEPiSCXzlgyHH0X9HVTUtsup74a9E,7174
|
137
137
|
hdl/utils/llm/extract.py,sha256=2sK_WJzmYIc8iuWaM9DA6Nw3_6q1O4lJ5pKpcZo-bBA,6512
|
138
138
|
hdl/utils/llm/llama_chat.py,sha256=watcHGOaz-bv3x-yDucYlGk5f8FiqfFhwWogrl334fk,4387
|
139
|
-
hdl/utils/llm/llm_wrapper.py,sha256=
|
139
|
+
hdl/utils/llm/llm_wrapper.py,sha256=l5D2gWuxm_tpIoCeCfprXNh3hykFP3jMDaM6XCDKdew,14966
|
140
140
|
hdl/utils/llm/vis.py,sha256=SSP6tOwKLq0hWcpM3twI9TitqzBmKjlcGrnXEWYlCzM,26055
|
141
141
|
hdl/utils/llm/visrag.py,sha256=0i-VrxqgiV-J7R3VPshu9oc7-rKjFJOldYik3HDXj6M,10176
|
142
142
|
hdl/utils/schedulers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
143
143
|
hdl/utils/schedulers/norm_lr.py,sha256=bDwCmdEK-WkgxQMFBiMuchv8Mm7C0-GZJ6usm-PQk14,4461
|
144
144
|
hdl/utils/weather/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
145
145
|
hdl/utils/weather/weather.py,sha256=k11o6wM15kF8b9NMlEfrg68ak-SfSYLN3nOOflFUv-I,4381
|
146
|
-
hjxdl-0.3.
|
147
|
-
hjxdl-0.3.
|
148
|
-
hjxdl-0.3.
|
149
|
-
hjxdl-0.3.
|
150
|
-
hjxdl-0.3.
|
146
|
+
hjxdl-0.3.30.dist-info/LICENSE,sha256=lkMiSbeZHBQLB9LJEkS9-L3Z-LBC4yGnKrzHSG8RkPM,2599
|
147
|
+
hjxdl-0.3.30.dist-info/METADATA,sha256=tcWR37ej1V4kjTKf_ND9R9Yd7dpuRbbFjL3yZhwSzOQ,1336
|
148
|
+
hjxdl-0.3.30.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
149
|
+
hjxdl-0.3.30.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
|
150
|
+
hjxdl-0.3.30.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|