Spaces:
Configuration error
Configuration error
Download clients/python/langsmith.py from AnthropicallyHuggingFaces/ai-platform-toolbox: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/resolve/main/clients/python/langsmith.py
- Command line
-
hf download hf://spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/clients/python/langsmith.py
-
curl -L -o langsmith.py https://huggingface.co/spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/resolve/main/clients/python/langsmith.py
1.2 kB
| """LangSmith client - tracing, datasets, evaluation.""" | |
| import os | |
| import requests | |
| BASE = os.getenv("LANGSMITH_ENDPOINT", "https://api.smith.langchain.com") | |
| KEY = os.getenv("LANGSMITH_API_KEY") | |
| def _h(): | |
| if not KEY: | |
| raise RuntimeError("LANGSMITH_API_KEY not set") | |
| return {"x-api-key": KEY, "Content-Type": "application/json"} | |
| def list_runs(limit=50, **params): | |
| return requests.get(f"{BASE}/runs", headers=_h(), params={"limit": limit, **params}, timeout=60).json() | |
| def get_run(run_id: str): | |
| return requests.get(f"{BASE}/runs/{run_id}", headers=_h(), timeout=60).json() | |
| def create_dataset(name, description=""): | |
| return requests.post(f"{BASE}/datasets", headers=_h(), json={"name": name, "description": description}, timeout=60).json() | |
| def upload_examples(dataset_id, examples): | |
| return requests.post(f"{BASE}/datasets/{dataset_id}/examples", headers=_h(), json=examples, timeout=120).json() | |
| def evaluate(run_name, evaluator, dataset_id, project_id=None): | |
| return requests.post(f"{BASE}/eval", headers=_h(), json={ | |
| "evaluators": [evaluator], "runName": run_name, | |
| "datasetId": dataset_id, "projectId": project_id, | |
| }, timeout=120).json() | |