Spaces:
Sleeping
Sleeping
File size: 797 Bytes
2faf743 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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
|