hjxdl 0.3.19__py3-none-any.whl → 0.3.21__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.19'
16
- __version_tuple__ = version_tuple = (0, 3, 19)
15
+ __version__ = version = '0.3.21'
16
+ __version_tuple__ = version_tuple = (0, 3, 21)
@@ -14,6 +14,26 @@ class OpenAIWrapper(object):
14
14
  *args,
15
15
  **kwargs
16
16
  ):
17
+ """
18
+ Initializes the client configuration for the class.
19
+
20
+ Args:
21
+ client_conf (dict, optional): A dictionary containing client configuration. If None,
22
+ client configuration will be loaded from the specified directory.
23
+ client_conf_dir (str, optional): The directory from which to load client configuration
24
+ if `client_conf` is None. Must be provided in that case.
25
+ load_conf (bool, optional): A flag indicating whether to load the client
26
+ configuration from the directory. Defaults to True.
27
+ *args: Variable length argument list for client initialization.
28
+ **kwargs: Arbitrary keyword arguments for client initialization.
29
+
30
+ Raises:
31
+ AssertionError: If `client_conf` is None and `client_conf_dir` is also None.
32
+
33
+ Note:
34
+ The method will create a client for each configuration found in `client_conf`,
35
+ initializing the client with the specified `base_url` and `api_key`.
36
+ """
17
37
  self.client_conf = {}
18
38
  if client_conf is None:
19
39
  assert client_conf_dir is not None
@@ -41,6 +61,24 @@ class OpenAIWrapper(object):
41
61
  api_key: str = "dummy_key",
42
62
  **kwargs
43
63
  ):
64
+ """
65
+ Add a new client configuration to the client manager.
66
+
67
+ This method stores the configuration details for a new client identified by the
68
+ provided client ID. It constructs the host URL based on the input parameters
69
+ and initializes an OpenAI client instance.
70
+
71
+ Args:
72
+ client_id (str): Unique identifier for the client.
73
+ host (str): Hostname or IP address of the client.
74
+ port (int, optional): Port number for the client connection. Defaults to None.
75
+ model (str, optional): Model to use for the client. Defaults to "default_model".
76
+ api_key (str, optional): API key for authentication. Defaults to "dummy_key".
77
+ **kwargs: Additional keyword arguments passed to the OpenAI client.
78
+
79
+ Raises:
80
+ ValueError: If both host and port are not valid for constructing a URL.
81
+ """
44
82
  self.client_conf[client_id] = {}
45
83
  if not host.startswith('http') and port:
46
84
  host = f"http://{host}:{port}/v1"
@@ -53,6 +91,22 @@ class OpenAIWrapper(object):
53
91
  )
54
92
 
55
93
  def load_clients(self):
94
+ """
95
+ Loads client configuration from a YAML file and updates the 'host' field
96
+ for each client entry, ensuring the correct URL format.
97
+
98
+ This method reads the client configuration from the specified path,
99
+ updates the 'host' field to include the appropriate port and the
100
+ 'http' protocol if not already specified, and stores the updated
101
+ configuration in the `client_conf` attribute.
102
+
103
+ Attributes:
104
+ client_conf_path (str): The file path to the client configuration YAML file.
105
+ client_conf (dict): The updated client configuration after processing.
106
+
107
+ Returns:
108
+ None
109
+ """
56
110
  with open(self.client_conf_path, 'r') as file:
57
111
  data = yaml.safe_load(file)
58
112
 
@@ -79,6 +133,26 @@ class OpenAIWrapper(object):
79
133
  response_model = None,
80
134
  **kwargs: t.Any,
81
135
  ):
136
+ """
137
+ Generates a response from a chat model based on the given prompt and additional context.
138
+
139
+ Args:
140
+ prompt (str): The main text prompt to send to the chat model.
141
+ client_id (str, optional): Identifier for the client configuration. Defaults to None.
142
+ history (list, optional): A list of previous messages to provide context for the conversation. Each message should be a dictionary with "role" and "content". Defaults to None.
143
+ sys_info (str, optional): System-level information to set the context of the chat. Defaults to None.
144
+ assis_info (str, optional): Information from the assistant to be included in the conversation. Defaults to None.
145
+ images (list, optional): A list of images to include in the message content. Defaults to None.
146
+ image_keys (tuple, optional): Keys to format the image data. Must be of length 1 or 2. Defaults to ("image_url", "url").
147
+ model (str, optional): The model to use for generating the response. If not provided, it defaults to the one in client configuration for the given client_id.
148
+ tools (list, optional): List of tools to be available during the chat. Defaults to None.
149
+ stream (bool, optional): Whether to stream the response. Defaults to True.
150
+ response_model (optional): Specifies the response model to use. Defaults to None.
151
+ **kwargs (Any): Additional configuration parameters.
152
+
153
+ Returns:
154
+ Response: The response object from the chat model.
155
+ """
82
156
  if not model:
83
157
  model = self.client_conf[client_id]['model']
84
158
 
@@ -157,6 +231,20 @@ class OpenAIWrapper(object):
157
231
  prompt,
158
232
  **kwargs
159
233
  ):
234
+ """
235
+ Invoke the API to get a response based on the provided prompt.
236
+
237
+ Args:
238
+ prompt (str): The input prompt to be processed.
239
+ **kwargs: Additional keyword arguments to customize the API request.
240
+
241
+ Returns:
242
+ dict: A dictionary containing the type of response and its contents.
243
+ The possible keys are:
244
+ - 'type' (str): Indicates the type of response ('text' or 'tool_calls').
245
+ - 'contents' (str, optional): The text content if the response type is 'text'.
246
+ - 'tool_params' (dict, optional): The parameters of the tool called if the response type is 'tool_calls'.
247
+ """
160
248
  answer_dict = {}
161
249
 
162
250
  resp = self.get_resp(
@@ -169,11 +257,29 @@ class OpenAIWrapper(object):
169
257
  answer_dict["contents"] = resp.choices[0].message.content
170
258
  elif resp.choices[0].finish_reason == "tool_calls":
171
259
  answer_dict["type"] = "tool_calls"
172
- answer_dict["tool_parmas"] = resp.choices[0].message.tool_calls[0].function
260
+ answer_dict["tool_params"] = resp.choices[0].message.tool_calls[0].function
173
261
 
174
262
  return answer_dict
175
263
 
176
264
  def stream(self, prompt, **kwargs):
265
+ """
266
+ Streams responses based on the provided prompt, yielding chunks of data.
267
+
268
+ This function calls the `get_resp` method with the prompt and additional keyword arguments,
269
+ streaming the response in chunks. It processes each chunk to yield either tool call parameters
270
+ or textual content. If an error occurs while processing the chunks, it yields an error message.
271
+
272
+ Args:
273
+ prompt (str): The input prompt to generate responses for.
274
+ **kwargs: Additional keyword arguments to be passed to the `get_resp` method.
275
+
276
+ Yields:
277
+ dict: A dictionary with the following possible keys:
278
+ - type (str): Indicates the type of the response ('tool_calls', 'text', or 'error').
279
+ - tool_params (dict, optional): Parameters of the tool call if the type is 'tool_calls'.
280
+ - content (str, optional): The generated text content if the type is 'text'.
281
+ - message (str, optional): An error message if the type is 'error'.
282
+ """
177
283
  resp = self.get_resp(prompt=prompt, stream=True, **kwargs)
178
284
 
179
285
  for chunk in resp:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: hjxdl
3
- Version: 0.3.19
3
+ Version: 0.3.21
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=TShPZTYoCOKWQEXBwv0B-a34cT3XntbYgzYc_AWIjXw,413
2
+ hdl/_version.py,sha256=RePWyWgLItSCeI7HV40DbnyFzjteC1Gpxd4cuRPe79I,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=fGe1jDwJKP7X5twjWbOQdaBH62OEm183bEnbWut_kjE,6420
137
+ hdl/utils/llm/llm_wrapper.py,sha256=sg1uh06yd5gEnHVhSp6FgQI9cOGFVJt0e0_vYpzpRPE,12377
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.19.dist-info/LICENSE,sha256=lkMiSbeZHBQLB9LJEkS9-L3Z-LBC4yGnKrzHSG8RkPM,2599
145
- hjxdl-0.3.19.dist-info/METADATA,sha256=E0ZcEclBokJou9oSSvR38M8dgnfoII_NPT7nDAACGjQ,1336
146
- hjxdl-0.3.19.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
147
- hjxdl-0.3.19.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
148
- hjxdl-0.3.19.dist-info/RECORD,,
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,,
File without changes