forked from sausheong/ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
86 lines (80 loc) · 2.83 KB
/
models.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from langchain.chat_models import AzureChatOpenAI, ChatVertexAI, ChatOpenAI
from langchain.llms import OpenAI, AzureOpenAI, VertexAI
from langchain.embeddings import OpenAIEmbeddings, VertexAIEmbeddings
from config import retries
from config import provider_config as cfg
from custom import Llama2API
def get_provider_model():
llm = None
# OpenAI
if cfg.provider == "openai":
if cfg.model_name.startswith("gpt-4") or cfg.model_name.startswith("gpt-3.5"):
llm = ChatOpenAI(
temperature=0.7,
model_name=cfg.model_name,
openai_api_key=cfg.api_key,
max_retries=retries,
)
else:
llm = OpenAI(
temperature=0.7,
model_name=cfg.model_name,
openai_api_key=cfg.api_key,
max_retries=retries,
)
embeddings = OpenAIEmbeddings(
openai_api_key=cfg.api_key,
)
# Azure OpenAI
if cfg.provider == "azure":
if cfg.model_name.startswith("gpt-4") or cfg.model_name.startswith("gpt-3.5"):
llm = AzureChatOpenAI(
temperature=0.7,
openai_api_base=cfg.base_url,
openai_api_version=cfg.api_version,
model_name=cfg.model_name,
deployment_name=cfg.deployment_name,
openai_api_key=cfg.api_key,
max_retries=retries,
openai_api_type="azure",
)
else:
llm = AzureOpenAI(
temperature=0.7,
openai_api_base=cfg.base_url,
openai_api_version=cfg.api_version,
model_name=cfg.model_name,
deployment_name=cfg.deployment_name,
openai_api_key=cfg.api_key,
max_retries=retries,
openai_api_type="azure",
)
embeddings = OpenAIEmbeddings(
openai_api_key=cfg.api_key,
)
# Google Vertex AI (PaLM)
if cfg.provider == "palm":
if cfg.model_name == "chat-bison" or cfg.model_name == "codechat-bison":
llm = ChatVertexAI(
temperature=0.7,
model_name=cfg.model_name,
location=cfg.location,
max_output_tokens=1024,
)
else:
llm = VertexAI(
temperature=0.7,
model_name=cfg.model_name,
location=cfg.location,
max_output_tokens=1024,
)
embeddings = VertexAIEmbeddings()
if cfg.provider == "llama2api":
llm = Llama2API(
temperature=0.7,
max_output_tokens=1024,
base_url=cfg.base_url,
api_key=cfg.api_key,
)
embeddings = OpenAIEmbeddings()
return llm, embeddings