chore: 添加虚拟环境到仓库
- 添加 backend_service/venv 虚拟环境 - 包含所有Python依赖包 - 注意:虚拟环境约393MB,包含12655个文件
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""The built-in hook functions in agentscope."""
|
||||
from functools import partial
|
||||
|
||||
from ._studio_hooks import (
|
||||
as_studio_forward_message_pre_print_hook,
|
||||
)
|
||||
from .. import _config
|
||||
from ..agent import AgentBase
|
||||
|
||||
|
||||
__all__ = [
|
||||
"as_studio_forward_message_pre_print_hook",
|
||||
]
|
||||
|
||||
|
||||
def _equip_as_studio_hooks(
|
||||
studio_url: str,
|
||||
) -> None:
|
||||
"""Connect to the agentscope studio."""
|
||||
AgentBase.register_class_hook(
|
||||
"pre_print",
|
||||
"as_studio_forward_message_pre_print_hook",
|
||||
partial(
|
||||
as_studio_forward_message_pre_print_hook,
|
||||
studio_url=studio_url,
|
||||
run_id=_config.run_id,
|
||||
),
|
||||
)
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,47 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""The studio related hook functions in agentscope."""
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
import shortuuid
|
||||
|
||||
from ..agent import AgentBase
|
||||
|
||||
|
||||
def as_studio_forward_message_pre_print_hook(
|
||||
self: AgentBase,
|
||||
kwargs: dict[str, Any],
|
||||
studio_url: str,
|
||||
run_id: str,
|
||||
) -> None:
|
||||
"""The pre-speak hook to forward messages to the studio."""
|
||||
msg = kwargs["msg"]
|
||||
|
||||
message_data = msg.to_dict()
|
||||
|
||||
if hasattr(self, "_reply_id"):
|
||||
reply_id = getattr(self, "_reply_id")
|
||||
else:
|
||||
reply_id = shortuuid.uuid()
|
||||
|
||||
n_retry = 0
|
||||
while True:
|
||||
try:
|
||||
res = requests.post(
|
||||
f"{studio_url}/trpc/pushMessage",
|
||||
json={
|
||||
"runId": run_id,
|
||||
"replyId": reply_id,
|
||||
"name": reply_id,
|
||||
"role": "assistant",
|
||||
"msg": message_data,
|
||||
},
|
||||
)
|
||||
res.raise_for_status()
|
||||
break
|
||||
except Exception as e:
|
||||
if n_retry < 3:
|
||||
n_retry += 1
|
||||
continue
|
||||
|
||||
raise e from None
|
||||
Reference in New Issue
Block a user