agentchat.utils
gather_usage_summary
def gather_usage_summary(
agents: List[Agent]) -> Dict[Dict[str, Dict], Dict[str, Dict]]
从所有代理中汇总使用 情况摘要。
参数:
agents
- (list): 代理列表。
返回值:
dictionary
- 包含两个键的字典:- "usage_including_cached_inference":包括缓存推理中的令牌在内的总使用情况的成本信息。
- "usage_excluding_cached_inference":不包括缓存中的令牌在内的令牌使用情况的成本信息。不超过"usage_including_cached_inference"。
示例:
{
"usage_including_cached_inference" : {
"total_cost": 0.0006090000000000001,
"gpt-35-turbo": {
"cost": 0.0006090000000000001,
"prompt_tokens": 242,
"completion_tokens": 123,
"total_tokens": 365
},
},
"usage_excluding_cached_inference" : {
"total_cost": 0.0006090000000000001,
"gpt-35-turbo": {
"cost": 0.0006090000000000001,
"prompt_tokens": 242,
"completion_tokens": 123,
"total_tokens": 365
},
}
}
备注:
如果没有代理产生任何费用(没有客户端),则 usage_including_cached_inference 和 usage_excluding_cached_inference 将为 {'total_cost': 0}
。
parse_tags_from_content
def parse_tags_from_content(
tag: str,
content: Union[str, List[Dict[str,
Any]]]) -> List[Dict[str, Dict[str, str]]]
从消息内容中解析HTML样式标签。
解析是通过查找与HTML标签格式匹配的文本模式来完成的。要解析的标签是作为函数的参数指定的。函数在文本中查找此标签并提取其内容。标签的内容是在标签内部,位于开放和关闭尖括号之间的所有内容。内容可以是单个字符串 或一组属性-值对。
示例:
<img http://example.com/image.png> -> [{"tag": "img", "attr": {"src": "http://example.com/image.png"}, "match": re.Match}]
[{"tag"
- "audio", "attr": {"text": "Hello I'm a robot", "prompt": "whisper"}, "match": re.Match}]
参数:
tag
str - 要解析的HTML样式标签。content
Union[str, List[Dict[str, Any]]] - 要解析的消息内容。可以是字符串或内容项的列表。
返回值:
List[Dict[str, str]]:一个字典列表,每个字典表示一个解析的标签。每个字典包含三个键值对:'type' 是标签,'attr' 是解析的属性的字典,'match' 是正则表达式匹配对象。
引发:
ValueError
- 如果内容不是字符串或列表。