hjxdl 0.3.18__py3-none-any.whl → 0.3.20__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.18'
16
- __version_tuple__ = version_tuple = (0, 3, 18)
15
+ __version__ = version = '0.3.20'
16
+ __version_tuple__ = version_tuple = (0, 3, 20)
@@ -169,31 +169,43 @@ class OpenAIWrapper(object):
169
169
  answer_dict["contents"] = resp.choices[0].message.content
170
170
  elif resp.choices[0].finish_reason == "tool_calls":
171
171
  answer_dict["type"] = "tool_calls"
172
- answer_dict["tool_parmas"] = resp.choices[0].message.tool_calls[0].function
172
+ answer_dict["tool_params"] = resp.choices[0].message.tool_calls[0].function
173
173
 
174
174
  return answer_dict
175
175
 
176
- def stream(
177
- self,
178
- prompt,
179
- **kwargs
180
- ):
181
- resp = self.get_resp(
182
- prompt=prompt,
183
- stream=True,
184
- **kwargs
185
- )
176
+ def stream(self, prompt, **kwargs):
177
+ resp = self.get_resp(prompt=prompt, stream=True, **kwargs)
178
+
186
179
  for chunk in resp:
187
- if chunk.choices[0].finish_reason == 'tool_calls':
188
- answer_dict = {}
189
- answer_dict["type"] = "tool_calls"
190
- answer_dict["tool_parmas"] = chunk.choices[0].delta.tool_calls[0].function
191
- return answer_dict
192
- else:
180
+ try:
181
+ choice = chunk.choices[0]
182
+
183
+ # 如果返回了 tool_calls
184
+ if hasattr(choice.delta, 'tool_calls') and choice.finish_reason == 'tool_calls':
185
+ tool_calls = choice.delta.tool_calls
186
+ if tool_calls: # 防止为空
187
+ yield {
188
+ "type": "tool_calls",
189
+ "tool_params": tool_calls[0].function
190
+ }
191
+ return # 直接返回,结束流式输出
192
+
193
+ # 返回文本内容
194
+ if hasattr(choice.delta, 'content'):
195
+ yield {
196
+ "type": "text",
197
+ "content": choice.delta.content
198
+ }
199
+
200
+ except (AttributeError, IndexError) as e:
201
+ # 防止意外的结构异常
193
202
  yield {
194
- "type": "text",
195
- "content": chunk.choices[0].delta.content
203
+ "type": "error",
204
+ "message": f"Stream chunk error: {str(e)}"
196
205
  }
206
+ return
207
+
208
+ return
197
209
 
198
210
 
199
211
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: hjxdl
3
- Version: 0.3.18
3
+ Version: 0.3.20
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=QAzjzlQ8v3ZqOKXdT0jblmkqebjcDj2MPKGBvc_ei_4,413
2
+ hdl/_version.py,sha256=0XAfq64E2h3BqosuCJunl1ENlgUhVRN79F4E0l9nrdU,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=Wk-ejwooxB6SRKuHW-UYxoBxgpYr9j-7ttKtFAaWFXw,5859
137
+ hdl/utils/llm/llm_wrapper.py,sha256=94xfPIR_eP7_S8FMCmRDvYpMnKpv9qVR9eDs2F7Nq-Y,6420
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.18.dist-info/LICENSE,sha256=lkMiSbeZHBQLB9LJEkS9-L3Z-LBC4yGnKrzHSG8RkPM,2599
145
- hjxdl-0.3.18.dist-info/METADATA,sha256=X1nGN-ixCM4ltZjIrxPGCzkOGUXy-aIpeRhrNmaCWIQ,1336
146
- hjxdl-0.3.18.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
147
- hjxdl-0.3.18.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
148
- hjxdl-0.3.18.dist-info/RECORD,,
144
+ hjxdl-0.3.20.dist-info/LICENSE,sha256=lkMiSbeZHBQLB9LJEkS9-L3Z-LBC4yGnKrzHSG8RkPM,2599
145
+ hjxdl-0.3.20.dist-info/METADATA,sha256=BJx8IbACYa8koyo5VGzB4q9R348FSz5U03Z_gLcHaXA,1336
146
+ hjxdl-0.3.20.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
147
+ hjxdl-0.3.20.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
148
+ hjxdl-0.3.20.dist-info/RECORD,,
File without changes