mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +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
|
import uvicorn
|
||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
# Internal Packages
|
# Internal Packages
|
||||||
|
@ -20,15 +21,21 @@ from src.processor.conversation.gpt import converse, message_to_prompt
|
||||||
model = SearchModels()
|
model = SearchModels()
|
||||||
search_config = SearchConfig()
|
search_config = SearchConfig()
|
||||||
processor_config = ProcessorConfig()
|
processor_config = ProcessorConfig()
|
||||||
|
config = {}
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
# app.mount("/views", StaticFiles(directory="./views"), name="views")
|
app.mount("/views", StaticFiles(directory="views"), name="views")
|
||||||
templates = Jinja2Templates(directory="views/")
|
templates = Jinja2Templates(directory="views/")
|
||||||
|
|
||||||
@app.get('/ui', response_class=HTMLResponse)
|
@app.get('/ui', response_class=HTMLResponse)
|
||||||
def ui(request: Request):
|
def ui(request: Request):
|
||||||
return templates.TemplateResponse("config.html", context={'request': request})
|
return templates.TemplateResponse("config.html", context={'request': request})
|
||||||
|
|
||||||
|
@app.get('/config')
|
||||||
|
def config():
|
||||||
|
print(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):
|
||||||
if q is None or q == '':
|
if q is None or q == '':
|
||||||
|
@ -173,6 +180,9 @@ if __name__ == '__main__':
|
||||||
# Load config from CLI
|
# Load config from CLI
|
||||||
args = cli(sys.argv[1:])
|
args = cli(sys.argv[1:])
|
||||||
|
|
||||||
|
# Store the path to the config file.
|
||||||
|
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.config, args.regenerate, args.verbose)
|
||||||
|
|
||||||
|
|
|
@ -3,49 +3,11 @@
|
||||||
<title>Set directories for your config file.</title>
|
<title>Set directories for your config file.</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form>
|
<button type="button" id="show-config">Show Config</button>
|
||||||
<input type="file" id="filepicker" name="fileList" />
|
<form id="update-config" style="display: none;">
|
||||||
<h2>Org notes</h2>
|
<h1 id="config-title"></h1>
|
||||||
<label>Input Files</label>
|
<h2>content-type</h2>
|
||||||
<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">
|
|
||||||
</form>
|
</form>
|
||||||
<output id="list"></output>
|
|
||||||
</body>
|
</body>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js"> </script>
|
<script src="views/scripts/readWriteConfig.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>
|
|
||||||
</html>
|
</html>
|
Loading…
Reference in a new issue