Spaces:
Runtime error
Runtime error
File size: 1,010 Bytes
5553e22 a9485fb 5553e22 5be2189 5553e22 a9485fb b929932 58295d1 5553e22 5be2189 58295d1 5be2189 58295d1 d9f3c04 5be2189 5553e22 5be2189 |
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 34 35 36 37 38 |
import os
import streamlit as st
from langchain_community.llms import HuggingFaceEndpoint
from pydantic import ValidationError
st.write(
"Has environment variables been set:",
os.environ["HUGGINGFACE_API_TOKEN"] == st.secrets["HUGGINGFACE_API_TOKEN"])
def load_llm(repo_id="mistralai/Mistral-7B-Instruct-v0.2"):
'''
Load the LLM from the HuggingFace model hub
Args:
repo_id (str): The HuggingFace model ID
Returns:
llm (HuggingFaceEndpoint): The LLM model
'''
try:
secret_token = os.getenv("HUGGINGFACE_API_TOKEN")
llm = HuggingFaceEndpoint(
repo_id=repo_id,
model_kwargs={"max_length": 128},
api_token=secret_token
)
return llm
except ValidationError as e:
print("Validation Error:", e)
# Log or handle the validation error appropriately
return None
except Exception as e:
print("Error:", e)
# Log or handle other exceptions
return None
|