File size: 1,956 Bytes
2faedff
1c0a23b
 
a2558c3
2faedff
a2558c3
2faedff
1c0a23b
240ad82
 
a2558c3
b29a8c2
2faedff
1c0a23b
240ad82
b29a8c2
240ad82
b29a8c2
240ad82
 
b29a8c2
 
6861834
240ad82
 
a2558c3
 
2faedff
 
 
 
 
 
 
 
 
1c0a23b
240ad82
b29a8c2
1c0a23b
240ad82
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
from langchain_openai import OpenAI
from langchain_anthropic import ChatAnthropic
from helpers.import_envs import openai_api_key, anthropic_api_key, huggingface_token
from langchain_openai import ChatOpenAI 
from transformers.pipelines import pipeline
# from langchain_community.llms.openllm import OpenLLM

GPT3 = "gpt-3.5"
GPT4 = "gpt-4o"
LLAMA3 = "meta-llama/Meta-Llama-3-8B"
ANTHROPIC2 = "Claude-2.1"
MISTRAL = "mistralai/Mistral-7B-Instruct-v0.3"

def _set_llm_based_on_choice(choice):
    if choice == GPT3:
        model_name = "gpt-3.5-turbo"
        llm = ChatOpenAI(model=model_name, temperature=0, api_key=openai_api_key)
    elif choice == GPT4:
        model_name = "gpt-4o"
        llm = ChatOpenAI(model=model_name, temperature=0, api_key=openai_api_key)
    elif choice == ANTHROPIC2:
        model_name = "claude-2.1"
        llm = ChatAnthropic(model_name=model_name, anthropic_api_key=anthropic_api_key)
    elif choice == LLAMA3:
        model_name = LLAMA3
        llm = pipeline("text-generation", model=model_name, token=huggingface_token)
    # elif choice == MISTRAL:
    #     runpod_endpoint = "https://api.runpod.ai/v2/q67259l60h6adh/openai/v1"
    #     runpod_api_key = os.getenv("RUNPOD_API_KEY")
    #     gen_kwargs = {
    #         "temperature": 0,
    #         "api_key": runpod_api_key
    #     }
    #     server_url = runpod_endpoint  # Replace with remote host if you are running on a remote server
    #     llm = OpenLLM(server_url=server_url, model_name=MISTRAL, llm_kwargs=gen_kwargs) 
    else:
        model_name = "gpt-3.5-turbo"
        llm = ChatOpenAI(model=model_name, temperature=0, api_key=openai_api_key)
    return llm

def set_summarization_llm(choice = None):
    return _set_llm_based_on_choice(choice)

def set_sentiment_analysis_llm(choice = None):
    return _set_llm_based_on_choice(choice)

def set_question_answer_llm(choice = None):
    return _set_llm_based_on_choice(choice)