-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinydb_cleanup.py
167 lines (132 loc) · 5.47 KB
/
tinydb_cleanup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# import json
# from tinydb import TinyDB, Query
# # Path to your existing database
# DB_PATH = "writers_toolkit.json"
# # Claude API parameter names to look for in tool options
# CLAUDE_API_PARAMS = [
# '--request_timeout',
# '--max_retries',
# '--context_window',
# '--betas_max_tokens',
# '--thinking_budget_tokens',
# '--thinking_budget',
# '--desired_output_tokens',
# '--max_tokens'
# ]
# # Parameter name mapping to standardized keys
# PARAM_MAPPING = {
# '--request_timeout': 'request_timeout',
# '--max_retries': 'max_retries',
# '--context_window': 'context_window',
# '--betas_max_tokens': 'betas_max_tokens',
# '--thinking_budget_tokens': 'thinking_budget_tokens',
# '--thinking_budget': 'thinking_budget_tokens',
# '--desired_output_tokens': 'desired_output_tokens',
# '--max_tokens': 'desired_output_tokens'
# }
# # Default Claude API settings
# DEFAULT_CLAUDE_API_SETTINGS = {
# "request_timeout": 300,
# "max_retries": 1,
# "context_window": 200000,
# "betas_max_tokens": 128000,
# "thinking_budget_tokens": 32000,
# "desired_output_tokens": 8000
# }
# def main():
# # Open the database
# db = TinyDB(DB_PATH)
# tools_table = db.table('tools')
# # Create new claude_api table
# claude_api_table = db.table('claude_api')
# # Dictionary to hold consolidated Claude API settings
# consolidated_settings = {}
# # Extract settings from all tools
# for tool in tools_table.all():
# if 'options' in tool:
# for option in tool['options']:
# param_name = option.get('name')
# if param_name in CLAUDE_API_PARAMS:
# # Get standardized key name
# key = PARAM_MAPPING.get(param_name)
# # Get value if it exists
# default_value = option.get('default')
# # Only store non-None values
# if default_value is not None:
# # If we have multiple values for the same parameter, take the latest
# consolidated_settings[key] = default_value
# # If we didn't find any settings, use defaults
# if not consolidated_settings:
# consolidated_settings = DEFAULT_CLAUDE_API_SETTINGS
# else:
# # Fill in any missing settings with defaults
# for key, value in DEFAULT_CLAUDE_API_SETTINGS.items():
# if key not in consolidated_settings:
# consolidated_settings[key] = value
# # Save consolidated settings to claude_api table
# # Clear the table first if it exists
# claude_api_table.truncate()
# claude_api_table.insert(consolidated_settings)
# # Ensure the document ID is 1
# claude_api_table.update(lambda _: True, doc_ids=[1])
# print(f"Claude API settings saved to claude_api table: {consolidated_settings}")
# # Now remove the Claude API settings from individual tools
# # This requires modifying each tool and updating the database
# modified_count = 0
# for tool in tools_table.all():
# tool_modified = False
# if 'options' in tool:
# # Keep only non-Claude API options
# new_options = []
# for option in tool['options']:
# param_name = option.get('name')
# # Keep the option in the tool configuration but update its default value
# # to reflect the centralized value
# if param_name in CLAUDE_API_PARAMS:
# key = PARAM_MAPPING.get(param_name)
# option['default'] = consolidated_settings.get(key)
# tool_modified = True
# new_options.append(option)
# # Update the tool's options
# if tool_modified:
# tools_table.update({'options': new_options}, doc_ids=[tool.doc_id])
# modified_count += 1
# print(f"Modified {modified_count} tools to use centralized Claude API settings")
# # Close the database
# db.close()
# print("Database cleanup complete.")
# if __name__ == "__main__":
# main()
from tinydb import TinyDB, Query
import os
TINYDB_FILE = "writers_toolkit_tinydb.json"
DEFAULT_CLAUDE_API_CONFIG = {
"max_retries": 1,
"request_timeout": 300,
"context_window": 200000,
"thinking_budget_tokens": 32000,
"betas_max_tokens": 128000,
"desired_output_tokens": 12000
}
DEFAULT_SETTINGS = {
"default_save_dir": "/Users/cleesmith/writing/a Smuffin",
"tools_config_json_dir": ".",
"current_project": "a Smuffin",
"current_project_path": "/Users/cleesmith/writing/a Smuffin",
"claude_api_configuration": DEFAULT_CLAUDE_API_CONFIG
}
def update_tinydb_settings():
if not os.path.exists(TINYDB_FILE):
print(f"Error: {TINYDB_FILE} does not exist.")
return
db = TinyDB(TINYDB_FILE)
# Remove any existing settings by dropping the table
if "settings" in db.tables():
db.drop_table("settings")
print("Dropped existing 'settings' table.")
# Create a new settings table and insert the default settings record
settings_table = db.table("settings")
settings_table.insert(DEFAULT_SETTINGS)
print("Inserted new default settings into the 'settings' table.")
if __name__ == "__main__":
update_tinydb_settings()