项目文件夹

文件
wehub-resource-sync e768098d0e
tools_continuous_delivery / Private PyPI non-main branch release (push) Has been skipped
tools_continuous_delivery / Private PyPI main branch release (push) Failing after 2m42s
Publish Promptflow Doc / Build (push) Has been cancelled
Publish Promptflow Doc / Deploy (push) Has been cancelled
Flake8 Lint / flake8 (push) Has been cancelled
Spell check CI / Spell_Check (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:39:52 +08:00

33 行
1.1 KiB
Python

from promptflow.core import tool
import json
import numpy as np
@tool
def calculate(llm_result: str) -> str:
try:
score = 1
response = json.loads(llm_result)
if response:
result = response.get("result", "")
print(result)
if result:
response = [
# Also handle 'attribited' here since llm tool will return 'attribited'
# instead of 'attributed' in its' response
int(item.get("attributed", "").lower() == "yes" or item.get("attribited", "").lower() == "yes")
if item.get("attributed") or item.get("attribited")
else np.nan
for item in result
]
denom = len(response)
print(response)
print(denom)
numerator = sum(response)
score = 5 * numerator / denom
return score if score >= 1 else 1
except Exception as e:
print("exception in calculate_context_recall: " + str(e))
print("llm_result: " + llm_result)
return np.nan