mgbam commited on
Commit
3e19edc
·
verified ·
1 Parent(s): 769d10e

Create hf_client.py

Browse files
Files changed (1) hide show
  1. hf_client.py +32 -0
hf_client.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+
4
+ ### hf_client.py
5
+ ```python
6
+ from huggingface_hub import InferenceClient, HfApi
7
+ from tavily import TavilyClient
8
+
9
+ # HF Inference Client
10
+ HF_TOKEN = os.getenv('HF_TOKEN')
11
+ if not HF_TOKEN:
12
+ raise RuntimeError("HF_TOKEN environment variable is not set. Please set it to your Hugging Face API token.")
13
+
14
+ def get_inference_client(model_id, provider="auto"):
15
+ """Return an InferenceClient with provider based on model_id and user selection."""
16
+ if model_id == "moonshotai/Kimi-K2-Instruct":
17
+ provider = "groq"
18
+ return InferenceClient(
19
+ provider=provider,
20
+ api_key=HF_TOKEN,
21
+ bill_to="huggingface"
22
+ )
23
+
24
+ # Tavily Search Client
25
+ TAVILY_API_KEY = os.getenv('TAVILY_API_KEY')
26
+ tavily_client = None
27
+ if TAVILY_API_KEY:
28
+ try:
29
+ tavily_client = TavilyClient(api_key=TAVILY_API_KEY)
30
+ except Exception as e:
31
+ print(f"Failed to initialize Tavily client: {e}")
32
+ tavily_client = None