Use global config and add a regenerate button to the config ui' && git push

This commit is contained in:
Saba 2021-11-28 13:28:22 -05:00
parent 34d1e4199c
commit 6f466c8d99
4 changed files with 19 additions and 8 deletions

View file

@ -19,4 +19,4 @@ search-type:
cross-encoder: cross-encoder/ms-marco-MiniLM-L-6-v2 cross-encoder: cross-encoder/ms-marco-MiniLM-L-6-v2
encoder: sentence-transformers/msmarco-MiniLM-L-6-v3 encoder: sentence-transformers/msmarco-MiniLM-L-6-v3
image: image:
encoder: clip-ViT-B-32 encoder: ''

View file

@ -38,11 +38,12 @@ def config():
@app.post('/config') @app.post('/config')
async def config(updated_config: FullConfig): async def config(updated_config: FullConfig):
print(updated_config.dict()) global config
config = updated_config
with open(config_file, 'w') as outfile: with open(config_file, 'w') as outfile:
yaml.dump(yaml.safe_load(updated_config.json(by_alias=True)), outfile) yaml.dump(yaml.safe_load(config.json(by_alias=True)), outfile)
outfile.close() outfile.close()
return updated_config return config
@app.get('/search') @app.get('/search')
def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None): def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None):
@ -91,6 +92,7 @@ def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None):
@app.get('/regenerate') @app.get('/regenerate')
def regenerate(t: Optional[SearchType] = None): def regenerate(t: Optional[SearchType] = None):
print("-----REGENERATING----")
if (t == SearchType.Notes or t == None) and search_config.notes: if (t == SearchType.Notes or t == None) and search_config.notes:
# Extract Entries, Generate Embeddings # Extract Entries, Generate Embeddings
model.notes_search = asymmetric.setup(search_config.notes, regenerate=True) model.notes_search = asymmetric.setup(search_config.notes, regenerate=True)
@ -124,7 +126,7 @@ def chat(q: str):
return {'status': 'ok', 'response': gpt_response} return {'status': 'ok', 'response': gpt_response}
def initialize_search(config: FullConfig, regenerate, verbose): def initialize_search(regenerate, verbose):
model = SearchModels() model = SearchModels()
search_config = SearchConfig() search_config = SearchConfig()
@ -151,7 +153,7 @@ def initialize_search(config: FullConfig, regenerate, verbose):
return model, search_config return model, search_config
def initialize_processor(config: FullConfig, verbose): def initialize_processor(verbose):
processor_config = ProcessorConfig() processor_config = ProcessorConfig()
# Initialize Conversation Processor # Initialize Conversation Processor
@ -195,10 +197,10 @@ if __name__ == '__main__':
config = args.config config = args.config
# Initialize Search from Config # Initialize Search from Config
model, search_config = initialize_search(args.config, args.regenerate, args.verbose) model, search_config = initialize_search(args.regenerate, args.verbose)
# Initialize Processor from Config # Initialize Processor from Config
processor_config = initialize_processor(args.config, args.verbose) processor_config = initialize_processor(args.verbose)
# Start Application Server # Start Application Server
if args.socket: if args.socket:

View file

@ -6,6 +6,7 @@
<body> <body>
<form id="config-form"> <form id="config-form">
</form> </form>
<button id="config-regenerate">regenerate</button>
</body> </body>
<script src="views/scripts/config.js"></script> <script src="views/scripts/config.js"></script>
</html> </html>

View file

@ -32,6 +32,14 @@ fetch("/config")
}); });
}); });
var regenerateButton = document.getElementById("config-regenerate");
regenerateButton.addEventListener("click", (event) => {
event.preventDefault();
fetch("/regenerate")
.then(response => response.json())
.then(data => console.log(data));
})
function processChildren(element, data) { function processChildren(element, data) {
for (let key in data) { for (let key in data) {
var child = document.createElement("div"); var child = document.createElement("div");