File size: 1,156 Bytes
cbf9f33
4c20612
96b76f8
 
0adaacb
96b76f8
 
 
 
0adaacb
96b76f8
 
3e19edc
96b76f8
3d99097
ad21232
 
 
3e19edc
 
ad21232
 
3e19edc
034cea3
96b76f8
 
034cea3
 
 
 
 
 
3d99097
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os

from huggingface_hub import InferenceClient, HfApi
from tavily import TavilyClient

# HF Inference Client
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"
    
    # When using a third-party provider, simply specify the provider.
    # Billing will automatically default to the account associated with the HF_TOKEN.
    # The 'bill_to' parameter is NOT needed for personal billing.
    return InferenceClient(
        provider=provider,
        api_key=HF_TOKEN
        # The `bill_to` parameter has been removed.
    )

# Tavily Search Client
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