Spaces:
Sleeping
Sleeping
import os | |
def get_openai_chat_model(API_key): | |
try: | |
from langchain.llms import OpenAI | |
except ImportError as err: | |
raise "{}, unable to load openAI. Please install openai and add OPENAIAPI_KEY" | |
os.environ["OPENAI_API_KEY"] = API_key | |
llm = OpenAI() | |
return llm | |
def get_hugging_face_model(model_id,API_key,temperature=0.1,max_tokens=4096): | |
try: | |
from langchain import HuggingFaceHub | |
except ImportError as err: | |
raise "{}, unable to load openAI. Please install openai and add OPENAIAPI_KEY" | |
chat_llm = HuggingFaceHub(huggingfacehub_api_token=API_key, | |
repo_id=model_id, | |
model_kwargs={"temperature": temperature, "max_new_tokens": max_tokens}) | |
return chat_llm | |