CoolFace
Apppublic

svijayanand/Podcast_Oracle

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
model_utils.py51 linesDownload Raw Back to helpers
1import os2from langchain_openai import OpenAI3from langchain_anthropic import ChatAnthropic4from helpers.import_envs import openai_api_key, anthropic_api_key, huggingface_token5from langchain_openai import ChatOpenAI 6from transformers.pipelines import pipeline7# from langchain_community.llms.openllm import OpenLLM8 9GPT3 = "gpt-3.5"10GPT4 = "gpt-4o"11LLAMA3 = "meta-llama/Meta-Llama-3-8B"12ANTHROPIC2 = "Claude-2.1"13MISTRAL = "mistralai/Mistral-7B-Instruct-v0.3"14 15def _set_llm_based_on_choice(choice):16    if choice == GPT3:17        model_name = "gpt-3.5-turbo"18        llm = ChatOpenAI(model=model_name, temperature=0, api_key=openai_api_key)19    elif choice == GPT4:20        model_name = "gpt-4o"21        llm = ChatOpenAI(model=model_name, temperature=0, api_key=openai_api_key)22    elif choice == ANTHROPIC2:23        model_name = "claude-2.1"24        llm = ChatAnthropic(model_name=model_name, anthropic_api_key=anthropic_api_key)25    elif choice == LLAMA3:26        model_name = LLAMA327        llm = pipeline("text-generation", model=model_name, token=huggingface_token)28    # elif choice == MISTRAL:29    #     runpod_endpoint = "https://api.runpod.ai/v2/q67259l60h6adh/openai/v1"30    #     runpod_api_key = os.getenv("RUNPOD_API_KEY")31    #     gen_kwargs = {32    #         "temperature": 0,33    #         "api_key": runpod_api_key34    #     }35    #     server_url = runpod_endpoint  # Replace with remote host if you are running on a remote server36    #     llm = OpenLLM(server_url=server_url, model_name=MISTRAL, llm_kwargs=gen_kwargs) 37    else:38        model_name = "gpt-3.5-turbo"39        llm = ChatOpenAI(model=model_name, temperature=0, api_key=openai_api_key)40    return llm41 42def set_summarization_llm(choice = None):43    return _set_llm_based_on_choice(choice)44 45def set_sentiment_analysis_llm(choice = None):46    return _set_llm_based_on_choice(choice)47 48def set_question_answer_llm(choice = None):49    return _set_llm_based_on_choice(choice)50 51