gohumanloop 0.0.2__py3-none-any.whl → 0.0.4__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.
- gohumanloop/adapters/langgraph_adapter.py +65 -52
- gohumanloop/core/interface.py +342 -21
- gohumanloop/core/manager.py +302 -39
- gohumanloop/manager/ghl_manager.py +24 -24
- gohumanloop/providers/api_provider.py +50 -24
- gohumanloop/providers/base.py +170 -9
- gohumanloop/providers/email_provider.py +66 -22
- gohumanloop/providers/terminal_provider.py +95 -23
- gohumanloop/utils/utils.py +33 -3
- {gohumanloop-0.0.2.dist-info → gohumanloop-0.0.4.dist-info}/METADATA +1 -1
- {gohumanloop-0.0.2.dist-info → gohumanloop-0.0.4.dist-info}/RECORD +15 -15
- {gohumanloop-0.0.2.dist-info → gohumanloop-0.0.4.dist-info}/WHEEL +1 -1
- {gohumanloop-0.0.2.dist-info → gohumanloop-0.0.4.dist-info}/entry_points.txt +0 -0
- {gohumanloop-0.0.2.dist-info → gohumanloop-0.0.4.dist-info}/licenses/LICENSE +0 -0
- {gohumanloop-0.0.2.dist-info → gohumanloop-0.0.4.dist-info}/top_level.txt +0 -0
gohumanloop/core/manager.py
CHANGED
@@ -53,11 +53,15 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
53
53
|
|
54
54
|
return provider_id
|
55
55
|
|
56
|
-
async def
|
56
|
+
async def async_register_provider(self, provider: HumanLoopProvider, provider_id: Optional[str] = None) -> str:
|
57
57
|
"""注册人机循环提供者"""
|
58
58
|
return self.register_provider_sync(provider, provider_id)
|
59
|
+
|
60
|
+
def register_provider(self, provider: HumanLoopProvider, provider_id: Optional[str] = None) -> str:
|
61
|
+
"""注册人机循环提供者(同步版本)"""
|
62
|
+
return self.register_provider_sync(provider, provider_id)
|
59
63
|
|
60
|
-
async def
|
64
|
+
async def async_request_humanloop(
|
61
65
|
self,
|
62
66
|
task_id: str,
|
63
67
|
conversation_id: str,
|
@@ -83,7 +87,7 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
83
87
|
|
84
88
|
try:
|
85
89
|
# 发送请求
|
86
|
-
result = await provider.
|
90
|
+
result = await provider.async_request_humanloop(
|
87
91
|
task_id=task_id,
|
88
92
|
conversation_id=conversation_id,
|
89
93
|
loop_type=loop_type,
|
@@ -116,24 +120,62 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
116
120
|
|
117
121
|
# 如果设置了超时,创建超时任务
|
118
122
|
if timeout:
|
119
|
-
self.
|
123
|
+
await self._async_create_timeout_task(conversation_id, request_id, timeout, provider, callback)
|
120
124
|
|
121
125
|
# 如果是阻塞模式,等待结果
|
122
126
|
if blocking:
|
123
|
-
return await self.
|
127
|
+
return await self._async_wait_for_result(conversation_id, request_id, provider, timeout)
|
124
128
|
else:
|
125
129
|
return request_id
|
126
130
|
except Exception as e:
|
127
131
|
# 处理请求过程中的异常
|
128
132
|
if callback:
|
129
133
|
try:
|
130
|
-
await callback.
|
134
|
+
await callback.async_on_humanloop_error(provider, e)
|
131
135
|
except:
|
132
136
|
# 如果错误回调也失败,只能忽略
|
133
137
|
pass
|
134
138
|
raise # 重新抛出异常,让调用者知道发生了错误
|
135
|
-
|
136
|
-
|
139
|
+
|
140
|
+
def request_humanloop(
|
141
|
+
self,
|
142
|
+
task_id: str,
|
143
|
+
conversation_id: str,
|
144
|
+
loop_type: HumanLoopType,
|
145
|
+
context: Dict[str, Any],
|
146
|
+
callback: Optional[HumanLoopCallback] = None,
|
147
|
+
metadata: Optional[Dict[str, Any]] = None,
|
148
|
+
provider_id: Optional[str] = None,
|
149
|
+
timeout: Optional[int] = None,
|
150
|
+
blocking: bool = False,
|
151
|
+
) -> Union[str, HumanLoopResult]:
|
152
|
+
"""请求人机循环(同步版本)"""
|
153
|
+
loop = asyncio.get_event_loop()
|
154
|
+
if loop.is_running():
|
155
|
+
# 如果事件循环已经在运行,创建一个新的事件循环
|
156
|
+
new_loop = asyncio.new_event_loop()
|
157
|
+
asyncio.set_event_loop(new_loop)
|
158
|
+
loop = new_loop
|
159
|
+
|
160
|
+
try:
|
161
|
+
return loop.run_until_complete(
|
162
|
+
self.async_request_humanloop(
|
163
|
+
task_id=task_id,
|
164
|
+
conversation_id=conversation_id,
|
165
|
+
loop_type=loop_type,
|
166
|
+
context=context,
|
167
|
+
callback=callback,
|
168
|
+
metadata=metadata,
|
169
|
+
provider_id=provider_id,
|
170
|
+
timeout=timeout,
|
171
|
+
blocking=blocking
|
172
|
+
)
|
173
|
+
)
|
174
|
+
finally:
|
175
|
+
if loop != asyncio.get_event_loop():
|
176
|
+
loop.close()
|
177
|
+
|
178
|
+
async def async_continue_humanloop(
|
137
179
|
self,
|
138
180
|
conversation_id: str,
|
139
181
|
context: Dict[str, Any],
|
@@ -160,7 +202,7 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
160
202
|
|
161
203
|
try:
|
162
204
|
# 发送继续请求
|
163
|
-
result = await provider.
|
205
|
+
result = await provider.async_continue_humanloop(
|
164
206
|
conversation_id=conversation_id,
|
165
207
|
context=context,
|
166
208
|
metadata=metadata,
|
@@ -197,24 +239,58 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
197
239
|
|
198
240
|
# 如果设置了超时,创建超时任务
|
199
241
|
if timeout:
|
200
|
-
self.
|
242
|
+
await self._async_create_timeout_task(conversation_id, request_id, timeout, provider, callback)
|
201
243
|
|
202
244
|
# 如果是阻塞模式,等待结果
|
203
245
|
if blocking:
|
204
|
-
return await self.
|
246
|
+
return await self._async_wait_for_result(conversation_id, request_id, provider, timeout)
|
205
247
|
else:
|
206
248
|
return request_id
|
207
249
|
except Exception as e:
|
208
250
|
# 处理继续请求过程中的异常
|
209
251
|
if callback:
|
210
252
|
try:
|
211
|
-
await callback.
|
253
|
+
await callback.async_on_humanloop_error(provider, e)
|
212
254
|
except:
|
213
255
|
# 如果错误回调也失败,只能忽略
|
214
256
|
pass
|
215
257
|
raise # 重新抛出异常,让调用者知道发生了错误
|
258
|
+
|
259
|
+
def continue_humanloop(
|
260
|
+
self,
|
261
|
+
conversation_id: str,
|
262
|
+
context: Dict[str, Any],
|
263
|
+
callback: Optional[HumanLoopCallback] = None,
|
264
|
+
metadata: Optional[Dict[str, Any]] = None,
|
265
|
+
provider_id: Optional[str] = None,
|
266
|
+
timeout: Optional[int] = None,
|
267
|
+
blocking: bool = False,
|
268
|
+
) -> Union[str, HumanLoopResult]:
|
269
|
+
"""继续人机循环(同步版本)"""
|
270
|
+
loop = asyncio.get_event_loop()
|
271
|
+
if loop.is_running():
|
272
|
+
# 如果事件循环已经在运行,创建一个新的事件循环
|
273
|
+
new_loop = asyncio.new_event_loop()
|
274
|
+
asyncio.set_event_loop(new_loop)
|
275
|
+
loop = new_loop
|
216
276
|
|
217
|
-
|
277
|
+
try:
|
278
|
+
return loop.run_until_complete(
|
279
|
+
self.async_continue_humanloop(
|
280
|
+
conversation_id=conversation_id,
|
281
|
+
context=context,
|
282
|
+
callback=callback,
|
283
|
+
metadata=metadata,
|
284
|
+
provider_id=provider_id,
|
285
|
+
timeout=timeout,
|
286
|
+
blocking=blocking
|
287
|
+
)
|
288
|
+
)
|
289
|
+
finally:
|
290
|
+
if loop != asyncio.get_event_loop():
|
291
|
+
loop.close()
|
292
|
+
|
293
|
+
async def async_check_request_status(
|
218
294
|
self,
|
219
295
|
conversation_id: str,
|
220
296
|
request_id: str,
|
@@ -232,11 +308,11 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
232
308
|
provider = self.providers[provider_id]
|
233
309
|
|
234
310
|
try:
|
235
|
-
result = await provider.
|
311
|
+
result = await provider.async_check_request_status(conversation_id, request_id)
|
236
312
|
|
237
313
|
# 如果有回调且状态不是等待或进行中,触发状态更新回调
|
238
314
|
if (conversation_id, request_id) in self._callbacks and result.status not in [HumanLoopStatus.PENDING]:
|
239
|
-
await self.
|
315
|
+
await self._async_trigger_update_callback(conversation_id, request_id, provider, result)
|
240
316
|
|
241
317
|
return result
|
242
318
|
except Exception as e:
|
@@ -244,13 +320,41 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
244
320
|
callback = self._callbacks.get((conversation_id, request_id))
|
245
321
|
if callback:
|
246
322
|
try:
|
247
|
-
await callback.
|
323
|
+
await callback.async_on_humanloop_error(provider, e)
|
248
324
|
except:
|
249
325
|
# 如果错误回调也失败,只能忽略
|
250
326
|
pass
|
251
327
|
raise # 重新抛出异常,让调用者知道发生了错误
|
252
|
-
|
253
|
-
|
328
|
+
|
329
|
+
|
330
|
+
def check_request_status(
|
331
|
+
self,
|
332
|
+
conversation_id: str,
|
333
|
+
request_id: str,
|
334
|
+
provider_id: Optional[str] = None
|
335
|
+
) -> HumanLoopResult:
|
336
|
+
"""检查请求状态(同步版本)"""
|
337
|
+
loop = asyncio.get_event_loop()
|
338
|
+
if loop.is_running():
|
339
|
+
# 如果事件循环已经在运行,创建一个新的事件循环
|
340
|
+
new_loop = asyncio.new_event_loop()
|
341
|
+
asyncio.set_event_loop(new_loop)
|
342
|
+
loop = new_loop
|
343
|
+
|
344
|
+
try:
|
345
|
+
return loop.run_until_complete(
|
346
|
+
self.async_check_request_status(
|
347
|
+
conversation_id=conversation_id,
|
348
|
+
request_id=request_id,
|
349
|
+
provider_id=provider_id
|
350
|
+
)
|
351
|
+
)
|
352
|
+
finally:
|
353
|
+
if loop != asyncio.get_event_loop():
|
354
|
+
loop.close()
|
355
|
+
|
356
|
+
|
357
|
+
async def async_check_conversation_status(
|
254
358
|
self,
|
255
359
|
conversation_id: str,
|
256
360
|
provider_id: Optional[str] = None
|
@@ -269,7 +373,7 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
269
373
|
|
270
374
|
try:
|
271
375
|
# 检查对话指定provider_id或默认provider_id最后一次请求的状态
|
272
|
-
return await provider.
|
376
|
+
return await provider.async_check_conversation_status(conversation_id)
|
273
377
|
except Exception as e:
|
274
378
|
# 处理检查对话状态过程中的异常
|
275
379
|
# 尝试找到与此对话关联的最后一个请求的回调
|
@@ -278,13 +382,37 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
278
382
|
callback = self._callbacks.get((conversation_id, last_request_id))
|
279
383
|
if callback:
|
280
384
|
try:
|
281
|
-
await callback.
|
385
|
+
await callback.async_on_humanloop_error(provider, e)
|
282
386
|
except:
|
283
387
|
# 如果错误回调也失败,只能忽略
|
284
388
|
pass
|
285
389
|
raise # 重新抛出异常,让调用者知道发生了错误
|
286
390
|
|
287
|
-
|
391
|
+
def check_conversation_status(
|
392
|
+
self,
|
393
|
+
conversation_id: str,
|
394
|
+
provider_id: Optional[str] = None
|
395
|
+
) -> HumanLoopResult:
|
396
|
+
"""检查对话状态(同步版本)"""
|
397
|
+
loop = asyncio.get_event_loop()
|
398
|
+
if loop.is_running():
|
399
|
+
# 如果事件循环已经在运行,创建一个新的事件循环
|
400
|
+
new_loop = asyncio.new_event_loop()
|
401
|
+
asyncio.set_event_loop(new_loop)
|
402
|
+
loop = new_loop
|
403
|
+
|
404
|
+
try:
|
405
|
+
return loop.run_until_complete(
|
406
|
+
self.async_check_conversation_status(
|
407
|
+
conversation_id=conversation_id,
|
408
|
+
provider_id=provider_id
|
409
|
+
)
|
410
|
+
)
|
411
|
+
finally:
|
412
|
+
if loop != asyncio.get_event_loop():
|
413
|
+
loop.close()
|
414
|
+
|
415
|
+
async def async_cancel_request(
|
288
416
|
self,
|
289
417
|
conversation_id: str,
|
290
418
|
request_id: str,
|
@@ -318,9 +446,37 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
318
446
|
if request_id in self._conversation_requests[conversation_id]:
|
319
447
|
self._conversation_requests[conversation_id].remove(request_id)
|
320
448
|
|
321
|
-
return await provider.
|
449
|
+
return await provider.async_cancel_request(conversation_id, request_id)
|
322
450
|
|
323
|
-
|
451
|
+
|
452
|
+
def cancel_request(
|
453
|
+
self,
|
454
|
+
conversation_id: str,
|
455
|
+
request_id: str,
|
456
|
+
provider_id: Optional[str] = None
|
457
|
+
) -> bool:
|
458
|
+
"""取消特定请求(同步版本)"""
|
459
|
+
loop = asyncio.get_event_loop()
|
460
|
+
if loop.is_running():
|
461
|
+
# 如果事件循环已经在运行,创建一个新的事件循环
|
462
|
+
new_loop = asyncio.new_event_loop()
|
463
|
+
asyncio.set_event_loop(new_loop)
|
464
|
+
loop = new_loop
|
465
|
+
|
466
|
+
try:
|
467
|
+
return loop.run_until_complete(
|
468
|
+
self.async_cancel_request(
|
469
|
+
conversation_id=conversation_id,
|
470
|
+
request_id=request_id,
|
471
|
+
provider_id=provider_id
|
472
|
+
)
|
473
|
+
)
|
474
|
+
finally:
|
475
|
+
if loop != asyncio.get_event_loop():
|
476
|
+
loop.close()
|
477
|
+
|
478
|
+
|
479
|
+
async def async_cancel_conversation(
|
324
480
|
self,
|
325
481
|
conversation_id: str,
|
326
482
|
provider_id: Optional[str] = None
|
@@ -382,9 +538,35 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
382
538
|
if conversation_id in self._conversation_provider:
|
383
539
|
del self._conversation_provider[conversation_id]
|
384
540
|
|
385
|
-
return await provider.
|
541
|
+
return await provider.async_cancel_conversation(conversation_id)
|
386
542
|
|
387
|
-
|
543
|
+
|
544
|
+
def cancel_conversation(
|
545
|
+
self,
|
546
|
+
conversation_id: str,
|
547
|
+
provider_id: Optional[str] = None
|
548
|
+
) -> bool:
|
549
|
+
"""取消整个对话(同步版本)"""
|
550
|
+
loop = asyncio.get_event_loop()
|
551
|
+
if loop.is_running():
|
552
|
+
# 如果事件循环已经在运行,创建一个新的事件循环
|
553
|
+
new_loop = asyncio.new_event_loop()
|
554
|
+
asyncio.set_event_loop(new_loop)
|
555
|
+
loop = new_loop
|
556
|
+
|
557
|
+
try:
|
558
|
+
return loop.run_until_complete(
|
559
|
+
self.async_cancel_conversation(
|
560
|
+
conversation_id=conversation_id,
|
561
|
+
provider_id=provider_id
|
562
|
+
)
|
563
|
+
)
|
564
|
+
finally:
|
565
|
+
if loop != asyncio.get_event_loop():
|
566
|
+
loop.close()
|
567
|
+
|
568
|
+
|
569
|
+
async def async_get_provider(
|
388
570
|
self,
|
389
571
|
provider_id: Optional[str] = None
|
390
572
|
) -> HumanLoopProvider:
|
@@ -395,11 +577,48 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
395
577
|
|
396
578
|
return self.providers[provider_id]
|
397
579
|
|
398
|
-
|
580
|
+
def get_provider(
|
581
|
+
self,
|
582
|
+
provider_id: Optional[str] = None
|
583
|
+
) -> HumanLoopProvider:
|
584
|
+
"""获取指定的提供者实例(同步版本)"""
|
585
|
+
loop = asyncio.get_event_loop()
|
586
|
+
if loop.is_running():
|
587
|
+
# 如果事件循环已经在运行,创建一个新的事件循环
|
588
|
+
new_loop = asyncio.new_event_loop()
|
589
|
+
asyncio.set_event_loop(new_loop)
|
590
|
+
loop = new_loop
|
591
|
+
|
592
|
+
try:
|
593
|
+
return loop.run_until_complete(
|
594
|
+
self.async_get_provider(provider_id=provider_id)
|
595
|
+
)
|
596
|
+
finally:
|
597
|
+
if loop != asyncio.get_event_loop():
|
598
|
+
loop.close()
|
599
|
+
|
600
|
+
async def async_list_providers(self) -> Dict[str, HumanLoopProvider]:
|
399
601
|
"""列出所有注册的提供者"""
|
400
602
|
return self.providers
|
401
603
|
|
402
|
-
|
604
|
+
|
605
|
+
def list_providers(self) -> Dict[str, HumanLoopProvider]:
|
606
|
+
"""列出所有注册的提供者(同步版本)"""
|
607
|
+
loop = asyncio.get_event_loop()
|
608
|
+
if loop.is_running():
|
609
|
+
# 如果事件循环已经在运行,创建一个新的事件循环
|
610
|
+
new_loop = asyncio.new_event_loop()
|
611
|
+
asyncio.set_event_loop(new_loop)
|
612
|
+
loop = new_loop
|
613
|
+
|
614
|
+
try:
|
615
|
+
return loop.run_until_complete(self.async_list_providers())
|
616
|
+
finally:
|
617
|
+
if loop != asyncio.get_event_loop():
|
618
|
+
loop.close()
|
619
|
+
|
620
|
+
|
621
|
+
async def async_set_default_provider(
|
403
622
|
self,
|
404
623
|
provider_id: str
|
405
624
|
) -> bool:
|
@@ -410,7 +629,29 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
410
629
|
self.default_provider_id = provider_id
|
411
630
|
return True
|
412
631
|
|
413
|
-
|
632
|
+
|
633
|
+
def set_default_provider(
|
634
|
+
self,
|
635
|
+
provider_id: str
|
636
|
+
) -> bool:
|
637
|
+
"""设置默认提供者(同步版本)"""
|
638
|
+
loop = asyncio.get_event_loop()
|
639
|
+
if loop.is_running():
|
640
|
+
# 如果事件循环已经在运行,创建一个新的事件循环
|
641
|
+
new_loop = asyncio.new_event_loop()
|
642
|
+
asyncio.set_event_loop(new_loop)
|
643
|
+
loop = new_loop
|
644
|
+
|
645
|
+
try:
|
646
|
+
return loop.run_until_complete(
|
647
|
+
self.async_set_default_provider(provider_id=provider_id)
|
648
|
+
)
|
649
|
+
finally:
|
650
|
+
if loop != asyncio.get_event_loop():
|
651
|
+
loop.close()
|
652
|
+
|
653
|
+
|
654
|
+
async def _async_create_timeout_task(
|
414
655
|
self,
|
415
656
|
conversation_id: str,
|
416
657
|
request_id: str,
|
@@ -422,13 +663,13 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
422
663
|
async def timeout_task():
|
423
664
|
await asyncio.sleep(timeout)
|
424
665
|
# 检查当前状态
|
425
|
-
result = await self.
|
666
|
+
result = await self.async_check_request_status(conversation_id, request_id, provider.name)
|
426
667
|
|
427
668
|
# 只有当状态为PENDING时才触发超时回调
|
428
669
|
# INPROGRESS状态表示对话正在进行中,不应视为超时
|
429
670
|
if result.status == HumanLoopStatus.PENDING:
|
430
671
|
if callback:
|
431
|
-
await callback.
|
672
|
+
await callback.async_on_humanloop_timeout(provider=provider)
|
432
673
|
# 如果状态是INPROGRESS,重置超时任务
|
433
674
|
elif result.status == HumanLoopStatus.INPROGRESS:
|
434
675
|
# 对于进行中的对话,我们可以选择延长超时时间
|
@@ -441,7 +682,7 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
441
682
|
task = asyncio.create_task(timeout_task())
|
442
683
|
self._timeout_tasks[(conversation_id, request_id)] = task
|
443
684
|
|
444
|
-
async def
|
685
|
+
async def _async_wait_for_result(
|
445
686
|
self,
|
446
687
|
conversation_id: str,
|
447
688
|
request_id: str,
|
@@ -453,7 +694,7 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
453
694
|
poll_interval = 1.0 # 轮询间隔(秒)
|
454
695
|
|
455
696
|
while True:
|
456
|
-
result = await self.
|
697
|
+
result = await self.async_check_request_status(conversation_id, request_id, provider.name)
|
457
698
|
|
458
699
|
#如果状态是最终状态(非PENDING),返回结果
|
459
700
|
if result.status != HumanLoopStatus.PENDING:
|
@@ -462,7 +703,7 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
462
703
|
# 等待一段时间后再次轮询
|
463
704
|
await asyncio.sleep(poll_interval)
|
464
705
|
|
465
|
-
async def
|
706
|
+
async def _async_trigger_update_callback(self, conversation_id: str, request_id: str, provider: HumanLoopProvider, result: HumanLoopResult):
|
466
707
|
"""触发状态更新回调"""
|
467
708
|
callback: Optional[HumanLoopCallback] = self._callbacks.get((conversation_id, request_id))
|
468
709
|
if callback:
|
@@ -480,7 +721,7 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
480
721
|
pass
|
481
722
|
|
482
723
|
# 添加新方法用于获取task相关信息
|
483
|
-
async def
|
724
|
+
async def async_get_task_conversations(self, task_id: str) -> List[str]:
|
484
725
|
"""获取任务关联的所有对话ID
|
485
726
|
|
486
727
|
Args:
|
@@ -502,7 +743,7 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
502
743
|
"""
|
503
744
|
return list(self._task_conversations.get(task_id, set()))
|
504
745
|
|
505
|
-
async def
|
746
|
+
async def async_get_conversation_requests(self, conversation_id: str) -> List[str]:
|
506
747
|
"""获取对话关联的所有请求ID
|
507
748
|
|
508
749
|
Args:
|
@@ -524,7 +765,7 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
524
765
|
"""
|
525
766
|
return self._conversation_requests.get(conversation_id, [])
|
526
767
|
|
527
|
-
async def
|
768
|
+
async def async_get_request_task(self, conversation_id: str, request_id: str) -> Optional[str]:
|
528
769
|
"""获取请求关联的任务ID
|
529
770
|
|
530
771
|
Args:
|
@@ -536,7 +777,7 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
536
777
|
"""
|
537
778
|
return self._request_task.get((conversation_id, request_id))
|
538
779
|
|
539
|
-
async def
|
780
|
+
async def async_get_conversation_provider(self, conversation_id: str) -> Optional[str]:
|
540
781
|
"""获取请求关联的提供者ID
|
541
782
|
|
542
783
|
Args:
|
@@ -547,7 +788,29 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
547
788
|
"""
|
548
789
|
return self._conversation_provider.get(conversation_id)
|
549
790
|
|
550
|
-
async def
|
791
|
+
async def async_check_conversation_exist(
|
792
|
+
self,
|
793
|
+
task_id:str,
|
794
|
+
conversation_id: str,
|
795
|
+
) -> bool:
|
796
|
+
"""判断对话是否已存在
|
797
|
+
|
798
|
+
Args:
|
799
|
+
conversation_id: 对话标识符
|
800
|
+
provider_id: 使用特定提供者的ID(可选)
|
801
|
+
|
802
|
+
Returns:
|
803
|
+
bool: 如果对话存在返回True,否则返回False
|
804
|
+
"""
|
805
|
+
# 检查task_id是否存在且conversation_id是否在该task的对话集合中
|
806
|
+
if task_id in self._task_conversations and conversation_id in self._task_conversations[task_id]:
|
807
|
+
# 进一步验证该对话是否有关联的请求
|
808
|
+
if conversation_id in self._conversation_requests and self._conversation_requests[conversation_id]:
|
809
|
+
return True
|
810
|
+
|
811
|
+
return False
|
812
|
+
|
813
|
+
def check_conversation_exist(
|
551
814
|
self,
|
552
815
|
task_id:str,
|
553
816
|
conversation_id: str,
|
@@ -569,7 +832,7 @@ class DefaultHumanLoopManager(HumanLoopManager):
|
|
569
832
|
|
570
833
|
return False
|
571
834
|
|
572
|
-
async def
|
835
|
+
async def async_shutdown(self):
|
573
836
|
pass
|
574
837
|
|
575
838
|
def shutdown(self):
|