KholoudLIA commited on
Commit
6d508c3
·
verified ·
1 Parent(s): 1fd7dc8

Upload models_configuration.py

Browse files
Files changed (1) hide show
  1. models_configuration.py +63 -0
models_configuration.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any, List, Dict, Optional
2
+ from langchain_community.chat_models import ChatOllama
3
+ from langchain_core.messages import HumanMessage, AIMessage, SystemMessage
4
+
5
+ model_configurations: Dict[str, Dict[str, Any]] = {
6
+ "qwen3:32b": {
7
+ "type": "Ollama",
8
+ "model_name": "qwen3:32b",
9
+ "temperature": 0.3,
10
+ },
11
+ "mistral-small:24b": {
12
+ "type": "Ollama",
13
+ "model_name": "mistral-small:24b",
14
+ "temperature": 0.3,
15
+ },
16
+ "deepseek-r1:32b": {
17
+ "type": "Ollama",
18
+ "model_name": "deepseek-r1:32b",
19
+ "temperature": 0.3,
20
+ }
21
+ }
22
+
23
+ class OllamaWithDebug(ChatOllama):
24
+ def __init__(self, model, **kwargs):
25
+ super().__init__(model=model, **kwargs)
26
+ print(f"--- DEBUG INIT: Model {model} ---")
27
+ print(f"Injected parameters: {kwargs}")
28
+ print("Actual instance attributes:")
29
+ for attr in ['temperature', 'top_p', 'base_url']:
30
+ print(f" - {attr}: {getattr(self, attr, 'UNDEFINED')}")
31
+ print("-" * 40)
32
+
33
+ def invoke(self, messages: Any, **kwargs):
34
+ print(f"\n[DEBUG INVOKE] Sending to {self.model}")
35
+ temp = getattr(self, 'temperature', 'N/A')
36
+ print(f"Active config -> Temp: {temp}")
37
+
38
+ preview = str(messages)[:150]
39
+ print(f"Input preview: {preview}...")
40
+
41
+ try:
42
+ response = super().invoke(messages, **kwargs)
43
+ print(f"[DEBUG RESPONSE] Success! Response length: {len(str(response.content))} chars")
44
+ return response
45
+
46
+ except Exception as e:
47
+ print(f"!!! DEBUG ERROR !!! Ollama call failed: {e}")
48
+ raise
49
+
50
+ def get_model_instance(model_key: str) -> Any:
51
+ config = model_configurations.get(model_key)
52
+ if config is None:
53
+ raise ValueError(f"Model not configured: {model_key}")
54
+
55
+ if config.get("type", "").lower() == "ollama":
56
+ return OllamaWithDebug(
57
+ model=config["model_name"],
58
+ base_url="http://localhost:11434",
59
+ temperature=config.get("temperature", 0.3),
60
+ top_p=config.get("top_p"),
61
+ )
62
+ else:
63
+ raise ValueError(f"Unsupported or missing model type: {config.get('type')}")