Spaces:
Sleeping
Sleeping
Polish price formatting and add remote validation script
Browse filesFiles changed (4)
- README.md+1
- router.py+2-2
- scripts/deploy.py+1-1
- scripts/smoke_remote.pyAdded+70
106 unmodified lines107108109110111112106 unmodified linesrequirements.txt Python 依赖(Gradio 由平台管理)packages.txt 系统依赖(LibreOffice、中文字体)scripts/deploy.py 私有 Space 创建、Secret 配置与上传```部署后的验收:确认 `RUNNING` 和启动日志;分别选择三个模型发送短消息;上传 PDF、DOCX、PPTX、XLSX 和图片各一份;追问附件内容;测试开启/关闭联网与来源显示;验证停止、新建对话和无效文件提示。仅语法检查不能代替这些线上验证。106 unmodified lines107108109110111112113106 unmodified linesrequirements.txt Python 依赖(Gradio 由平台管理)packages.txt 系统依赖(LibreOffice、中文字体)scripts/deploy.py 私有 Space 创建、Secret 配置与上传scripts/smoke_remote.py 远程 Space 端到端验收(会产生少量 API 用量)```部署后的验收:确认 `RUNNING` 和启动日志;分别选择三个模型发送短消息;上传 PDF、DOCX、PPTX、XLSX 和图片各一份;追问附件内容;测试开启/关闭联网与来源显示;验证停止、新建对话和无效文件提示。仅语法检查不能代替这些线上验证。
45 unmodified lines464748495051525345 unmodified linesm = data.get(model_id)try:p = m["pricing"]inp = f'{Decimal(p["prompt"]) * 1_000_000:g}'out = f'{Decimal(p["completion"]) * 1_000_000:g}'search = f'${Decimal(p["web_search"]):g}/次' if p.get("web_search") else "按搜索引擎计费"source = "目录报价"except (KeyError, TypeError, ArithmeticError):45 unmodified lines464748495051525345 unmodified linesm = data.get(model_id)try:p = m["pricing"]inp = format((Decimal(p["prompt"]) * 1_000_000).normalize(), "f")out = format((Decimal(p["completion"]) * 1_000_000).normalize(), "f")search = f'${Decimal(p["web_search"]):g}/次' if p.get("web_search") else "按搜索引擎计费"source = "目录报价"except (KeyError, TypeError, ArithmeticError):
7 unmodified lines8910111213147 unmodified linesROOT = Path(__file__).resolve().parents[1]FILES = ["README.md", "app.py", "router.py", "attachments.py", "requirements.txt","packages.txt", ".gitignore", ".env.example", "scripts/deploy.py"]def run(args: list[str], **kwargs) -> subprocess.CompletedProcess:7 unmodified lines8910111213147 unmodified linesROOT = Path(__file__).resolve().parents[1]FILES = ["README.md", "app.py", "router.py", "attachments.py", "requirements.txt","packages.txt", ".gitignore", ".env.example", "scripts/deploy.py", "scripts/smoke_remote.py"]def run(args: list[str], **kwargs) -> subprocess.CompletedProcess:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970"""Small, billed end-to-end checks against an already deployed private Space.
Requires gradio_client and huggingface_hub. Fixtures are deliberately synthetic.Never reads or prints the OpenRouter API key; the Space uses its Secret."""
import argparseimport jsonfrom pathlib import Path
from gradio_client import Client, handle_filefrom huggingface_hub import get_token
def answer_text(result: tuple) -> str: messages = result[0] if not messages or messages[-1]["role"] != "assistant": return "" content = messages[-1]["content"] if isinstance(content, str): return content return "\n".join(part.get("text", "") for part in content if part.get("type") == "text")
def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("repo_id") parser.add_argument("--fixtures", type=Path) parser.add_argument("--case", choices=["models", "files", "search", "errors", "prices"], required=True) args = parser.parse_args() client = Client(args.repo_id, token=get_token(), httpx_kwargs={"timeout": 360}, verbose=False)
def chat(text: str, files=None, model="anthropic/claude-sonnet-5.5", search=False, max_tokens=1024): result = client.predict(text, files or [], model, search, max_tokens, "low", api_name="/chat") answer = answer_text(result) print(json.dumps({"model": model, "answer": answer[:2000], "status": result[-1]}, ensure_ascii=False), flush=True) return answer, result
if args.case == "prices": result = client.predict("anthropic/claude-sonnet-5.5", api_name="/prices") assert all(name in result[-1] for name in ["Opus 5.5", "Sonnet 5.5", "Fable 5.1"]) print(result[-1], flush=True) elif args.case == "models": for slug in ["sonnet-5.5", "opus-5.5", "fable-5.1"]: answer, result = chat("This is a connectivity test. Reply with exactly CONNECTED.", model="anthropic/claude-" + slug) assert "CONNECTED" in answer, result[-1] elif args.case == "files": if not args.fixtures: parser.error("--fixtures is required") files = [handle_file(str(args.fixtures / ("sample." + ext))) for ext in ["pdf", "docx", "pptx", "xlsx", "png", "csv"]] answer, result = chat("Read all six attachments. Return the PDF_CODE, WORD_CODE, SLIDE_CODE, SHEET_CODE, CSV_CODE values and the image's dominant color. Be brief.", files=files, max_tokens=2048) for code in ["ORANGE-42", "MAPLE-17", "OCEAN-29", "CEDAR-63", "BIRCH-36"]: assert code in answer, (code, result[-1]) assert "red" in answer.lower() or "红" in answer answer, result = chat("Without uploading again, what was WORD_CODE in the earlier Word attachment? Reply with its value only.") assert "MAPLE-17" in answer, result[-1] elif args.case == "search": answer, result = chat("Use web search now to find the official Hugging Face Spaces overview documentation. State one hosting option and cite its URL. Keep the answer under 100 words.", search=True, max_tokens=2048) assert "huggingface.co" in answer, result[-1] assert "参考来源" in answer or "联网搜索 1" in result[-1], "Need evidence of tool execution, not just a guessed URL" elif args.case == "errors": if not args.fixtures: parser.error("--fixtures is required") answer, result = chat("Read this file", files=[handle_file(str(args.fixtures / "invalid.pdf"))]) assert "无法解析" in result[-1] and not answer print("PASS: " + args.case, flush=True)
if __name__ == "__main__": main()README.md+1
router.py+2-2
scripts/deploy.py+1-1
scripts/smoke_remote.pyAdded+70