Files
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

37 lines
980 B
Python

from typing import Any
import requests
from tau_bench.model_utils.model.general_model import wrap_temperature
def generate_request(
url: str,
prompt: str,
temperature: float = 0.0,
force_json: bool = False,
**req_body_kwargs: Any,
) -> str:
args = {
"prompt": prompt,
"temperature": wrap_temperature(temperature),
"max_tokens": 4096,
**req_body_kwargs,
}
if force_json:
# the prompt will have a suffix of '```json\n' to indicate that the response should be a JSON object
args["stop"] = ["```"]
res = requests.post(
url,
json=args,
)
res.raise_for_status()
json_res = res.json()
if "text" not in json_res:
raise ValueError(f"Unexpected response: {json_res}")
elif len(json_res["text"]) == 0:
raise ValueError(f"Empty response: {json_res}")
text = json_res["text"][0]
assert isinstance(text, str)
return text.removeprefix(prompt)