Spaces:
Configuration error
Configuration error
Download clients/python/nvidia_nim.py from AnthropicallyHuggingFaces/ai-platform-toolbox: direct link, hf CLI and curl.
- Browser
- Download file 705 Bytes
-
https://huggingface.co/spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/resolve/main/clients/python/nvidia_nim.py
- Command line
-
hf download hf://spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/clients/python/nvidia_nim.py
-
curl -L -o nvidia_nim.py https://huggingface.co/spaces/AnthropicallyHuggingFaces/ai-platform-toolbox/resolve/main/clients/python/nvidia_nim.py
705 Bytes
| """NVIDIA NIM client - OpenAI-compatible chat completions.""" | |
| import os | |
| import requests | |
| BASE = os.getenv("NVIDIA_NIM_BASE", "https://integrate.api.nvidia.com/v1") | |
| KEY = os.getenv("NVIDIA_API_KEY") | |
| def _h(): | |
| headers = {"Content-Type": "application/json"} | |
| if KEY: | |
| headers["Authorization"] = f"Bearer {KEY}" | |
| return headers | |
| def chat(messages, model="meta/llama-3.1-8b-instruct", stream=False, **kwargs): | |
| body = {"model": model, "messages": messages, "stream": stream, **kwargs} | |
| return requests.post(f"{BASE}/chat/completions", headers=_h(), json=body, timeout=120, stream=stream) | |
| def list_models(): | |
| return requests.get(f"{BASE}/models", headers=_h(), timeout=30).json() | |