Download LLM/proxy_client.py from GakkiLi/simcourt: direct link, hf CLI and curl.
- Browser
- Download file 983 Bytes
-
https://huggingface.co/spaces/GakkiLi/simcourt/resolve/main/LLM/proxy_client.py
- Command line
-
hf download hf://spaces/GakkiLi/simcourt/LLM/proxy_client.py
-
curl -L -o proxy_client.py https://huggingface.co/spaces/GakkiLi/simcourt/resolve/main/LLM/proxy_client.py
983 Bytes
| import json | |
| from .base_client import BaseClient | |
| from api_pool.api_pool import api_pool | |
| class ProxyClient(BaseClient): | |
| def __init__(self, model_name): | |
| if model_name not in api_pool: | |
| raise ValueError("Invalid model name") | |
| self.query_function = api_pool[model_name] | |
| def send_request( | |
| self, | |
| messages, | |
| temperature=0, | |
| max_tokens=4096, | |
| *args, | |
| **kwargs, | |
| ): #temperature is set to zero | |
| # Prepare the payload | |
| payload = { | |
| "messages": messages, | |
| "temperature": temperature, | |
| "max_tokens": max_tokens, | |
| } | |
| # Call the appropriate function from api_pool | |
| try: | |
| result, usage = self.query_function(**payload) | |
| print(f"Result: {result}") | |
| print(f"Usage: {usage}") | |
| return result | |
| except Exception as e: | |
| print(f"Error during API call: {str(e)}") | |
| return "" | |