|
|
|
|
|
from huggingface_hub import InferenceClient, HfApi |
|
from tavily import TavilyClient |
|
import os |
|
|
|
|
|
HF_TOKEN = os.getenv('HF_TOKEN') |
|
if not HF_TOKEN: |
|
raise RuntimeError("HF_TOKEN environment variable is not set. Please set it to your Hugging Face API token.") |
|
|
|
def get_inference_client(model_id, provider="auto"): |
|
"""Return an InferenceClient with provider based on model_id and user selection.""" |
|
if model_id == "moonshotai/Kimi-K2-Instruct": |
|
provider = "groq" |
|
return InferenceClient( |
|
provider=provider, |
|
api_key=HF_TOKEN, |
|
bill_to="huggingface" |
|
) |
|
|
|
|
|
TAVILY_API_KEY = os.getenv('TAVILY_API_KEY') |
|
tavily_client = None |
|
if TAVILY_API_KEY: |
|
try: |
|
tavily_client = TavilyClient(api_key=TAVILY_API_KEY) |
|
except Exception as e: |
|
print(f"Failed to initialize Tavily client: {e}") |
|
tavily_client = None |
|
|