Customers commited on
Commit
c264ca1
·
verified ·
1 Parent(s): 5deed68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -26
app.py CHANGED
@@ -1940,22 +1940,13 @@ HF_TOKEN = os.getenv("HF_TOKEN") or get_token("HF_TOKEN")
1940
  if HF_TOKEN:
1941
  login(token=HF_TOKEN)
1942
 
1943
- def get_inference_client():
1944
- """Get inference client with multiple fallback options"""
1945
- fallback_models = [
1946
- "microsoft/Phi-3-mini-4k-instruct", # Primary fallback
1947
- "microsoft/Phi-3.5-mini-instruct",
1948
- "mistralai/Mistral-7B-Instruct-v0.3",
1949
- "meta-llama/Llama-3.1-8B-Instruct",
1950
- "meta-llama/Llama-3.2-3B-Instruct",
1951
- "HuggingFaceH4/zephyr-7b-beta"
1952
- ]
1953
 
 
1954
  try:
1955
- # First try to get assigned LLM from spreadsheet
1956
  GAS_URL = "https://script.google.com/macros/s/AKfycbxnUdGOmaNwH5IEnjNZOnWxBVqbHimJxIH1EMjoVDJ4n8rkteDW-51DmPUKoY_3al-SWQ/exec"
1957
  email = OWNER_EMAIL
1958
 
 
1959
  response = requests.get(f"{GAS_URL}?email={email}")
1960
  data = response.json()
1961
 
@@ -1978,21 +1969,9 @@ def get_inference_client():
1978
  except Exception as e:
1979
  print(f"Error from fallback GAS endpoint: {str(e)}")
1980
 
1981
- # Try each fallback model in order until one works
1982
- for model in fallback_models:
1983
- try:
1984
- client = InferenceClient(model)
1985
- # Test the client with a small request
1986
- test_response = client.text_generation("Hello", max_new_tokens=1)
1987
- print(f"✅ Successfully connected to Default LLM: {model}")
1988
- return client
1989
- except Exception as e:
1990
- print(f"❌ Failed to connect to {model}: {str(e)}")
1991
- continue
1992
-
1993
- # If all else fails, use the first fallback and let it error
1994
- print("⚠️ All fallbacks failed, using primary fallback (may not work)")
1995
- return InferenceClient(fallback_models[0])
1996
 
1997
  # Replace the client initialization
1998
  client = get_inference_client()
 
1940
  if HF_TOKEN:
1941
  login(token=HF_TOKEN)
1942
 
 
 
 
 
 
 
 
 
 
 
1943
 
1944
+ def get_inference_client():
1945
  try:
 
1946
  GAS_URL = "https://script.google.com/macros/s/AKfycbxnUdGOmaNwH5IEnjNZOnWxBVqbHimJxIH1EMjoVDJ4n8rkteDW-51DmPUKoY_3al-SWQ/exec"
1947
  email = OWNER_EMAIL
1948
 
1949
+ # First try to get assigned LLM from spreadsheet
1950
  response = requests.get(f"{GAS_URL}?email={email}")
1951
  data = response.json()
1952
 
 
1969
  except Exception as e:
1970
  print(f"Error from fallback GAS endpoint: {str(e)}")
1971
 
1972
+ # Final fallback to default model , others microsoft/Phi-3-mini-4k-instruct, microsoft/Phi-3.5-mini-instruct,
1973
+ #mistralai/Mistral-7B-Instruct-v0.3, meta-llama/Llama-3.1-8B-Instruct, meta-llama/Llama-3.2-3B-Instruct, HuggingFaceH4/zephyr-7b-beta
1974
+ return InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
 
 
 
 
 
 
 
 
 
 
 
 
1975
 
1976
  # Replace the client initialization
1977
  client = get_inference_client()