hjxdl 0.3.21__py3-none-any.whl → 0.3.23__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.3.21'
16
- __version_tuple__ = version_tuple = (0, 3, 21)
15
+ __version__ = version = '0.3.23'
16
+ __version_tuple__ = version_tuple = (0, 3, 23)
@@ -2,7 +2,6 @@ import yaml
2
2
  import typing as t
3
3
 
4
4
  from openai import OpenAI
5
- import instructor
6
5
 
7
6
 
8
7
  class OpenAIWrapper(object):
@@ -33,6 +32,12 @@ class OpenAIWrapper(object):
33
32
  Note:
34
33
  The method will create a client for each configuration found in `client_conf`,
35
34
  initializing the client with the specified `base_url` and `api_key`.
35
+ Examples:
36
+ >>> llm = OpenAIWrapper(
37
+ >>> client_conf_dir="/some/path/model_conf.yaml",
38
+ >>> # load_conf=False
39
+ >>> )
40
+ )
36
41
  """
37
42
  self.client_conf = {}
38
43
  if client_conf is None:
@@ -78,6 +83,13 @@ class OpenAIWrapper(object):
78
83
 
79
84
  Raises:
80
85
  ValueError: If both host and port are not valid for constructing a URL.
86
+ Examples:
87
+ >>> llm.add_client(
88
+ >>> client_id="rone",
89
+ >>> host="127.0.0.1",
90
+ >>> port=22299,
91
+ >>> model="ictrek/rone:1.5b32k",
92
+ >>> )
81
93
  """
82
94
  self.client_conf[client_id] = {}
83
95
  if not host.startswith('http') and port:
@@ -158,6 +170,7 @@ class OpenAIWrapper(object):
158
170
 
159
171
  client = self.client_conf[client_id]['client']
160
172
  if response_model:
173
+ import instructor #TODO 有些模型支持这个 instructor 的结构化输出,但实际上它调用的还是openai api的功能,以后适时删除或补全
161
174
  client = instructor.from_openai(client)
162
175
 
163
176
  messages = []
@@ -190,7 +203,10 @@ class OpenAIWrapper(object):
190
203
  elif len(image_keys) == 1:
191
204
  image_keys = (image_keys[0],) * 3
192
205
 
193
- content = []
206
+ content = [{
207
+ "type": "text",
208
+ "text": prompt
209
+ }]
194
210
  if images:
195
211
  if isinstance(images, str):
196
212
  images = [images]
@@ -244,6 +260,15 @@ class OpenAIWrapper(object):
244
260
  - 'type' (str): Indicates the type of response ('text' or 'tool_calls').
245
261
  - 'contents' (str, optional): The text content if the response type is 'text'.
246
262
  - 'tool_params' (dict, optional): The parameters of the tool called if the response type is 'tool_calls'.
263
+
264
+ Examples:
265
+ >>> llm.invoke(
266
+ >>> client_id="glm_4_flash",
267
+ >>> prompt="深圳天气怎么样?",
268
+ >>> tools=[TOOL_DICT['get_weather']],
269
+ >>> )
270
+ {'type': 'tool_calls',
271
+ 'tool_parmas': Function(arguments='{"location": "Shenzhen"}', name='get_weather')}
247
272
  """
248
273
  answer_dict = {}
249
274
 
@@ -279,6 +304,16 @@ class OpenAIWrapper(object):
279
304
  - tool_params (dict, optional): Parameters of the tool call if the type is 'tool_calls'.
280
305
  - content (str, optional): The generated text content if the type is 'text'.
281
306
  - message (str, optional): An error message if the type is 'error'.
307
+
308
+ Examplse:
309
+ >>> resp = llm.stream(
310
+ >>> client_id="r1", #此模型可以进行cot
311
+ >>> prompt=prompt,
312
+ >>> # tools=[TOOL_DICT['get_weather']],
313
+ >>> )
314
+ >>> for i in resp:
315
+ >>> if i['type'] == 'text' and i['content']:
316
+ >>> print(i['content'], flush=True, end="")
282
317
  """
283
318
  resp = self.get_resp(prompt=prompt, stream=True, **kwargs)
284
319
 
@@ -312,7 +347,3 @@ class OpenAIWrapper(object):
312
347
  return
313
348
 
314
349
  return
315
-
316
-
317
-
318
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: hjxdl
3
- Version: 0.3.21
3
+ Version: 0.3.23
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=GffnD0jLJdhkd-vo989v40N90sQbofkayRBwxc6TVhQ,72
2
- hdl/_version.py,sha256=RePWyWgLItSCeI7HV40DbnyFzjteC1Gpxd4cuRPe79I,413
2
+ hdl/_version.py,sha256=Li8JkxhYfS5RJsRP9TE94VsfPVxFjJHFIPlVKBeP0UY,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
@@ -134,15 +134,15 @@ hdl/utils/llm/chatgr.py,sha256=5F5PJHe8vz3iCfi4TT54DCLRi1UeJshECdVtgvvvao0,3696
134
134
  hdl/utils/llm/embs.py,sha256=Tf0FOYrOFZp7qQpEPiSCXzlgyHH0X9HVTUtsup74a9E,7174
135
135
  hdl/utils/llm/extract.py,sha256=2sK_WJzmYIc8iuWaM9DA6Nw3_6q1O4lJ5pKpcZo-bBA,6512
136
136
  hdl/utils/llm/llama_chat.py,sha256=watcHGOaz-bv3x-yDucYlGk5f8FiqfFhwWogrl334fk,4387
137
- hdl/utils/llm/llm_wrapper.py,sha256=sg1uh06yd5gEnHVhSp6FgQI9cOGFVJt0e0_vYpzpRPE,12377
137
+ hdl/utils/llm/llm_wrapper.py,sha256=gHG-VNTUmLcTs5xtAtmnjOiSJRoBbvsiduPQyUWH8pA,13729
138
138
  hdl/utils/llm/vis.py,sha256=SSP6tOwKLq0hWcpM3twI9TitqzBmKjlcGrnXEWYlCzM,26055
139
139
  hdl/utils/llm/visrag.py,sha256=0i-VrxqgiV-J7R3VPshu9oc7-rKjFJOldYik3HDXj6M,10176
140
140
  hdl/utils/schedulers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
141
141
  hdl/utils/schedulers/norm_lr.py,sha256=bDwCmdEK-WkgxQMFBiMuchv8Mm7C0-GZJ6usm-PQk14,4461
142
142
  hdl/utils/weather/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
143
143
  hdl/utils/weather/weather.py,sha256=k11o6wM15kF8b9NMlEfrg68ak-SfSYLN3nOOflFUv-I,4381
144
- hjxdl-0.3.21.dist-info/LICENSE,sha256=lkMiSbeZHBQLB9LJEkS9-L3Z-LBC4yGnKrzHSG8RkPM,2599
145
- hjxdl-0.3.21.dist-info/METADATA,sha256=4iJS1jchqo13kaCQ7DzOspSZT1E4d3NJkn1bk75cGmc,1336
146
- hjxdl-0.3.21.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
147
- hjxdl-0.3.21.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
148
- hjxdl-0.3.21.dist-info/RECORD,,
144
+ hjxdl-0.3.23.dist-info/LICENSE,sha256=lkMiSbeZHBQLB9LJEkS9-L3Z-LBC4yGnKrzHSG8RkPM,2599
145
+ hjxdl-0.3.23.dist-info/METADATA,sha256=llZdZm3Z6-1VOhNdOgVHGwtW1mDAy2kfCYm85r5O-Eg,1336
146
+ hjxdl-0.3.23.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
147
+ hjxdl-0.3.23.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
148
+ hjxdl-0.3.23.dist-info/RECORD,,
File without changes