OverviewFilesCommitsIssuesDocsReleasesPeers

ollama_semantic_function_calling commits / 54d3e3b

Add fallback MatrixConfig implementation for when ollamatools is not available
54d3e3ba399812ec310580992c055715a129d710
by fleeky.ashatron <fleeky@7rnx.net> · 2025-04-19T23:44:21.000Z

Changed files (1) +99 -0

ollamatools-new/matrix_cmd/matrix_client.py +99 -0
……@@ -84,6 +84,105 @@ except ImportError:
8484 )
8585 sys.exit(1)
8686 OLLAMATOOLS_AVAILABLE = False
87
88 # Define MatrixConfig for fallback
89 class MatrixConfig:
90 """
91 Configuration handler for Matrix integration.
92 """
93
94 @staticmethod
95 def load_config(config_path: str) -> Dict:
96 """
97 Load configuration from a YAML file.
98
99 Args:
100 config_path: Path to the configuration file
101
102 Returns:
103 Dict: The configuration as a dictionary
104 """
105 try:
106 with open(config_path, 'r') as f:
107 config = yaml.safe_load(f)
108
109 logger.info(f"Loaded configuration from {config_path}")
110 return config
111
112 except Exception as e:
113 logger.error(f"Error loading configuration from {config_path}: {e}")
114 raise
115
116 @staticmethod
117 def save_config(config: Dict, config_path: str) -> None:
118 """
119 Save configuration to a YAML file.
120
121 Args:
122 config: The configuration as a dictionary
123 config_path: Path to save the configuration to
124 """
125 try:
126 # Create directory if it doesn't exist
127 os.makedirs(os.path.dirname(config_path), exist_ok=True)
128
129 with open(config_path, 'w') as f:
130 yaml.dump(config, f, default_flow_style=False)
131
132 logger.info(f"Saved configuration to {config_path}")
133
134 except Exception as e:
135 logger.error(f"Error saving configuration to {config_path}: {e}")
136 raise
137
138 @staticmethod
139 def create_default_config() -> Dict:
140 """
141 Create a default configuration.
142
143 Returns:
144 Dict: The default configuration
145 """
146 return {
147 "MATRIX": {
148 "HOMESERVER": "https://matrix.example.org",
149 "USER": "@user:example.org",
150 "PASSWORD": "your-password",
151 "DEVICE_ID": "matrix-cmd-agent",
152 "ROOMS": [
153 "#room:example.org"
154 ],
155 "ADMIN_USERS": [
156 "@admin:example.org"
157 ]
158 },
159 "OLLAMA": {
160 "HOST": "localhost:11434",
161 "MODEL": "llama3:latest",
162 "PROMPT": "You are a helpful assistant.",
163 "AVAILABLE_MODELS": [
164 "llama3:latest",
165 "mistral:latest",
166 "gemma:latest"
167 ]
168 },
169 "ENHANCED": {
170 "ENABLE_SEARCH": False,
171 "ENABLE_CONVERSATION_TRACKING": False,
172 "HISTORY_FILE": "~/.config/matrix-cmd/history.json",
173 "MAX_CONVERSATION_HISTORY": 100,
174 "RESPOND_TO_ALL_MESSAGES": False,
175 "OPENSEARCH": {
176 "BASE_URL": "http://localhost:8081",
177 "ENGINES": [
178 "google",
179 "bing",
180 "duckduckgo"
181 ],
182 "NUM_RESULTS": 5
183 }
184 }
185 }
87186
88187# Make ollama import optional
89188try: