-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetChatModel.py
More file actions
183 lines (156 loc) · 5.91 KB
/
GetChatModel.py
File metadata and controls
183 lines (156 loc) · 5.91 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import os
# from langchain_aws import Bedrock, BedrockChat
from langchain_community.chat_models import ChatOllama
from langchain_community.utilities.dalle_image_generator import (
DallEAPIWrapper)
from langchain_core.callbacks import BaseCallbackHandler
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from env_value import EnvValue
# from token_call_back import TokenCounterCallback
class GetChatModel(object):
@staticmethod
def get_ollama_cht_model(model_name: str = "phi3:mini", cache: bool = False) -> ChatOllama:
chat_model = ChatOllama(model=model_name, cache=cache)
return chat_model
@staticmethod
def get_ollama_cht_model_c(model_name: str = "phi3:mini", cache: bool = False) -> ChatOpenAI:
llm = ChatOpenAI(
api_key="ollama", # pyright: ignore [reportArgumentType]
model="mistral",
base_url="http://localhost:11434/v1",
)
return llm
@staticmethod
def get_google_model() -> ChatGoogleGenerativeAI:
key = EnvValue.get_google_ai_key()
# key = getpass.getpass(key)
os.environ["GOOGLE_API_KEY"] = key # pyright: ignore [reportArgumentType]
llm = ChatGoogleGenerativeAI(
model="gemini-2.5-flash-preview-05-20",
)
return llm
@staticmethod
def get_chat_gpt_35_model() -> ChatOpenAI:
key = EnvValue.get_open_ai_key()
# key = getpass.getpass(key)
llm = ChatOpenAI(
model="gpt-3.5-turbo",
api_key=key, # pyright: ignore [reportArgumentType]
)
return llm
@staticmethod
def get_chat_gpt_40Mini_model() -> ChatOpenAI:
key = EnvValue.get_open_ai_key()
# key = getpass.getpass(key)
llm = ChatOpenAI(
model="gpt-4o-mini",
api_key=key, # pyright: ignore [reportArgumentType]
)
return llm
@staticmethod
def get_chat_gpt_40_model() -> ChatOpenAI:
key = EnvValue.get_open_ai_key()
# key = getpass.getpass(key)
llm = ChatOpenAI(
model="gpt-4o",
api_key=key, # pyright: ignore [reportArgumentType]
)
return llm
@staticmethod
def get_chat_gpt_default_model() -> ChatOpenAI:
key = EnvValue.get_open_ai_key()
# key = getpass.getpass(key)
llm = ChatOpenAI(
# model="gpt-3.5-turbo",
api_key=key
)
return llm
# @staticmethod
# def get_dall_image_model() -> DallEAPIWrapper:
# key = EnvValue.get_open_ai_key()
# # key = getpass.getpass(key)
#
# image_generator = DallEAPIWrapper(
# model='dall-e-3',
# api_key=key,
# size='1024x1024',
# quality='hd'
# )
# return image_generator
@staticmethod
def get_open_embedding_model() -> OpenAIEmbeddings:
key = EnvValue.get_open_ai_key()
embeddings_model = OpenAIEmbeddings(
model='text-embedding-3-large',
openai_api_key=key # pyright: ignore [reportCallIssue]
)
return embeddings_model
# token_counter_use = TokenCounterCallback()
# @staticmethod
# def get_aws_model_nova_lite(tokenCallBack: TokenCounterCallback):
# # lite
# access_key = EnvValue.get_aws_access_key()
# secret_key = EnvValue.get_aws_secret_key()
#
# os.environ["AWS_ACCESS_KEY_ID"] = access_key # pyright: ignore [reportArgumentType]
# os.environ["AWS_SECRET_ACCESS_KEY"] = secret_key # pyright: ignore [reportArgumentType]
# llm = ChatBedrock( # pyright: ignore [reportCallIssue]
# # client=bedrock_client,
# model_id="us.amazon.nova-lite-v1:0", # pyright: ignore [reportCallIssue]
# # You can also use other models like "ai21.j2-ultra"
# # model_kwargs={
# # "max_tokens_to_sample": 500,
# # "temperature": 0.7,
# # }
#
# region_name='us-east-1', # pyright: ignore [reportArgumentType]
# callbacks=[tokenCallBack]
#
# )
#
# return llm
# @staticmethod
# def get_aws_model_nova_micro(tokenCallBack: TokenCounterCallback):
# # lite
# access_key = EnvValue.get_aws_access_key()
# secret_key = EnvValue.get_aws_secret_key()
#
# os.environ["AWS_ACCESS_KEY_ID"] = access_key # pyright: ignore [reportArgumentType]
# os.environ["AWS_SECRET_ACCESS_KEY"] = secret_key # pyright: ignore [reportArgumentType]
# llm = ChatBedrock( # pyright: ignore [reportCallIssue]
# # client=bedrock_client,
# model_id="us.amazon.nova-micro-v1:0", # You can also use other models like "ai21.j2-ultra"
# # model_kwargs={
# # "max_tokens_to_sample": 500,
# # "temperature": 0.7,
# # }
#
# region_name='us-east-1',
# callbacks=[tokenCallBack]
#
# )
#
# return llm
# @staticmethod
# def get_aws_model_nova_pro(tokenCallBack: TokenCounterCallback):
# # lite
# access_key = EnvValue.get_aws_access_key()
# secret_key = EnvValue.get_aws_secret_key()
#
# os.environ["AWS_ACCESS_KEY_ID"] = access_key # pyright: ignore [reportArgumentType]
# os.environ["AWS_SECRET_ACCESS_KEY"] = secret_key # pyright: ignore [reportArgumentType]
# llm = ChatBedrock( # pyright: ignore [reportCallIssue]
# # client=bedrock_client,
# model_id="us.amazon.nova-pro-v1:0", # You can also use other models like "ai21.j2-ultra"
# # model_kwargs={
# # "max_tokens_to_sample": 500,
# # "temperature": 0.7,
# # }
#
# region_name='us-east-1',
# callbacks=[tokenCallBack]
#
# )
#
# return llm