Skip to content

Commit 242e417

Browse files
authored
Add files via upload
1 parent 297b9fe commit 242e417

File tree

17 files changed

+1176
-0
lines changed

17 files changed

+1176
-0
lines changed

frontend/config/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__init__.py
2+
from .settings import Settings
3+
4+
__all__ = ['Settings']

frontend/config/settings.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# config/settings.py
2+
import json
3+
import os
4+
5+
class Settings:
6+
def __init__(self):
7+
self.config_file = 'config/config.json'
8+
self.default_settings = {
9+
'api_base': 'http://localhost:11434/api',
10+
'default_model': 'llama2-3.2-vision:latest',
11+
'temperature': 0.7,
12+
'max_tokens': 2000,
13+
'db_path': 'data/ollama_gui.db',
14+
'rag_settings': {
15+
'chunk_size': 1000,
16+
'chunk_overlap': 200,
17+
'similarity_threshold': 0.7
18+
}
19+
}
20+
self.current_settings = self.load_settings()
21+
22+
def load_settings(self):
23+
if os.path.exists(self.config_file):
24+
with open(self.config_file, 'r') as f:
25+
return json.load(f)
26+
return self.default_settings.copy()
27+
28+
def save_settings(self):
29+
os.makedirs(os.path.dirname(self.config_file), exist_ok=True)
30+
with open(self.config_file, 'w') as f:
31+
json.dump(self.current_settings, f, indent=4)

frontend/database/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .db_manager import DatabaseManager
2+
3+
__all__ = ['DatabaseManager']

frontend/database/db_manager.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# database/db_manager.py
2+
import sqlite3
3+
from datetime import datetime
4+
5+
class DatabaseManager:
6+
def add_interaction_metrics(self, model_name, prompt, response, tokens_used, response_time, success_rate):
7+
with sqlite3.connect(self.db_path) as conn:
8+
cursor = conn.cursor()
9+
cursor.execute('''
10+
INSERT INTO model_metrics
11+
(timestamp, model_name, prompt_length, response_length, tokens_used,
12+
response_time, success_rate)
13+
VALUES (?, ?, ?, ?, ?, ?, ?)
14+
''', (
15+
datetime.now(), model_name, len(prompt), len(response),
16+
tokens_used, response_time, success_rate
17+
))
18+
19+
def init_database(self):
20+
with sqlite3.connect(self.db_path) as conn:
21+
cursor = conn.cursor()
22+
23+
# Create tables
24+
cursor.execute('''
25+
CREATE TABLE IF NOT EXISTS chat_history (
26+
id INTEGER PRIMARY KEY,
27+
timestamp DATETIME,
28+
model TEXT,
29+
message TEXT,
30+
response TEXT,
31+
tokens INTEGER,
32+
response_time FLOAT
33+
)
34+
''')
35+
36+
cursor.execute('''
37+
CREATE TABLE IF NOT EXISTS model_metrics (
38+
id INTEGER PRIMARY KEY,
39+
model TEXT,
40+
date DATE,
41+
total_tokens INTEGER,
42+
avg_response_time FLOAT,
43+
total_conversations INTEGER
44+
)
45+
''')
46+
47+
conn.commit()
48+
49+
def add_chat_entry(self, model, message, response, tokens, response_time):
50+
with sqlite3.connect(self.db_path) as conn:
51+
cursor = conn.cursor()
52+
cursor.execute('''
53+
INSERT INTO chat_history (timestamp, model, message, response, tokens, response_time)
54+
VALUES (?, ?, ?, ?, ?, ?)
55+
''', (datetime.now(), model, message, response, tokens, response_time))
56+
conn.commit()

frontend/gui/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .app_window import OllamaGUI
2+
3+
__all__ = ['OllamaGUI']

frontend/gui/app_window.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import tkinter as tk
2+
from tkinter import ttk
3+
from .frames.model_frame import ModelFrame
4+
from .frames.chat_frame import ChatFrame
5+
from .frames.control_frame import ControlFrame
6+
7+
class OllamaGUI:
8+
def __init__(self, root):
9+
self.root = root
10+
self.root.title("Ollama Chat Interface")
11+
self.root.geometry("1200x800")
12+
13+
# Initialize main container
14+
self.main_container = ttk.PanedWindow(root, orient=tk.HORIZONTAL)
15+
self.main_container.pack(fill=tk.BOTH, expand=True)
16+
17+
# Create frames
18+
self.model_frame = ModelFrame(self.main_container, self) # Pass self as controller
19+
self.main_container.add(self.model_frame)
20+
21+
# Create right pane
22+
self.right_pane = ttk.PanedWindow(self.main_container, orient=tk.VERTICAL)
23+
self.main_container.add(self.right_pane)
24+
25+
self.chat_frame = ChatFrame(self.right_pane, self) # Pass self as controller
26+
self.right_pane.add(self.chat_frame)
27+
28+
self.control_frame = ControlFrame(self.right_pane, self) # Pass self as controller
29+
self.right_pane.add(self.control_frame)

frontend/gui/frames/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .chat_frame import ChatFrame
2+
from .model_frame import ModelFrame
3+
from .control_frame import ControlFrame

0 commit comments

Comments
 (0)