mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Update content by source via API. Make web client use this API for config
This commit is contained in:
parent
9ab327a2b6
commit
d527b644f4
7 changed files with 32 additions and 29 deletions
|
@ -9,6 +9,6 @@ The Github integration allows you to index as many repositories as you want. It'
|
||||||
## Use the Github plugin
|
## Use the Github plugin
|
||||||
|
|
||||||
1. Generate a [classic PAT (personal access token)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) from [Github](https://github.com/settings/tokens) with `repo` and `admin:org` scopes at least.
|
1. Generate a [classic PAT (personal access token)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) from [Github](https://github.com/settings/tokens) with `repo` and `admin:org` scopes at least.
|
||||||
2. Navigate to [http://localhost:42110/config/content_type/github](http://localhost:42110/config/content_type/github) to configure your Github settings. Enter in your PAT, along with details for each repository you want to index.
|
2. Navigate to [http://localhost:42110/config/content-source/github](http://localhost:42110/config/content-source/github) to configure your Github settings. Enter in your PAT, along with details for each repository you want to index.
|
||||||
3. Click `Save`. Go back to the settings page and click `Configure`.
|
3. Click `Save`. Go back to the settings page and click `Configure`.
|
||||||
4. Go to [http://localhost:42110/](http://localhost:42110/) and start searching!
|
4. Go to [http://localhost:42110/](http://localhost:42110/) and start searching!
|
||||||
|
|
|
@ -8,7 +8,7 @@ We haven't setup a fancy integration with OAuth yet, so this integration still r
|
||||||
![setup_new_integration](https://github.com/khoj-ai/khoj/assets/65192171/b056e057-d4dc-47dc-aad3-57b59a22c68b)
|
![setup_new_integration](https://github.com/khoj-ai/khoj/assets/65192171/b056e057-d4dc-47dc-aad3-57b59a22c68b)
|
||||||
3. Share all the workspaces that you want to integrate with the Khoj integration you just made in the previous step
|
3. Share all the workspaces that you want to integrate with the Khoj integration you just made in the previous step
|
||||||
![enable_workspace](https://github.com/khoj-ai/khoj/assets/65192171/98290303-b5b8-4cb0-b32c-f68c6923a3d0)
|
![enable_workspace](https://github.com/khoj-ai/khoj/assets/65192171/98290303-b5b8-4cb0-b32c-f68c6923a3d0)
|
||||||
4. In the first step, you generated an API key. Use the newly generated API Key in your Khoj settings, by default at http://localhost:42110/config/content_type/notion. Click `Save`.
|
4. In the first step, you generated an API key. Use the newly generated API Key in your Khoj settings, by default at http://localhost:42110/config/content-source/notion. Click `Save`.
|
||||||
5. Click `Configure` in http://localhost:42110/config to index your Notion workspace(s).
|
5. Click `Configure` in http://localhost:42110/config to index your Notion workspace(s).
|
||||||
|
|
||||||
That's it! You should be ready to start searching and chatting. Make sure you've configured your OpenAI API Key for chat.
|
That's it! You should be ready to start searching and chatting. Make sure you've configured your OpenAI API Key for chat.
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<p class="card-description">Set repositories to index</p>
|
<p class="card-description">Set repositories to index</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-action-row">
|
<div class="card-action-row">
|
||||||
<a class="card-button" href="/config/content_type/github">
|
<a class="card-button" href="/config/content-source/github">
|
||||||
{% if current_model_state.github %}
|
{% if current_model_state.github %}
|
||||||
Update
|
Update
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
<p class="card-description">Configure your settings from Notion</p>
|
<p class="card-description">Configure your settings from Notion</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-action-row">
|
<div class="card-action-row">
|
||||||
<a class="card-button" href="/config/content_type/notion">
|
<a class="card-button" href="/config/content-source/notion">
|
||||||
{% if current_model_state.content %}
|
{% if current_model_state.content %}
|
||||||
Update
|
Update
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -176,8 +176,9 @@
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
function clearContentType(content_type) {
|
function clearContentType(content_source) {
|
||||||
fetch('/api/config/data/content_type/' + content_type, {
|
|
||||||
|
fetch('/api/config/data/content-source/' + content_source, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -186,15 +187,15 @@
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.status == "ok") {
|
if (data.status == "ok") {
|
||||||
var contentTypeClearButton = document.getElementById("clear-" + content_type);
|
var contentTypeClearButton = document.getElementById("clear-" + content_source);
|
||||||
contentTypeClearButton.style.display = "none";
|
contentTypeClearButton.style.display = "none";
|
||||||
|
|
||||||
var configuredIcon = document.getElementById("configured-icon-" + content_type);
|
var configuredIcon = document.getElementById("configured-icon-" + content_source);
|
||||||
if (configuredIcon) {
|
if (configuredIcon) {
|
||||||
configuredIcon.style.display = "none";
|
configuredIcon.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
var misconfiguredIcon = document.getElementById("misconfigured-icon-" + content_type);
|
var misconfiguredIcon = document.getElementById("misconfigured-icon-" + content_source);
|
||||||
if (misconfiguredIcon) {
|
if (misconfiguredIcon) {
|
||||||
misconfiguredIcon.style.display = "none";
|
misconfiguredIcon.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1];
|
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1];
|
||||||
fetch('/api/config/data/content_type/github', {
|
fetch('/api/config/data/content-source/github', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
|
@ -42,7 +42,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1];
|
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1];
|
||||||
fetch('/api/config/data/content_type/notion', {
|
fetch('/api/config/data/content-source/notion', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
|
@ -61,11 +61,13 @@ api = APIRouter()
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def map_config_to_object(content_type: str):
|
def map_config_to_object(content_source: str):
|
||||||
if content_type == "github":
|
if content_source == "github":
|
||||||
return GithubConfig
|
return GithubConfig
|
||||||
if content_type == "notion":
|
if content_source == "notion":
|
||||||
return NotionConfig
|
return NotionConfig
|
||||||
|
if content_source == "computer":
|
||||||
|
return "Computer"
|
||||||
|
|
||||||
|
|
||||||
async def map_config_to_db(config: FullConfig, user: KhojUser):
|
async def map_config_to_db(config: FullConfig, user: KhojUser):
|
||||||
|
@ -164,7 +166,7 @@ async def set_config_data(
|
||||||
return state.config
|
return state.config
|
||||||
|
|
||||||
|
|
||||||
@api.post("/config/data/content_type/github", status_code=200)
|
@api.post("/config/data/content-source/github", status_code=200)
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def set_content_config_github_data(
|
async def set_content_config_github_data(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
@ -192,7 +194,7 @@ async def set_content_config_github_data(
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
@api.post("/config/data/content_type/notion", status_code=200)
|
@api.post("/config/data/content-source/notion", status_code=200)
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def set_content_config_notion_data(
|
async def set_content_config_notion_data(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
@ -219,11 +221,11 @@ async def set_content_config_notion_data(
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
@api.delete("/config/data/content_type/{content_type}", status_code=200)
|
@api.delete("/config/data/content-source/{content_source}", status_code=200)
|
||||||
@requires(["authenticated"])
|
@requires(["authenticated"])
|
||||||
async def remove_content_config_data(
|
async def remove_content_source_data(
|
||||||
request: Request,
|
request: Request,
|
||||||
content_type: str,
|
content_source: str,
|
||||||
client: Optional[str] = None,
|
client: Optional[str] = None,
|
||||||
):
|
):
|
||||||
user = request.user.object
|
user = request.user.object
|
||||||
|
@ -233,15 +235,15 @@ async def remove_content_config_data(
|
||||||
telemetry_type="api",
|
telemetry_type="api",
|
||||||
api="delete_content_config",
|
api="delete_content_config",
|
||||||
client=client,
|
client=client,
|
||||||
metadata={"content_type": content_type},
|
metadata={"content_source": content_source},
|
||||||
)
|
)
|
||||||
|
|
||||||
content_object = map_config_to_object(content_type)
|
content_object = map_config_to_object(content_source)
|
||||||
if content_object is None:
|
if content_object is None:
|
||||||
raise ValueError(f"Invalid content type: {content_type}")
|
raise ValueError(f"Invalid content source: {content_source}")
|
||||||
|
elif content_object != "Computer":
|
||||||
await content_object.objects.filter(user=user).adelete()
|
await content_object.objects.filter(user=user).adelete()
|
||||||
await sync_to_async(EntryAdapters.delete_all_entries)(user, content_type)
|
await sync_to_async(EntryAdapters.delete_all_entries_by_source)(user, content_source)
|
||||||
|
|
||||||
enabled_content = await sync_to_async(EntryAdapters.get_unique_file_types)(user)
|
enabled_content = await sync_to_async(EntryAdapters.get_unique_file_types)(user)
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
|
@ -150,7 +150,7 @@ def config_page(request: Request):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@web_client.get("/config/content_type/github", response_class=HTMLResponse)
|
@web_client.get("/config/content-source/github", response_class=HTMLResponse)
|
||||||
@requires(["authenticated"], redirect="login_page")
|
@requires(["authenticated"], redirect="login_page")
|
||||||
def github_config_page(request: Request):
|
def github_config_page(request: Request):
|
||||||
user = request.user.object
|
user = request.user.object
|
||||||
|
@ -177,7 +177,7 @@ def github_config_page(request: Request):
|
||||||
current_config = {} # type: ignore
|
current_config = {} # type: ignore
|
||||||
|
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
"content_type_github_input.html",
|
"content_source_github_input.html",
|
||||||
context={
|
context={
|
||||||
"request": request,
|
"request": request,
|
||||||
"current_config": current_config,
|
"current_config": current_config,
|
||||||
|
@ -187,7 +187,7 @@ def github_config_page(request: Request):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@web_client.get("/config/content_type/notion", response_class=HTMLResponse)
|
@web_client.get("/config/content-source/notion", response_class=HTMLResponse)
|
||||||
@requires(["authenticated"], redirect="login_page")
|
@requires(["authenticated"], redirect="login_page")
|
||||||
def notion_config_page(request: Request):
|
def notion_config_page(request: Request):
|
||||||
user = request.user.object
|
user = request.user.object
|
||||||
|
@ -201,7 +201,7 @@ def notion_config_page(request: Request):
|
||||||
current_config = json.loads(current_config.json())
|
current_config = json.loads(current_config.json())
|
||||||
|
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
"content_type_notion_input.html",
|
"content_source_notion_input.html",
|
||||||
context={
|
context={
|
||||||
"request": request,
|
"request": request,
|
||||||
"current_config": current_config,
|
"current_config": current_config,
|
||||||
|
|
Loading…
Add table
Reference in a new issue