26
26
embeddings as google_embeddings ,
27
27
)
28
28
from langchain_mistralai import ChatMistralAI
29
+
29
30
# from pydantic.v1.types import SecretStr
30
31
from python .helpers import dotenv , runtime
31
32
from python .helpers .dotenv import load_dotenv
34
35
# environment variables
35
36
load_dotenv ()
36
37
37
- # Configuration
38
- DEFAULT_TEMPERATURE = 0.0
39
-
40
38
41
39
class ModelType (Enum ):
42
40
CHAT = "Chat"
@@ -110,7 +108,6 @@ def get_ollama_base_url():
110
108
111
109
def get_ollama_chat (
112
110
model_name : str ,
113
- temperature = DEFAULT_TEMPERATURE ,
114
111
base_url = None ,
115
112
num_ctx = 8192 ,
116
113
** kwargs ,
@@ -119,7 +116,6 @@ def get_ollama_chat(
119
116
base_url = get_ollama_base_url ()
120
117
return ChatOllama (
121
118
model = model_name ,
122
- temperature = temperature ,
123
119
base_url = base_url ,
124
120
num_ctx = num_ctx ,
125
121
** kwargs ,
@@ -128,22 +124,21 @@ def get_ollama_chat(
128
124
129
125
def get_ollama_embedding (
130
126
model_name : str ,
131
- temperature = DEFAULT_TEMPERATURE ,
132
127
base_url = None ,
128
+ num_ctx = 8192 ,
133
129
** kwargs ,
134
130
):
135
131
if not base_url :
136
132
base_url = get_ollama_base_url ()
137
133
return OllamaEmbeddings (
138
- model = model_name , temperature = temperature , base_url = base_url , ** kwargs
134
+ model = model_name , base_url = base_url , num_ctx = num_ctx , ** kwargs
139
135
)
140
136
141
137
142
138
# HuggingFace models
143
139
def get_huggingface_chat (
144
140
model_name : str ,
145
141
api_key = None ,
146
- temperature = DEFAULT_TEMPERATURE ,
147
142
** kwargs ,
148
143
):
149
144
# different naming convention here
@@ -155,7 +150,6 @@ def get_huggingface_chat(
155
150
repo_id = model_name ,
156
151
task = "text-generation" ,
157
152
do_sample = True ,
158
- temperature = temperature ,
159
153
** kwargs ,
160
154
)
161
155
@@ -177,13 +171,12 @@ def get_lmstudio_base_url():
177
171
178
172
def get_lmstudio_chat (
179
173
model_name : str ,
180
- temperature = DEFAULT_TEMPERATURE ,
181
174
base_url = None ,
182
175
** kwargs ,
183
176
):
184
177
if not base_url :
185
178
base_url = get_lmstudio_base_url ()
186
- return ChatOpenAI (model_name = model_name , base_url = base_url , temperature = temperature , api_key = "none" , ** kwargs ) # type: ignore
179
+ return ChatOpenAI (model_name = model_name , base_url = base_url , api_key = "none" , ** kwargs ) # type: ignore
187
180
188
181
189
182
def get_lmstudio_embedding (
@@ -200,12 +193,16 @@ def get_lmstudio_embedding(
200
193
def get_anthropic_chat (
201
194
model_name : str ,
202
195
api_key = None ,
203
- temperature = DEFAULT_TEMPERATURE ,
196
+ base_url = None ,
204
197
** kwargs ,
205
198
):
206
199
if not api_key :
207
200
api_key = get_api_key ("anthropic" )
208
- return ChatAnthropic (model_name = model_name , temperature = temperature , api_key = api_key , ** kwargs ) # type: ignore
201
+ if not base_url :
202
+ base_url = (
203
+ dotenv .get_dotenv_value ("ANTHROPIC_BASE_URL" ) or "https://api.anthropic.com"
204
+ )
205
+ return ChatAnthropic (model_name = model_name , api_key = api_key , base_url = base_url , ** kwargs ) # type: ignore
209
206
210
207
211
208
# right now anthropic does not have embedding models, but that might change
@@ -223,12 +220,11 @@ def get_anthropic_embedding(
223
220
def get_openai_chat (
224
221
model_name : str ,
225
222
api_key = None ,
226
- temperature = DEFAULT_TEMPERATURE ,
227
223
** kwargs ,
228
224
):
229
225
if not api_key :
230
226
api_key = get_api_key ("openai" )
231
- return ChatOpenAI (model_name = model_name , temperature = temperature , api_key = api_key , ** kwargs ) # type: ignore
227
+ return ChatOpenAI (model_name = model_name , api_key = api_key , ** kwargs ) # type: ignore
232
228
233
229
234
230
def get_openai_embedding (model_name : str , api_key = None , ** kwargs ):
@@ -240,15 +236,14 @@ def get_openai_embedding(model_name: str, api_key=None, **kwargs):
240
236
def get_openai_azure_chat (
241
237
deployment_name : str ,
242
238
api_key = None ,
243
- temperature = DEFAULT_TEMPERATURE ,
244
239
azure_endpoint = None ,
245
240
** kwargs ,
246
241
):
247
242
if not api_key :
248
243
api_key = get_api_key ("openai_azure" )
249
244
if not azure_endpoint :
250
245
azure_endpoint = dotenv .get_dotenv_value ("OPENAI_AZURE_ENDPOINT" )
251
- return AzureChatOpenAI (deployment_name = deployment_name , temperature = temperature , api_key = api_key , azure_endpoint = azure_endpoint , ** kwargs ) # type: ignore
246
+ return AzureChatOpenAI (deployment_name = deployment_name , api_key = api_key , azure_endpoint = azure_endpoint , ** kwargs ) # type: ignore
252
247
253
248
254
249
def get_openai_azure_embedding (
@@ -268,12 +263,11 @@ def get_openai_azure_embedding(
268
263
def get_google_chat (
269
264
model_name : str ,
270
265
api_key = None ,
271
- temperature = DEFAULT_TEMPERATURE ,
272
266
** kwargs ,
273
267
):
274
268
if not api_key :
275
269
api_key = get_api_key ("google" )
276
- return GoogleGenerativeAI (model = model_name , temperature = temperature , google_api_key = api_key , safety_settings = {HarmCategory .HARM_CATEGORY_DANGEROUS_CONTENT : HarmBlockThreshold .BLOCK_NONE }, ** kwargs ) # type: ignore
270
+ return GoogleGenerativeAI (model = model_name , google_api_key = api_key , safety_settings = {HarmCategory .HARM_CATEGORY_DANGEROUS_CONTENT : HarmBlockThreshold .BLOCK_NONE }, ** kwargs ) # type: ignore
277
271
278
272
279
273
def get_google_embedding (
@@ -290,49 +284,48 @@ def get_google_embedding(
290
284
def get_mistralai_chat (
291
285
model_name : str ,
292
286
api_key = None ,
293
- temperature = DEFAULT_TEMPERATURE ,
294
287
** kwargs ,
295
288
):
296
289
if not api_key :
297
290
api_key = get_api_key ("mistral" )
298
- return ChatMistralAI (model = model_name , temperature = temperature , api_key = api_key , ** kwargs ) # type: ignore
291
+ return ChatMistralAI (model = model_name , api_key = api_key , ** kwargs ) # type: ignore
299
292
300
293
301
294
# Groq models
302
295
def get_groq_chat (
303
296
model_name : str ,
304
297
api_key = None ,
305
- temperature = DEFAULT_TEMPERATURE ,
306
298
** kwargs ,
307
299
):
308
300
if not api_key :
309
301
api_key = get_api_key ("groq" )
310
- return ChatGroq (model_name = model_name , temperature = temperature , api_key = api_key , ** kwargs ) # type: ignore
302
+ return ChatGroq (model_name = model_name , api_key = api_key , ** kwargs ) # type: ignore
311
303
312
304
313
305
# DeepSeek models
314
306
def get_deepseek_chat (
315
307
model_name : str ,
316
308
api_key = None ,
317
- temperature = DEFAULT_TEMPERATURE ,
318
309
base_url = None ,
319
310
** kwargs ,
320
311
):
321
312
if not api_key :
322
313
api_key = get_api_key ("deepseek" )
323
314
if not base_url :
324
315
base_url = (
325
- dotenv .get_dotenv_value ("DEEPSEEK_BASE_URL" )
326
- or "https://api.deepseek.com"
316
+ dotenv .get_dotenv_value ("DEEPSEEK_BASE_URL" ) or "https://api.deepseek.com"
327
317
)
328
- return ChatOpenAI (api_key = api_key , model = model_name , temperature = temperature , base_url = base_url , ** kwargs ) # type: ignore
329
-
318
+
319
+ model = ChatOpenAI (api_key = api_key , model = model_name , base_url = base_url , ** kwargs ) # type: ignore
320
+ # little hack for reasoning model's problem with temperature
321
+ if not "temperature" in kwargs :
322
+ model .temperature = None # type: ignore
323
+ return model
330
324
331
325
# OpenRouter models
332
326
def get_openrouter_chat (
333
327
model_name : str ,
334
328
api_key = None ,
335
- temperature = DEFAULT_TEMPERATURE ,
336
329
base_url = None ,
337
330
** kwargs ,
338
331
):
@@ -343,7 +336,7 @@ def get_openrouter_chat(
343
336
dotenv .get_dotenv_value ("OPEN_ROUTER_BASE_URL" )
344
337
or "https://openrouter.ai/api/v1"
345
338
)
346
- return ChatOpenAI (api_key = api_key , model = model_name , temperature = temperature , base_url = base_url , ** kwargs ) # type: ignore
339
+ return ChatOpenAI (api_key = api_key , model = model_name , base_url = base_url , ** kwargs ) # type: ignore
347
340
348
341
349
342
def get_openrouter_embedding (
@@ -366,7 +359,6 @@ def get_openrouter_embedding(
366
359
def get_sambanova_chat (
367
360
model_name : str ,
368
361
api_key = None ,
369
- temperature = DEFAULT_TEMPERATURE ,
370
362
base_url = None ,
371
363
max_tokens = 1024 ,
372
364
** kwargs ,
@@ -378,7 +370,7 @@ def get_sambanova_chat(
378
370
dotenv .get_dotenv_value ("SAMBANOVA_BASE_URL" )
379
371
or "https://fast-api.snova.ai/v1"
380
372
)
381
- return ChatOpenAI (api_key = api_key , model = model_name , temperature = temperature , base_url = base_url , max_tokens = max_tokens , ** kwargs ) # type: ignore
373
+ return ChatOpenAI (api_key = api_key , model = model_name , base_url = base_url , max_tokens = max_tokens , ** kwargs ) # type: ignore
382
374
383
375
384
376
# right now sambanova does not have embedding models, but that might change
@@ -402,11 +394,10 @@ def get_sambanova_embedding(
402
394
def get_other_chat (
403
395
model_name : str ,
404
396
api_key = None ,
405
- temperature = DEFAULT_TEMPERATURE ,
406
397
base_url = None ,
407
398
** kwargs ,
408
399
):
409
- return ChatOpenAI (api_key = api_key , model = model_name , temperature = temperature , base_url = base_url , ** kwargs ) # type: ignore
400
+ return ChatOpenAI (api_key = api_key , model = model_name , base_url = base_url , ** kwargs ) # type: ignore
410
401
411
402
412
403
def get_other_embedding (model_name : str , api_key = None , base_url = None , ** kwargs ):
0 commit comments