mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 15:38:55 +01:00
Basic example of serving conifg as JSON and retriving on button click
This commit is contained in:
parent
3d4471e107
commit
3db06eee3f
2 changed files with 16 additions and 44 deletions
12
src/main.py
12
src/main.py
|
@ -7,6 +7,7 @@ from typing import Optional
|
|||
import uvicorn
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
# Internal Packages
|
||||
|
@ -20,15 +21,21 @@ from src.processor.conversation.gpt import converse, message_to_prompt
|
|||
model = SearchModels()
|
||||
search_config = SearchConfig()
|
||||
processor_config = ProcessorConfig()
|
||||
config = {}
|
||||
app = FastAPI()
|
||||
|
||||
# app.mount("/views", StaticFiles(directory="./views"), name="views")
|
||||
app.mount("/views", StaticFiles(directory="views"), name="views")
|
||||
templates = Jinja2Templates(directory="views/")
|
||||
|
||||
@app.get('/ui', response_class=HTMLResponse)
|
||||
def ui(request: Request):
|
||||
return templates.TemplateResponse("config.html", context={'request': request})
|
||||
|
||||
@app.get('/config')
|
||||
def config():
|
||||
print(config)
|
||||
return config
|
||||
|
||||
@app.get('/search')
|
||||
def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None):
|
||||
if q is None or q == '':
|
||||
|
@ -173,6 +180,9 @@ if __name__ == '__main__':
|
|||
# Load config from CLI
|
||||
args = cli(sys.argv[1:])
|
||||
|
||||
# Store the path to the config file.
|
||||
config = args.config
|
||||
|
||||
# Initialize Search from Config
|
||||
model, search_config = initialize_search(args.config, args.regenerate, args.verbose)
|
||||
|
||||
|
|
|
@ -3,49 +3,11 @@
|
|||
<title>Set directories for your config file.</title>
|
||||
</head>
|
||||
<body>
|
||||
<form>
|
||||
<input type="file" id="filepicker" name="fileList" />
|
||||
<h2>Org notes</h2>
|
||||
<label>Input Files</label>
|
||||
<input type="textarea" id="org-files" name="org-files" placeholder='"/home/saba/notes/notes.org", "/home/saba/notes/writing.org"/'>
|
||||
<label>Input Filter</label>
|
||||
<input type="text" id="org-files" name="org-files" placeholder="null">
|
||||
<button type="button" id="show-config">Show Config</button>
|
||||
<form id="update-config" style="display: none;">
|
||||
<h1 id="config-title"></h1>
|
||||
<h2>content-type</h2>
|
||||
</form>
|
||||
<output id="list"></output>
|
||||
</body>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js"> </script>
|
||||
<script>
|
||||
var filePicker = document.getElementById("filepicker");
|
||||
filePicker.addEventListener("change", () => {
|
||||
console.log(filePicker);
|
||||
for (const file of filePicker.files) {
|
||||
|
||||
if(!file.type.includes("yaml")) {
|
||||
console.log(file);
|
||||
let url = URL.createObjectURL(file);
|
||||
|
||||
const reader = new FileReader();
|
||||
|
||||
// Closure to capture the file information.
|
||||
reader.onload = (function(theFile) {
|
||||
return function(e) {
|
||||
// Render thumbnail.
|
||||
var span = document.createElement('span');
|
||||
span.innerHTML = ['<img class="thumb" src="', e.target.result,
|
||||
'" title="', escape(theFile.name), '"/>'].join('');
|
||||
document.getElementById('list').insertBefore(span, null);
|
||||
};
|
||||
})(file);
|
||||
|
||||
// Read in the image file as a data URL.
|
||||
reader.readAsDataURL(file);
|
||||
|
||||
window.jsyaml.loadAll(url, function(doc) {
|
||||
reader.readAsDataURL(url);
|
||||
console.log(doc);
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<script src="views/scripts/readWriteConfig.js"></script>
|
||||
</html>
|
Loading…
Reference in a new issue