1- import sqlite3
21import os
32import json
43import argparse
@@ -9,94 +8,29 @@ def create_settings(ci_mode=False):
98 if ci_mode :
109 # Use default values for CI
1110 api_key = "sk-test-key"
12- tier = "tier-4"
1311 log_path = './var/logs/error.log'
14- database_path = './var/data/agents.db'
12+ debug = False
1513 else :
1614 # Prompt user for settings
1715 api_key = input ('Enter your OpenAI API key: ' )
18- tier = input ('Enter your OpenAI tier level (e.g., tier-1): ' )
1916 log_path = input ('Enter the log directory path [default: ./var/logs/error.log]: ' ) or './var/logs/error.log'
20- database_path = input ('Enter the database path [default: ./var/data/agents.db ]: ' ) or './var/data/agents.db '
17+ debug = input ('Enable debug mode? [y/n ]: ' ). lower () == 'y '
2118
2219 # Save settings to JSON file
2320 settings = {
2421 'openai_api_key' : api_key ,
25- 'tier' : tier ,
2622 'log_path' : log_path ,
27- 'database_path ' : database_path
23+ 'debug ' : debug
2824 }
2925 os .makedirs ('./config' , exist_ok = True )
3026 with open ('./config/settings.json' , 'w' ) as f :
3127 json .dump (settings , f , indent = 4 )
3228 print ('Settings saved to config/settings.json' )
3329
3430
35- # Function to create the database structure
36-
37- def create_database (db_path ):
38- os .makedirs (os .path .dirname (db_path ), exist_ok = True )
39- conn = sqlite3 .connect (db_path )
40- c = conn .cursor ()
41-
42- # Create tables
43- c .execute ('''CREATE TABLE IF NOT EXISTS models (
44- id INTEGER PRIMARY KEY,
45- model TEXT NOT NULL,
46- price_per_prompt_token REAL NOT NULL,
47- price_per_completion_token REAL NOT NULL)''' )
48-
49- c .execute ('''CREATE TABLE IF NOT EXISTS rate_limits (
50- id INTEGER PRIMARY KEY,
51- model TEXT NOT NULL,
52- tier TEXT NOT NULL,
53- rpm_limit INTEGER NOT NULL,
54- tpm_limit INTEGER NOT NULL,
55- rpd_limit INTEGER NOT NULL)''' )
56-
57- c .execute ('''CREATE TABLE IF NOT EXISTS api_usage (
58- id INTEGER PRIMARY KEY,
59- timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
60- session_id TEXT NOT NULL,
61- model TEXT NOT NULL,
62- prompt_tokens INTEGER NOT NULL,
63- completion_tokens INTEGER NOT NULL,
64- total_tokens INTEGER NOT NULL,
65- price_per_prompt_token REAL NOT NULL,
66- price_per_completion_token REAL NOT NULL,
67- total_cost REAL NOT NULL)''' )
68-
69- c .execute ('''CREATE TABLE IF NOT EXISTS chat_sessions (
70- id INTEGER PRIMARY KEY,
71- session_id TEXT NOT NULL,
72- start_time DATETIME DEFAULT CURRENT_TIMESTAMP,
73- end_time DATETIME)''' )
74-
75- c .execute ('''CREATE TABLE IF NOT EXISTS chats (
76- id INTEGER PRIMARY KEY,
77- session_id TEXT NOT NULL,
78- chat_id TEXT NOT NULL,
79- message TEXT NOT NULL,
80- role TEXT NOT NULL,
81- timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)''' )
82-
83- # Insert default models and rate limits
84- c .execute ("INSERT INTO models (model, price_per_prompt_token, price_per_completion_token) VALUES ('gpt-4o-mini', 0.03, 0.06)" )
85- c .execute ("INSERT INTO rate_limits (model, tier, rpm_limit, tpm_limit, rpd_limit) VALUES ('gpt-4o-mini', 'tier-1', 60, 50000, 1000)" )
86-
87- conn .commit ()
88- conn .close ()
89- print (f"Database created at { db_path } " )
90-
91-
9231if __name__ == '__main__' :
9332 parser = argparse .ArgumentParser (description = 'Setup script for installation.' )
9433 parser .add_argument ('--ci' , action = 'store_true' , help = 'Use default values for CI without prompting.' )
9534 args = parser .parse_args ()
9635
9736 create_settings (ci_mode = args .ci )
98-
99- with open ('./config/settings.json' , 'r' ) as f :
100- settings = json .load (f )
101-
102- create_database (settings ['database_path' ])
0 commit comments