mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Use global config and add a regenerate button to the config ui' && git push
This commit is contained in:
parent
34d1e4199c
commit
6f466c8d99
4 changed files with 19 additions and 8 deletions
|
@ -19,4 +19,4 @@ search-type:
|
|||
cross-encoder: cross-encoder/ms-marco-MiniLM-L-6-v2
|
||||
encoder: sentence-transformers/msmarco-MiniLM-L-6-v3
|
||||
image:
|
||||
encoder: clip-ViT-B-32
|
||||
encoder: ''
|
||||
|
|
16
src/main.py
16
src/main.py
|
@ -38,11 +38,12 @@ def config():
|
|||
|
||||
@app.post('/config')
|
||||
async def config(updated_config: FullConfig):
|
||||
print(updated_config.dict())
|
||||
global config
|
||||
config = updated_config
|
||||
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()
|
||||
return updated_config
|
||||
return config
|
||||
|
||||
@app.get('/search')
|
||||
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')
|
||||
def regenerate(t: Optional[SearchType] = None):
|
||||
print("-----REGENERATING----")
|
||||
if (t == SearchType.Notes or t == None) and search_config.notes:
|
||||
# Extract Entries, Generate Embeddings
|
||||
model.notes_search = asymmetric.setup(search_config.notes, regenerate=True)
|
||||
|
@ -124,7 +126,7 @@ def chat(q: str):
|
|||
return {'status': 'ok', 'response': gpt_response}
|
||||
|
||||
|
||||
def initialize_search(config: FullConfig, regenerate, verbose):
|
||||
def initialize_search(regenerate, verbose):
|
||||
model = SearchModels()
|
||||
search_config = SearchConfig()
|
||||
|
||||
|
@ -151,7 +153,7 @@ def initialize_search(config: FullConfig, regenerate, verbose):
|
|||
return model, search_config
|
||||
|
||||
|
||||
def initialize_processor(config: FullConfig, verbose):
|
||||
def initialize_processor(verbose):
|
||||
processor_config = ProcessorConfig()
|
||||
|
||||
# Initialize Conversation Processor
|
||||
|
@ -195,10 +197,10 @@ if __name__ == '__main__':
|
|||
config = args.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
|
||||
processor_config = initialize_processor(args.config, args.verbose)
|
||||
processor_config = initialize_processor(args.verbose)
|
||||
|
||||
# Start Application Server
|
||||
if args.socket:
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<body>
|
||||
<form id="config-form">
|
||||
</form>
|
||||
<button id="config-regenerate">regenerate</button>
|
||||
</body>
|
||||
<script src="views/scripts/config.js"></script>
|
||||
</html>
|
|
@ -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) {
|
||||
for (let key in data) {
|
||||
var child = document.createElement("div");
|
||||
|
|
Loading…
Reference in a new issue