diff --git a/.github/workflows/run_evals.yml b/.github/workflows/run_evals.yml index 15800691..dc8c89b7 100644 --- a/.github/workflows/run_evals.yml +++ b/.github/workflows/run_evals.yml @@ -76,12 +76,12 @@ jobs: DEBIAN_FRONTEND: noninteractive run: | # install postgres and other dependencies - apt update && apt install -y git python3-pip libegl1 sqlite3 libsqlite3-dev libsqlite3-0 ffmpeg libsm6 libxext6 - apt install -y postgresql postgresql-client && apt install -y postgresql-server-dev-14 + sudo apt update && sudo apt install -y git python3-pip libegl1 sqlite3 libsqlite3-dev libsqlite3-0 ffmpeg libsm6 libxext6 + sudo apt install -y postgresql postgresql-client && sudo apt install -y postgresql-server-dev-14 # upgrade pip python -m ensurepip --upgrade && python -m pip install --upgrade pip # install terrarium for code sandbox - git clone https://github.com/cohere-ai/cohere-terrarium.git && cd cohere-terrarium && npm install && mkdir pyodide_cache + git clone https://github.com/khoj-ai/terrarium.git && cd terrarium && npm install --legacy-peer-deps && mkdir pyodide_cache - name: ⬇️ Install Application run: | @@ -113,7 +113,7 @@ jobs: khoj --anonymous-mode --non-interactive & # Start code sandbox - npm run dev --prefix cohere-terrarium & + npm run dev --prefix terrarium & # Wait for server to be ready timeout=120 diff --git a/.gitignore b/.gitignore index 4041122a..09288aa7 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,13 @@ src/interface/obsidian/main.js # obsidian data.json + +# Android +src/interface/android/.gradle +src/interface/android/app/build +src/interface/android/build +src/interface/android/*.aab +src/interface/android/*.apk +src/interface/android/*.apk.idsig +src/interface/android/*.keystore +src/interface/android/local.properties diff --git a/docker-compose.yml b/docker-compose.yml index 652cf6a0..960dc1b8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,7 +22,7 @@ services: depends_on: database: condition: service_healthy - # Use the following line to use the latest version of khoj. Otherwise, it will build from source. + # Use the following line to use the latest version of khoj. Otherwise, it will build from source. Set this to ghcr.io/khoj-ai/khoj-cloud if you want to use the prod image. image: ghcr.io/khoj-ai/khoj:latest # Uncomment the following line to build from source. This will take a few minutes. Comment the next two lines out if you want to use the offiicial image. # build: @@ -83,6 +83,7 @@ services: # Telemetry helps us prioritize feature development and understand how people are using Khoj # Read more at https://docs.khoj.dev/miscellaneous/telemetry # - KHOJ_TELEMETRY_DISABLE=True + # Uncomment this line when you're using the official ghcr.io/khoj-ai/khoj-cloud prod image. command: --host="0.0.0.0" --port=42110 -vv --anonymous-mode --non-interactive diff --git a/documentation/docs/clients/emacs.md b/documentation/docs/clients/emacs.md index 73405b69..c047e282 100644 --- a/documentation/docs/clients/emacs.md +++ b/documentation/docs/clients/emacs.md @@ -114,7 +114,7 @@ This feature finds entries similar to the one you are currently on. 2. Hit `C-c s f` (or `M-x khoj RET f`) to find similar entries ### Advanced Usage -- Add [query filters](https://github.com/khoj-ai/khoj/#query-filters) during search to narrow down results further +- Add [query filters](/miscellaneous/advanced#query-filters) during search to narrow down results further e.g. `What is the meaning of life? -"god" +"none" dt>"last week"` - Use `C-c C-o 2` to open the current result at cursor in its source org file diff --git a/pyproject.toml b/pyproject.toml index 59adf952..af3460b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,6 +64,7 @@ dependencies = [ "anyio == 3.7.1", "pymupdf == 1.24.11", "django == 5.0.9", + "django-unfold == 0.42.0", "authlib == 1.2.1", "llama-cpp-python == 0.2.88", "itsdangerous == 2.1.2", diff --git a/src/interface/android/app/build.gradle b/src/interface/android/app/build.gradle new file mode 100644 index 00000000..bfa06911 --- /dev/null +++ b/src/interface/android/app/build.gradle @@ -0,0 +1,211 @@ +/* + * Copyright 2019 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import groovy.xml.MarkupBuilder + +plugins { + id 'com.android.application' +} + +def twaManifest = [ + applicationId: 'dev.khoj.app', + hostName: 'app.khoj.dev', // The domain being opened in the TWA. + launchUrl: '/', // The start path for the TWA. Must be relative to the domain. + name: 'Khoj AI', // The application name. + launcherName: 'Khoj', // The name shown on the Android Launcher. + themeColor: '#FFFFFF', // The color used for the status bar. + themeColorDark: '#000000', // The color used for the dark status bar. + navigationColor: '#000000', // The color used for the navigation bar. + navigationColorDark: '#000000', // The color used for the dark navbar. + navigationDividerColor: '#000000', // The navbar divider color. + navigationDividerColorDark: '#000000', // The dark navbar divider color. + backgroundColor: '#FFFFFF', // The color used for the splash screen background. + enableNotifications: true, // Set to true to enable notification delegation. + // Every shortcut must include the following fields: + // - name: String that will show up in the shortcut. + // - short_name: Shorter string used if |name| is too long. + // - url: Absolute path of the URL to launch the app with (e.g '/create'). + // - icon: Name of the resource in the drawable folder to use as an icon. + shortcuts: [], + // The duration of fade out animation in milliseconds to be played when removing splash screen. + splashScreenFadeOutDuration: 300, + generatorApp: 'bubblewrap-cli', // Application that generated the Android Project + // The fallback strategy for when Trusted Web Activity is not available. Possible values are + // 'customtabs' and 'webview'. + fallbackType: 'customtabs', + enableSiteSettingsShortcut: 'true', + orientation: 'natural', +] + +android { + compileSdkVersion 35 + namespace "dev.khoj.app" + defaultConfig { + applicationId "dev.khoj.app" + minSdkVersion 19 + targetSdkVersion 35 + versionCode 4 + versionName "4" + + // The name for the application + resValue "string", "appName", twaManifest.name + + // The name for the application on the Android Launcher + resValue "string", "launcherName", twaManifest.launcherName + + // The URL that will be used when launching the TWA from the Android Launcher + def launchUrl = "https://" + twaManifest.hostName + twaManifest.launchUrl + resValue "string", "launchUrl", launchUrl + + + // The URL the Web Manifest for the Progressive Web App that the TWA points to. This + // is used by Chrome OS and Meta Quest to open the Web version of the PWA instead of + // the TWA, as it will probably give a better user experience for non-mobile devices. + resValue "string", "webManifestUrl", 'https://app.khoj.dev/static/khoj.webmanifest' + + + + // This is used by Meta Quest. + resValue "string", "fullScopeUrl", 'https://app.khoj.dev/' + + + + + // The hostname is used when building the intent-filter, so the TWA is able to + // handle Intents to open host url of the application. + resValue "string", "hostName", twaManifest.hostName + + // This attribute sets the status bar color for the TWA. It can be either set here or in + // `res/values/colors.xml`. Setting in both places is an error and the app will not + // compile. If not set, the status bar color defaults to #FFFFFF - white. + resValue "color", "colorPrimary", twaManifest.themeColor + + // This attribute sets the dark status bar color for the TWA. It can be either set here or in + // `res/values/colors.xml`. Setting in both places is an error and the app will not + // compile. If not set, the status bar color defaults to #000000 - white. + resValue "color", "colorPrimaryDark", twaManifest.themeColorDark + + // This attribute sets the navigation bar color for the TWA. It can be either set here or + // in `res/values/colors.xml`. Setting in both places is an error and the app will not + // compile. If not set, the navigation bar color defaults to #FFFFFF - white. + resValue "color", "navigationColor", twaManifest.navigationColor + + // This attribute sets the dark navigation bar color for the TWA. It can be either set here + // or in `res/values/colors.xml`. Setting in both places is an error and the app will not + // compile. If not set, the navigation bar color defaults to #000000 - black. + resValue "color", "navigationColorDark", twaManifest.navigationColorDark + + // This attribute sets the navbar divider color for the TWA. It can be either + // set here or in `res/values/colors.xml`. Setting in both places is an error and the app + // will not compile. If not set, the divider color defaults to #00000000 - transparent. + resValue "color", "navigationDividerColor", twaManifest.navigationDividerColor + + // This attribute sets the dark navbar divider color for the TWA. It can be either + // set here or in `res/values/colors.xml`. Setting in both places is an error and the + //app will not compile. If not set, the divider color defaults to #000000 - black. + resValue "color", "navigationDividerColorDark", twaManifest.navigationDividerColorDark + + // Sets the color for the background used for the splash screen when launching the + // Trusted Web Activity. + resValue "color", "backgroundColor", twaManifest.backgroundColor + + // Defines a provider authority for the Splash Screen + resValue "string", "providerAuthority", twaManifest.applicationId + '.fileprovider' + + // The enableNotification resource is used to enable or disable the + // TrustedWebActivityService, by changing the android:enabled and android:exported + // attributes + resValue "bool", "enableNotification", twaManifest.enableNotifications.toString() + + twaManifest.shortcuts.eachWithIndex { shortcut, index -> + resValue "string", "shortcut_name_$index", "$shortcut.name" + resValue "string", "shortcut_short_name_$index", "$shortcut.short_name" + } + + // The splashScreenFadeOutDuration resource is used to set the duration of fade out animation in milliseconds + // to be played when removing splash screen. The default is 0 (no animation). + resValue "integer", "splashScreenFadeOutDuration", twaManifest.splashScreenFadeOutDuration.toString() + + resValue "string", "generatorApp", twaManifest.generatorApp + + resValue "string", "fallbackType", twaManifest.fallbackType + + resValue "bool", "enableSiteSettingsShortcut", twaManifest.enableSiteSettingsShortcut + resValue "string", "orientation", twaManifest.orientation + } + buildTypes { + release { + minifyEnabled true + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + lintOptions { + checkReleaseBuilds false + } +} + +task generateShorcutsFile { + assert twaManifest.shortcuts.size() < 5, "You can have at most 4 shortcuts." + twaManifest.shortcuts.eachWithIndex { s, i -> + assert s.name != null, 'Missing `name` in shortcut #' + i + assert s.short_name != null, 'Missing `short_name` in shortcut #' + i + assert s.url != null, 'Missing `icon` in shortcut #' + i + assert s.icon != null, 'Missing `url` in shortcut #' + i + } + + def shortcutsFile = new File("$projectDir/src/main/res/xml", "shortcuts.xml") + + def xmlWriter = new StringWriter() + def xmlMarkup = new MarkupBuilder(new IndentPrinter(xmlWriter, " ", true)) + + xmlMarkup + .'shortcuts'('xmlns:android': 'http://schemas.android.com/apk/res/android') { + twaManifest.shortcuts.eachWithIndex { s, i -> + 'shortcut'( + 'android:shortcutId': 'shortcut' + i, + 'android:enabled': 'true', + 'android:icon': '@drawable/' + s.icon, + 'android:shortcutShortLabel': '@string/shortcut_short_name_' + i, + 'android:shortcutLongLabel': '@string/shortcut_name_' + i) { + 'intent'( + 'android:action': 'android.intent.action.MAIN', + 'android:targetPackage': twaManifest.applicationId, + 'android:targetClass': twaManifest.applicationId + '.LauncherActivity', + 'android:data': s.url) + 'categories'('android:name': 'android.intent.category.LAUNCHER') + } + } + } + shortcutsFile.text = xmlWriter.toString() + '\n' +} + +preBuild.dependsOn(generateShorcutsFile) + +repositories { + +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + + implementation 'com.google.androidbrowserhelper:locationdelegation:1.1.1' + + implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.5.0' + +} diff --git a/src/interface/android/app/src/main/AndroidManifest.xml b/src/interface/android/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..39fee27d --- /dev/null +++ b/src/interface/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/interface/android/app/src/main/java/dev/khoj/app/Application.java b/src/interface/android/app/src/main/java/dev/khoj/app/Application.java new file mode 100644 index 00000000..a1d3040f --- /dev/null +++ b/src/interface/android/app/src/main/java/dev/khoj/app/Application.java @@ -0,0 +1,29 @@ +/* + * Copyright 2020 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package dev.khoj.app; + + + +public class Application extends android.app.Application { + + + + @Override + public void onCreate() { + super.onCreate(); + + } +} diff --git a/src/interface/android/app/src/main/java/dev/khoj/app/DelegationService.java b/src/interface/android/app/src/main/java/dev/khoj/app/DelegationService.java new file mode 100644 index 00000000..d8d6bd10 --- /dev/null +++ b/src/interface/android/app/src/main/java/dev/khoj/app/DelegationService.java @@ -0,0 +1,17 @@ +package dev.khoj.app; + + +import com.google.androidbrowserhelper.locationdelegation.LocationDelegationExtraCommandHandler; + + +public class DelegationService extends + com.google.androidbrowserhelper.trusted.DelegationService { + @Override + public void onCreate() { + super.onCreate(); + + + registerExtraCommandHandler(new LocationDelegationExtraCommandHandler()); + + } +} diff --git a/src/interface/android/app/src/main/java/dev/khoj/app/LauncherActivity.java b/src/interface/android/app/src/main/java/dev/khoj/app/LauncherActivity.java new file mode 100644 index 00000000..a56c4232 --- /dev/null +++ b/src/interface/android/app/src/main/java/dev/khoj/app/LauncherActivity.java @@ -0,0 +1,54 @@ +/* + * Copyright 2020 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package dev.khoj.app; + +import android.content.pm.ActivityInfo; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; + + + +public class LauncherActivity + extends com.google.androidbrowserhelper.trusted.LauncherActivity { + + + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // Setting an orientation crashes the app due to the transparent background on Android 8.0 + // Oreo and below. We only set the orientation on Oreo and above. This only affects the + // splash screen and Chrome will still respect the orientation. + // See https://github.com/GoogleChromeLabs/bubblewrap/issues/496 for details. + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); + } else { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); + } + } + + @Override + protected Uri getLaunchingUrl() { + // Get the original launch Url. + Uri uri = super.getLaunchingUrl(); + + + + return uri; + } +} diff --git a/src/interface/android/app/src/main/res/drawable-anydpi/shortcut_legacy_background.xml b/src/interface/android/app/src/main/res/drawable-anydpi/shortcut_legacy_background.xml new file mode 100644 index 00000000..d53c148a --- /dev/null +++ b/src/interface/android/app/src/main/res/drawable-anydpi/shortcut_legacy_background.xml @@ -0,0 +1,25 @@ + + + + + + + + + diff --git a/src/interface/android/app/src/main/res/drawable-hdpi/ic_notification_icon.png b/src/interface/android/app/src/main/res/drawable-hdpi/ic_notification_icon.png new file mode 100644 index 00000000..db196a12 Binary files /dev/null and b/src/interface/android/app/src/main/res/drawable-hdpi/ic_notification_icon.png differ diff --git a/src/interface/android/app/src/main/res/drawable-hdpi/splash.png b/src/interface/android/app/src/main/res/drawable-hdpi/splash.png new file mode 100644 index 00000000..9d2384e2 Binary files /dev/null and b/src/interface/android/app/src/main/res/drawable-hdpi/splash.png differ diff --git a/src/interface/android/app/src/main/res/drawable-mdpi/ic_notification_icon.png b/src/interface/android/app/src/main/res/drawable-mdpi/ic_notification_icon.png new file mode 100644 index 00000000..1d97f7c1 Binary files /dev/null and b/src/interface/android/app/src/main/res/drawable-mdpi/ic_notification_icon.png differ diff --git a/src/interface/android/app/src/main/res/drawable-mdpi/splash.png b/src/interface/android/app/src/main/res/drawable-mdpi/splash.png new file mode 100644 index 00000000..77088425 Binary files /dev/null and b/src/interface/android/app/src/main/res/drawable-mdpi/splash.png differ diff --git a/src/interface/android/app/src/main/res/drawable-xhdpi/ic_notification_icon.png b/src/interface/android/app/src/main/res/drawable-xhdpi/ic_notification_icon.png new file mode 100644 index 00000000..9625ad91 Binary files /dev/null and b/src/interface/android/app/src/main/res/drawable-xhdpi/ic_notification_icon.png differ diff --git a/src/interface/android/app/src/main/res/drawable-xhdpi/splash.png b/src/interface/android/app/src/main/res/drawable-xhdpi/splash.png new file mode 100644 index 00000000..1d4f64fe Binary files /dev/null and b/src/interface/android/app/src/main/res/drawable-xhdpi/splash.png differ diff --git a/src/interface/android/app/src/main/res/drawable-xxhdpi/ic_notification_icon.png b/src/interface/android/app/src/main/res/drawable-xxhdpi/ic_notification_icon.png new file mode 100644 index 00000000..355b7586 Binary files /dev/null and b/src/interface/android/app/src/main/res/drawable-xxhdpi/ic_notification_icon.png differ diff --git a/src/interface/android/app/src/main/res/drawable-xxhdpi/splash.png b/src/interface/android/app/src/main/res/drawable-xxhdpi/splash.png new file mode 100644 index 00000000..43423514 Binary files /dev/null and b/src/interface/android/app/src/main/res/drawable-xxhdpi/splash.png differ diff --git a/src/interface/android/app/src/main/res/drawable-xxxhdpi/ic_notification_icon.png b/src/interface/android/app/src/main/res/drawable-xxxhdpi/ic_notification_icon.png new file mode 100644 index 00000000..9ed4d5e6 Binary files /dev/null and b/src/interface/android/app/src/main/res/drawable-xxxhdpi/ic_notification_icon.png differ diff --git a/src/interface/android/app/src/main/res/drawable-xxxhdpi/splash.png b/src/interface/android/app/src/main/res/drawable-xxxhdpi/splash.png new file mode 100644 index 00000000..cec7e27d Binary files /dev/null and b/src/interface/android/app/src/main/res/drawable-xxxhdpi/splash.png differ diff --git a/src/interface/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/src/interface/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..b97b2df5 Binary files /dev/null and b/src/interface/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/src/interface/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/src/interface/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..0a454eb1 Binary files /dev/null and b/src/interface/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/src/interface/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/src/interface/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..47c45373 Binary files /dev/null and b/src/interface/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/src/interface/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/src/interface/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..643b56f7 Binary files /dev/null and b/src/interface/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/src/interface/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/src/interface/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..3a456d9f Binary files /dev/null and b/src/interface/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/src/interface/android/app/src/main/res/raw/web_app_manifest.json b/src/interface/android/app/src/main/res/raw/web_app_manifest.json new file mode 100644 index 00000000..cff9d4ef --- /dev/null +++ b/src/interface/android/app/src/main/res/raw/web_app_manifest.json @@ -0,0 +1 @@ +{"name":"Khoj","short_name":"Khoj","display":"standalone","start_url":"/","description":"The open, personal AI for your digital brain. You can ask Khoj to draft a message, paint your imagination, find information on the internet and even answer questions from your documents.","theme_color":"#ffffff","background_color":"#ffffff","icons":[{"src":"/static/assets/icons/khoj_lantern_128x128.png","sizes":"128x128","type":"image/png"},{"src":"/static/assets/icons/khoj_lantern_256x256.png","sizes":"256x256","type":"image/png"}],"screenshots":[{"src":"/static/assets/samples/phone-remember-plan-sample.png","sizes":"419x900","type":"image/png","form_factor":"narrow","label":"Remember and Plan"},{"src":"/static/assets/samples/phone-browse-draw-sample.png","sizes":"419x900","type":"image/png","form_factor":"narrow","label":"Browse and Draw"},{"src":"/static/assets/samples/desktop-remember-plan-sample.png","sizes":"1260x742","type":"image/png","form_factor":"wide","label":"Remember and Plan"},{"src":"/static/assets/samples/desktop-browse-draw-sample.png","sizes":"1260x742","type":"image/png","form_factor":"wide","label":"Browse and Draw"}]} diff --git a/src/interface/android/app/src/main/res/values/colors.xml b/src/interface/android/app/src/main/res/values/colors.xml new file mode 100644 index 00000000..e66222d0 --- /dev/null +++ b/src/interface/android/app/src/main/res/values/colors.xml @@ -0,0 +1,18 @@ + + + #F5F5F5 + diff --git a/src/interface/android/app/src/main/res/values/strings.xml b/src/interface/android/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..d5d34f8b --- /dev/null +++ b/src/interface/android/app/src/main/res/values/strings.xml @@ -0,0 +1,36 @@ + + + + + + + + [{ + \"relation\": [\"delegate_permission/common.handle_all_urls\"], + \"target\": { + \"namespace\": \"web\", + \"site\": \"https://app.khoj.dev\" + } + }] + + + diff --git a/src/interface/android/app/src/main/res/xml/filepaths.xml b/src/interface/android/app/src/main/res/xml/filepaths.xml new file mode 100644 index 00000000..a5434852 --- /dev/null +++ b/src/interface/android/app/src/main/res/xml/filepaths.xml @@ -0,0 +1,18 @@ + + + + diff --git a/src/interface/android/app/src/main/res/xml/shortcuts.xml b/src/interface/android/app/src/main/res/xml/shortcuts.xml new file mode 100644 index 00000000..5effdb1d --- /dev/null +++ b/src/interface/android/app/src/main/res/xml/shortcuts.xml @@ -0,0 +1 @@ + diff --git a/src/interface/android/build.gradle b/src/interface/android/build.gradle new file mode 100644 index 00000000..fe8944ba --- /dev/null +++ b/src/interface/android/build.gradle @@ -0,0 +1,42 @@ +/* + * Copyright 2019 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + + repositories { + google() + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:8.7.2' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +tasks.register('clean', Delete) { + delete rootProject.buildDir +} diff --git a/src/interface/android/gradle.properties b/src/interface/android/gradle.properties new file mode 100644 index 00000000..784a1d43 --- /dev/null +++ b/src/interface/android/gradle.properties @@ -0,0 +1,14 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +android.useAndroidX=true diff --git a/src/interface/android/gradle/wrapper/gradle-wrapper.jar b/src/interface/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..5c2d1cf0 Binary files /dev/null and b/src/interface/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/src/interface/android/gradle/wrapper/gradle-wrapper.properties b/src/interface/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..b30c9914 --- /dev/null +++ b/src/interface/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +networkTimeout=10000 +validateDistributionUrl=true diff --git a/src/interface/android/gradlew b/src/interface/android/gradlew new file mode 100755 index 00000000..b740cf13 --- /dev/null +++ b/src/interface/android/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/src/interface/android/gradlew.bat b/src/interface/android/gradlew.bat new file mode 100644 index 00000000..7101f8e4 --- /dev/null +++ b/src/interface/android/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/interface/android/manifest-checksum.txt b/src/interface/android/manifest-checksum.txt new file mode 100644 index 00000000..d3280ee8 --- /dev/null +++ b/src/interface/android/manifest-checksum.txt @@ -0,0 +1 @@ +6ee1711cf4f745dafc80c1cc13c3025342a0f5da diff --git a/src/interface/android/settings.gradle b/src/interface/android/settings.gradle new file mode 100644 index 00000000..e7b4def4 --- /dev/null +++ b/src/interface/android/settings.gradle @@ -0,0 +1 @@ +include ':app' diff --git a/src/interface/android/store_icon.png b/src/interface/android/store_icon.png new file mode 100644 index 00000000..93b5729d Binary files /dev/null and b/src/interface/android/store_icon.png differ diff --git a/src/interface/android/twa-manifest.json b/src/interface/android/twa-manifest.json new file mode 100644 index 00000000..9b462834 --- /dev/null +++ b/src/interface/android/twa-manifest.json @@ -0,0 +1,55 @@ +{ + "packageId": "dev.khoj.app", + "host": "app.khoj.dev", + "name": "Khoj AI", + "launcherName": "Khoj", + "display": "standalone", + "themeColor": "#FFFFFF", + "themeColorDark": "#000000", + "navigationColor": "#000000", + "navigationColorDark": "#000000", + "navigationDividerColor": "#000000", + "navigationDividerColorDark": "#000000", + "backgroundColor": "#FFFFFF", + "enableNotifications": true, + "startUrl": "/", + "iconUrl": "https://assets.khoj.dev/khoj_lantern_1200x1200.png", + "splashScreenFadeOutDuration": 300, + "signingKey": { + "path": "android.keystore", + "alias": "android" + }, + "appVersionName": "4", + "appVersionCode": 4, + "shortcuts": [], + "generatorApp": "bubblewrap-cli", + "webManifestUrl": "https://app.khoj.dev/static/khoj.webmanifest", + "fallbackType": "customtabs", + "features": { + "locationDelegation": { + "enabled": true + } + }, + "alphaDependencies": { + "enabled": false + }, + "enableSiteSettingsShortcut": true, + "isChromeOSOnly": false, + "isMetaQuest": false, + "fullScopeUrl": "https://app.khoj.dev/", + "minSdkVersion": 19, + "orientation": "natural", + "fingerprints": [ + { + "name": "signing", + "value": "CC:98:4A:0A:F1:CC:84:26:AC:02:86:49:AA:69:64:B9:5E:63:A3:EF:18:56:EA:CA:13:C1:3A:15:CA:49:77:46" + }, + { + "name": "upload", + "value": "D4:5A:6F:6C:18:28:D2:1C:78:27:92:C6:AC:DB:4C:12:C4:52:A1:88:9B:A1:F5:67:D1:22:FE:A0:0F:B1:AE:92" + } + ], + "additionalTrustedOrigins": [], + "retainedBundles": [], + "appVersion": "4" +} diff --git a/src/interface/emacs/khoj.el b/src/interface/emacs/khoj.el index 21daffa2..83651895 100644 --- a/src/interface/emacs/khoj.el +++ b/src/interface/emacs/khoj.el @@ -434,9 +434,9 @@ Auto invokes setup steps on calling main entrypoint." Append 'TYPE-QUERY' as query parameter in request url. Specify `BOUNDARY' used to separate files in request header." (let ((url-request-method (if force "PUT" "PATCH")) - (url-request-data body) - (url-request-extra-headers `(("content-type" . ,(format "multipart/form-data; boundary=%s" boundary)) - ("Authorization" . ,(format "Bearer %s" khoj-api-key))))) + (url-request-data (encode-coding-string body 'utf-8)) + (url-request-extra-headers `(("content-type" . ,(format "multipart/form-data; boundary=%s" boundary)) + ("Authorization" . ,(encode-coding-string (format "Bearer %s" khoj-api-key) 'utf-8))))) (with-current-buffer (url-retrieve (format "%s/api/content?%s&client=emacs" khoj-server-url type-query) ;; render response from indexing API endpoint on server @@ -668,9 +668,9 @@ Simplified fork of `org-cycle-content' from Emacs 29.1 to work with >=27.1." "Sync call API at PATH with METHOD, query PARAMS and BODY as kv assoc list. Optionally apply CALLBACK with JSON parsed response and CBARGS." (let* ((url-request-method (or method "GET")) - (url-request-extra-headers `(("Authorization" . ,(format "Bearer %s" khoj-api-key)))) - (url-request-extra-headers `(("Authorization" . ,(format "Bearer %s" khoj-api-key)) ("Content-Type" . "application/json"))) - (url-request-data (if body (json-encode body) nil)) + (url-request-extra-headers `(("Authorization" . ,(encode-coding-string (format "Bearer %s" khoj-api-key) 'utf-8)) + ("Content-Type" . "application/json"))) + (url-request-data (if body (encode-coding-string (json-encode body) 'utf-8) nil)) (param-string (url-build-query-string (append params '((client "emacs"))))) (query-url (format "%s%s?%s" khoj-server-url path param-string)) (cbargs (if (and (listp cbargs) (listp (car cbargs))) (car cbargs) cbargs))) ; normalize cbargs to (a b) from ((a b)) if required @@ -689,8 +689,9 @@ Optionally apply CALLBACK with JSON parsed response and CBARGS." "Async call to API at PATH with specified METHOD, query PARAMS and request BODY. Optionally apply CALLBACK with JSON parsed response and CBARGS." (let* ((url-request-method (or method "GET")) - (url-request-extra-headers `(("Authorization" . ,(format "Bearer %s" khoj-api-key)) ("Content-Type" . "application/json"))) - (url-request-data (if body (json-encode body) nil)) + (url-request-extra-headers `(("Authorization" . ,(encode-coding-string (format "Bearer %s" khoj-api-key) 'utf-8)) + ("Content-Type" . "application/json"))) + (url-request-data (if body (encode-coding-string (json-encode body) 'utf-8) nil)) (param-string (url-build-query-string (append params '((client "emacs"))))) (query-url (format "%s%s?%s" khoj-server-url path param-string)) (cbargs (if (and (listp cbargs) (listp (car cbargs))) (car cbargs) cbargs))) ; normalize cbargs to (a b) from ((a b)) if required @@ -716,7 +717,10 @@ Optionally apply CALLBACK with JSON parsed response and CBARGS." Render search results in BUFFER-NAME using CONTENT-TYPE and QUERY. Filter out first similar result if IS-FIND-SIMILAR set." (let* ((rerank (or rerank "false")) - (params `((q ,query) (t ,content-type) (r ,rerank) (n ,khoj-results-count))) + (params `((q ,(encode-coding-string query 'utf-8)) + (t ,content-type) + (r ,rerank) + (n ,khoj-results-count))) (path "/api/search")) (khoj--call-api-async path "GET" diff --git a/src/interface/obsidian/src/chat_view.ts b/src/interface/obsidian/src/chat_view.ts index 18001f47..1dcea196 100644 --- a/src/interface/obsidian/src/chat_view.ts +++ b/src/interface/obsidian/src/chat_view.ts @@ -541,12 +541,10 @@ export class KhojChatView extends KhojPaneView { imageMarkdown += `${message}`; } - if (!images || images.length === 0) { - if (inferredQueries) { - imageMarkdown += "\n\n**Inferred Query**:"; - for (let inferredQuery of inferredQueries) { - imageMarkdown += `\n\n${inferredQuery}`; - } + if (images?.length === 0 && inferredQueries) { + imageMarkdown += "\n\n**Inferred Query**:"; + for (let inferredQuery of inferredQueries) { + imageMarkdown += `\n\n${inferredQuery}`; } } return imageMarkdown; diff --git a/src/interface/web/app/components/chatMessage/chatMessage.tsx b/src/interface/web/app/components/chatMessage/chatMessage.tsx index 49ce4c00..89c3038a 100644 --- a/src/interface/web/app/components/chatMessage/chatMessage.tsx +++ b/src/interface/web/app/components/chatMessage/chatMessage.tsx @@ -397,11 +397,6 @@ const ChatMessage = forwardRef((props, ref) => // Prepare initial message for rendering let message = props.chatMessage.message; - if (props.chatMessage.intent && props.chatMessage.intent.type == "excalidraw") { - message = props.chatMessage.intent["inferred-queries"][0]; - setExcalidrawData(props.chatMessage.message); - } - if (props.chatMessage.excalidrawDiagram) { setExcalidrawData(props.chatMessage.excalidrawDiagram); } diff --git a/src/interface/web/public/assets/icons/khoj_lantern.svg b/src/interface/web/public/assets/icons/khoj_lantern.svg new file mode 100644 index 00000000..d78bddd5 --- /dev/null +++ b/src/interface/web/public/assets/icons/khoj_lantern.svg @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/interface/web/public/assets/icons/khoj_lantern_1200x1200.png b/src/interface/web/public/assets/icons/khoj_lantern_1200x1200.png new file mode 100644 index 00000000..14a8b28b Binary files /dev/null and b/src/interface/web/public/assets/icons/khoj_lantern_1200x1200.png differ diff --git a/src/interface/web/public/assets/icons/khoj_lantern_128x128_dark.png b/src/interface/web/public/assets/icons/khoj_lantern_128x128_dark.png new file mode 100644 index 00000000..8fc673a5 Binary files /dev/null and b/src/interface/web/public/assets/icons/khoj_lantern_128x128_dark.png differ diff --git a/src/interface/web/public/assets/icons/khoj_lantern_512x512.png b/src/interface/web/public/assets/icons/khoj_lantern_512x512.png new file mode 100644 index 00000000..046db170 Binary files /dev/null and b/src/interface/web/public/assets/icons/khoj_lantern_512x512.png differ diff --git a/src/interface/web/public/khoj.webmanifest b/src/interface/web/public/khoj.webmanifest index e0ed3744..29522389 100644 --- a/src/interface/web/public/khoj.webmanifest +++ b/src/interface/web/public/khoj.webmanifest @@ -1,11 +1,18 @@ { - "name": "Khoj", + "id": "https://app.khoj.dev", + "name": "Khoj AI - Get Answers, Create Anything", "short_name": "Khoj", "display": "standalone", "start_url": "/", - "description": "The open, personal AI for your digital brain. You can ask Khoj to draft a message, paint your imagination, find information on the internet and even answer questions from your documents.", + "scope": "/", + "description": "Khoj is your open, personal AI. Gets answers from the internet and your documents. Quickly draft messages, summarize any information, generate beautiful paintings, create personal agents and do deep research.", + "categories": ["productivity", "utilities", "personalization", "education"], "theme_color": "#ffffff", "background_color": "#ffffff", + "orientation": "natural", + "launch_handler": { + "client_mode": ["navigate-existing", "auto"] + }, "icons": [ { "src": "/static/assets/icons/khoj_lantern_128x128.png", @@ -16,6 +23,24 @@ "src": "/static/assets/icons/khoj_lantern_256x256.png", "sizes": "256x256", "type": "image/png" + }, + { + "src": "/static/assets/icons/khoj_lantern_512x512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "any" + }, + { + "src": "/static/assets/icons/khoj_lantern_512x512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "/static/assets/icons/khoj_lantern_1200x1200.png", + "sizes": "1200x1200", + "type": "image/png", + "purpose": "any" } ], "screenshots": [ diff --git a/src/khoj/app/settings.py b/src/khoj/app/settings.py index 020b2b2e..708e11d0 100644 --- a/src/khoj/app/settings.py +++ b/src/khoj/app/settings.py @@ -13,6 +13,8 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ import os from pathlib import Path +from django.templatetags.static import static + from khoj.utils.helpers import in_debug_mode, is_env_var_true # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -72,6 +74,7 @@ INSTALLED_APPS = [ "django.contrib.auth", "django.contrib.contenttypes", "khoj.database.apps.DatabaseConfig", + "unfold", "django.contrib.admin", "django.contrib.sessions", "django.contrib.messages", @@ -195,3 +198,21 @@ APSCHEDULER_DATETIME_FORMAT = "N j, Y, f:s a" # that supports multiple background worker processes instead (e.g. Dramatiq, Celery, Django-RQ, # etc. See: https://djangopackages.org/grids/g/workers-queues-tasks/ for popular options). APSCHEDULER_RUN_NOW_TIMEOUT = 240 # Seconds + +UNFOLD = { + "SITE_TITLE": "Khoj Admin Panel", + "SITE_HEADER": "Khoj Admin Panel", + "SITE_URL": "/", + "SITE_ICON": { + "light": lambda request: static("assets/icons/khoj_lantern_128x128.png"), + "dark": lambda request: static("assets/icons/khoj_lantern_128x128_dark.png"), + }, + "SITE_FAVICONS": [ + { + "rel": "icon", + "sizes": "32x32", + "type": "image/svg+xml", + "href": lambda request: static("assets/icons/khoj_lantern.svg"), + }, + ], +} diff --git a/src/khoj/database/adapters/__init__.py b/src/khoj/database/adapters/__init__.py index 46a65c79..151abc83 100644 --- a/src/khoj/database/adapters/__init__.py +++ b/src/khoj/database/adapters/__init__.py @@ -224,7 +224,9 @@ async def acreate_user_by_phone_number(phone_number: str) -> KhojUser: ) await user.asave() - await Subscription.objects.acreate(user=user, type=Subscription.Type.STANDARD) + user_subscription = await Subscription.objects.filter(user=user).afirst() + if not user_subscription: + await Subscription.objects.acreate(user=user, type=Subscription.Type.STANDARD) return user @@ -296,7 +298,9 @@ async def create_user_by_google_token(token: dict) -> KhojUser: user=user, ) - await Subscription.objects.acreate(user=user, type=Subscription.Type.STANDARD) + user_subscription = await Subscription.objects.filter(user=user).afirst() + if not user_subscription: + await Subscription.objects.acreate(user=user, type=Subscription.Type.STANDARD) return user diff --git a/src/khoj/database/admin.py b/src/khoj/database/admin.py index b71f1f81..73fd5340 100644 --- a/src/khoj/database/admin.py +++ b/src/khoj/database/admin.py @@ -4,11 +4,14 @@ from datetime import date, datetime, timedelta, timezone from apscheduler.job import Job from django.contrib import admin, messages -from django.contrib.auth.admin import UserAdmin +from django.contrib.auth.admin import GroupAdmin as BaseGroupAdmin +from django.contrib.auth.admin import UserAdmin as BaseUserAdmin +from django.contrib.auth.models import Group from django.http import HttpResponse -from django_apscheduler.admin import DjangoJobAdmin +from django_apscheduler.admin import DjangoJobAdmin, DjangoJobExecutionAdmin from django_apscheduler.jobstores import DjangoJobStore -from django_apscheduler.models import DjangoJob +from django_apscheduler.models import DjangoJob, DjangoJobExecution +from unfold import admin as unfold_admin from khoj.database.models import ( Agent, @@ -35,10 +38,8 @@ from khoj.database.models import ( ) from khoj.utils.helpers import ImageIntentType -admin.site.unregister(DjangoJob) - -class KhojDjangoJobAdmin(DjangoJobAdmin): +class KhojDjangoJobAdmin(DjangoJobAdmin, unfold_admin.ModelAdmin): list_display = ( "id", "next_run_time", @@ -62,10 +63,25 @@ class KhojDjangoJobAdmin(DjangoJobAdmin): return queryset, use_distinct +class KhojDjangoJobExecutionAdmin(DjangoJobExecutionAdmin, unfold_admin.ModelAdmin): + pass + + +admin.site.unregister(DjangoJob) admin.site.register(DjangoJob, KhojDjangoJobAdmin) +admin.site.unregister(DjangoJobExecution) +admin.site.register(DjangoJobExecution, KhojDjangoJobExecutionAdmin) -class KhojUserAdmin(UserAdmin): +class GroupAdmin(BaseGroupAdmin, unfold_admin.ModelAdmin): + pass + + +class UserAdmin(BaseUserAdmin, unfold_admin.ModelAdmin): + pass + + +class KhojUserAdmin(UserAdmin, unfold_admin.ModelAdmin): class DateJoinedAfterFilter(admin.SimpleListFilter): title = "Joined after" parameter_name = "joined_after" @@ -137,21 +153,22 @@ class KhojUserAdmin(UserAdmin): get_email_login_url.short_description = "Get email login URL" # type: ignore +admin.site.unregister(Group) admin.site.register(KhojUser, KhojUserAdmin) -admin.site.register(ProcessLock) -admin.site.register(SpeechToTextModelOptions) -admin.site.register(ReflectiveQuestion) -admin.site.register(ClientApplication) -admin.site.register(GithubConfig) -admin.site.register(NotionConfig) -admin.site.register(UserVoiceModelConfig) -admin.site.register(VoiceModelOption) -admin.site.register(UserRequests) +admin.site.register(ProcessLock, unfold_admin.ModelAdmin) +admin.site.register(SpeechToTextModelOptions, unfold_admin.ModelAdmin) +admin.site.register(ReflectiveQuestion, unfold_admin.ModelAdmin) +admin.site.register(ClientApplication, unfold_admin.ModelAdmin) +admin.site.register(GithubConfig, unfold_admin.ModelAdmin) +admin.site.register(NotionConfig, unfold_admin.ModelAdmin) +admin.site.register(UserVoiceModelConfig, unfold_admin.ModelAdmin) +admin.site.register(VoiceModelOption, unfold_admin.ModelAdmin) +admin.site.register(UserRequests, unfold_admin.ModelAdmin) @admin.register(Agent) -class AgentAdmin(admin.ModelAdmin): +class AgentAdmin(unfold_admin.ModelAdmin): list_display = ( "id", "name", @@ -161,7 +178,7 @@ class AgentAdmin(admin.ModelAdmin): @admin.register(Entry) -class EntryAdmin(admin.ModelAdmin): +class EntryAdmin(unfold_admin.ModelAdmin): list_display = ( "id", "created_at", @@ -183,7 +200,7 @@ class EntryAdmin(admin.ModelAdmin): @admin.register(Subscription) -class KhojUserSubscription(admin.ModelAdmin): +class KhojUserSubscription(unfold_admin.ModelAdmin): list_display = ( "id", "user", @@ -195,7 +212,7 @@ class KhojUserSubscription(admin.ModelAdmin): @admin.register(ChatModelOptions) -class ChatModelOptionsAdmin(admin.ModelAdmin): +class ChatModelOptionsAdmin(unfold_admin.ModelAdmin): list_display = ( "id", "chat_model", @@ -206,7 +223,7 @@ class ChatModelOptionsAdmin(admin.ModelAdmin): @admin.register(TextToImageModelConfig) -class TextToImageModelOptionsAdmin(admin.ModelAdmin): +class TextToImageModelOptionsAdmin(unfold_admin.ModelAdmin): list_display = ( "id", "model_name", @@ -216,7 +233,7 @@ class TextToImageModelOptionsAdmin(admin.ModelAdmin): @admin.register(OpenAIProcessorConversationConfig) -class OpenAIProcessorConversationConfigAdmin(admin.ModelAdmin): +class OpenAIProcessorConversationConfigAdmin(unfold_admin.ModelAdmin): list_display = ( "id", "name", @@ -227,7 +244,7 @@ class OpenAIProcessorConversationConfigAdmin(admin.ModelAdmin): @admin.register(SearchModelConfig) -class SearchModelConfigAdmin(admin.ModelAdmin): +class SearchModelConfigAdmin(unfold_admin.ModelAdmin): list_display = ( "id", "name", @@ -238,7 +255,7 @@ class SearchModelConfigAdmin(admin.ModelAdmin): @admin.register(ServerChatSettings) -class ServerChatSettingsAdmin(admin.ModelAdmin): +class ServerChatSettingsAdmin(unfold_admin.ModelAdmin): list_display = ( "chat_default", "chat_advanced", @@ -247,7 +264,7 @@ class ServerChatSettingsAdmin(admin.ModelAdmin): @admin.register(WebScraper) -class WebScraperAdmin(admin.ModelAdmin): +class WebScraperAdmin(unfold_admin.ModelAdmin): list_display = ( "priority", "name", @@ -261,7 +278,7 @@ class WebScraperAdmin(admin.ModelAdmin): @admin.register(Conversation) -class ConversationAdmin(admin.ModelAdmin): +class ConversationAdmin(unfold_admin.ModelAdmin): list_display = ( "id", "user", @@ -360,7 +377,7 @@ class ConversationAdmin(admin.ModelAdmin): @admin.register(UserConversationConfig) -class UserConversationConfigAdmin(admin.ModelAdmin): +class UserConversationConfigAdmin(unfold_admin.ModelAdmin): list_display = ( "id", "get_user_email", diff --git a/src/khoj/database/models/__init__.py b/src/khoj/database/models/__init__.py index 521eee9b..dea678d8 100644 --- a/src/khoj/database/models/__init__.py +++ b/src/khoj/database/models/__init__.py @@ -40,7 +40,7 @@ class CodeContextResult(PydanticBaseModel): class CodeContextData(PydanticBaseModel): code: str - result: CodeContextResult + result: Optional[CodeContextResult] = None class WebPage(PydanticBaseModel): @@ -50,27 +50,27 @@ class WebPage(PydanticBaseModel): class AnswerBox(PydanticBaseModel): - link: str - snippet: str + link: Optional[str] = None + snippet: Optional[str] = None title: str - snippetHighlighted: List[str] + snippetHighlighted: Optional[List[str]] = None class PeopleAlsoAsk(PydanticBaseModel): - link: str - question: str - snippet: str + link: Optional[str] = None + question: Optional[str] = None + snippet: Optional[str] = None title: str class KnowledgeGraph(PydanticBaseModel): - attributes: Dict[str, str] - description: str - descriptionLink: str - descriptionSource: str - imageUrl: str + attributes: Optional[Dict[str, str]] = None + description: Optional[str] = None + descriptionLink: Optional[str] = None + descriptionSource: Optional[str] = None + imageUrl: Optional[str] = None title: str - type: str + type: Optional[str] = None class OrganicContext(PydanticBaseModel): diff --git a/src/khoj/processor/content/markdown/markdown_to_entries.py b/src/khoj/processor/content/markdown/markdown_to_entries.py index c4ee03ef..8d1fbbf4 100644 --- a/src/khoj/processor/content/markdown/markdown_to_entries.py +++ b/src/khoj/processor/content/markdown/markdown_to_entries.py @@ -3,7 +3,7 @@ import re from pathlib import Path from typing import Dict, List, Tuple -import urllib3 +import urllib3.util from khoj.database.models import Entry as DbEntry from khoj.database.models import KhojUser @@ -51,11 +51,11 @@ class MarkdownToEntries(TextToEntries): return num_new_embeddings, num_deleted_embeddings @staticmethod - def extract_markdown_entries(markdown_files, max_tokens=256) -> Tuple[Dict, List[Entry]]: + def extract_markdown_entries(markdown_files: Dict[str, str], max_tokens=256) -> Tuple[Dict[str, str], List[Entry]]: "Extract entries by heading from specified Markdown files" entries: List[str] = [] entry_to_file_map: List[Tuple[str, str]] = [] - file_to_text_map = dict() + file_to_text_map: Dict[str, str] = dict() for markdown_file in markdown_files: try: markdown_content = markdown_files[markdown_file] @@ -128,7 +128,7 @@ class MarkdownToEntries(TextToEntries): return entries, entry_to_file_map @staticmethod - def convert_markdown_entries_to_maps(parsed_entries: List[str], entry_to_file_map) -> List[Entry]: + def convert_markdown_entries_to_maps(parsed_entries: List[str], entry_to_file_map: Dict[str, str]) -> List[Entry]: "Convert each Markdown entries into a dictionary" entries: List[Entry] = [] for parsed_entry in parsed_entries: @@ -139,7 +139,7 @@ class MarkdownToEntries(TextToEntries): # Escape the URL to avoid issues with special characters entry_filename = urllib3.util.parse_url(raw_filename).url else: - entry_filename = str(Path(raw_filename)) + entry_filename = raw_filename heading = parsed_entry.splitlines()[0] if re.search(r"^#+\s", parsed_entry) else "" # Append base filename to compiled entry for context to model @@ -151,7 +151,7 @@ class MarkdownToEntries(TextToEntries): compiled=compiled_entry, raw=parsed_entry, heading=f"{prefix}{heading}", - file=f"{entry_filename}", + file=entry_filename, ) ) diff --git a/src/khoj/processor/content/org_mode/org_to_entries.py b/src/khoj/processor/content/org_mode/org_to_entries.py index cfc17cc0..4b9fe3ae 100644 --- a/src/khoj/processor/content/org_mode/org_to_entries.py +++ b/src/khoj/processor/content/org_mode/org_to_entries.py @@ -208,7 +208,7 @@ class OrgToEntries(TextToEntries): compiled += f"\n {parsed_entry.body}" # Add the sub-entry contents to the entry - entry_compiled += f"{compiled}" + entry_compiled += compiled entry_raw += f"{parsed_entry}" if not entry_heading: entry_heading = heading @@ -218,8 +218,8 @@ class OrgToEntries(TextToEntries): Entry( compiled=entry_compiled, raw=entry_raw, - heading=f"{entry_heading}", - file=f"{entry_to_file_map[parsed_entry]}", + heading=entry_heading, + file=entry_to_file_map[parsed_entry], ) ) diff --git a/src/khoj/processor/conversation/anthropic/anthropic_chat.py b/src/khoj/processor/conversation/anthropic/anthropic_chat.py index e72146e5..688514ca 100644 --- a/src/khoj/processor/conversation/anthropic/anthropic_chat.py +++ b/src/khoj/processor/conversation/anthropic/anthropic_chat.py @@ -160,7 +160,7 @@ def converse_anthropic( generated_images: Optional[list[str]] = None, generated_files: List[FileAttachment] = None, generated_excalidraw_diagram: Optional[str] = None, - additional_context: Optional[List[str]] = None, + program_execution_context: Optional[List[str]] = None, tracer: dict = {}, ): """ @@ -224,7 +224,7 @@ def converse_anthropic( generated_excalidraw_diagram=generated_excalidraw_diagram, generated_files=generated_files, generated_images=generated_images, - additional_program_context=additional_context, + program_execution_context=program_execution_context, ) messages, system_prompt = format_messages_for_anthropic(messages, system_prompt) diff --git a/src/khoj/processor/conversation/google/gemini_chat.py b/src/khoj/processor/conversation/google/gemini_chat.py index fc49e35f..ad10acda 100644 --- a/src/khoj/processor/conversation/google/gemini_chat.py +++ b/src/khoj/processor/conversation/google/gemini_chat.py @@ -170,7 +170,7 @@ def converse_gemini( generated_images: Optional[list[str]] = None, generated_files: List[FileAttachment] = None, generated_excalidraw_diagram: Optional[str] = None, - additional_context: List[str] = None, + program_execution_context: List[str] = None, tracer={}, ): """ @@ -235,7 +235,7 @@ def converse_gemini( generated_excalidraw_diagram=generated_excalidraw_diagram, generated_files=generated_files, generated_images=generated_images, - additional_program_context=additional_context, + program_execution_context=program_execution_context, ) messages, system_prompt = format_messages_for_gemini(messages, system_prompt) diff --git a/src/khoj/processor/conversation/offline/chat_model.py b/src/khoj/processor/conversation/offline/chat_model.py index d493dd30..d81c194c 100644 --- a/src/khoj/processor/conversation/offline/chat_model.py +++ b/src/khoj/processor/conversation/offline/chat_model.py @@ -234,7 +234,7 @@ def converse_offline( model_type=ChatModelOptions.ModelType.OFFLINE, query_files=query_files, generated_files=generated_files, - additional_program_context=additional_context, + program_execution_context=additional_context, ) logger.debug(f"Conversation Context for {model}: {messages_to_print(messages)}") diff --git a/src/khoj/processor/conversation/openai/gpt.py b/src/khoj/processor/conversation/openai/gpt.py index 9cfb9620..c8faf25e 100644 --- a/src/khoj/processor/conversation/openai/gpt.py +++ b/src/khoj/processor/conversation/openai/gpt.py @@ -160,7 +160,7 @@ def converse( generated_images: Optional[list[str]] = None, generated_files: List[FileAttachment] = None, generated_excalidraw_diagram: Optional[str] = None, - additional_context: List[str] = None, + program_execution_context: List[str] = None, tracer: dict = {}, ): """ @@ -226,7 +226,7 @@ def converse( generated_excalidraw_diagram=generated_excalidraw_diagram, generated_files=generated_files, generated_images=generated_images, - additional_program_context=additional_context, + program_execution_context=program_execution_context, ) logger.debug(f"Conversation Context for GPT: {messages_to_print(messages)}") diff --git a/src/khoj/processor/conversation/prompts.py b/src/khoj/processor/conversation/prompts.py index 5e28a912..04ee8b13 100644 --- a/src/khoj/processor/conversation/prompts.py +++ b/src/khoj/processor/conversation/prompts.py @@ -186,9 +186,7 @@ Here is the image you generated based on my query. You can follow-up with a gene generated_diagram_attachment = PromptTemplate.from_template( f""" -The AI has successfully created a diagram based on the user's query and handled the request. Good job! This will be shared with the user. - -AI can follow-up with a general response or summary. Limit to 1-2 sentences. +I've successfully created a diagram based on the user's query. The diagram will automatically be shared with the user. I can follow-up with a general response or summary. Limit to 1-2 sentences. """.strip() ) @@ -1045,12 +1043,11 @@ A: additional_program_context = PromptTemplate.from_template( """ -Here's some additional context about what happened while I was executing this query: +Here are some additional results from the query execution: {context} - """.strip() +""".strip() ) - personality_prompt_safety_expert_lax = PromptTemplate.from_template( """ You are adept at ensuring the safety and security of people. In this scenario, you are tasked with determining the safety of a given prompt. diff --git a/src/khoj/processor/conversation/utils.py b/src/khoj/processor/conversation/utils.py index 64d42716..d68e592e 100644 --- a/src/khoj/processor/conversation/utils.py +++ b/src/khoj/processor/conversation/utils.py @@ -383,7 +383,7 @@ def generate_chatml_messages_with_context( generated_images: Optional[list[str]] = None, generated_files: List[FileAttachment] = None, generated_excalidraw_diagram: str = None, - additional_program_context: List[str] = [], + program_execution_context: List[str] = [], ): """Generate chat messages with appropriate context from previous conversation to send to the chat model""" # Set max prompt size from user config or based on pre-configured for model and machine specs @@ -433,19 +433,20 @@ def generate_chatml_messages_with_context( reconstructed_context_message = ChatMessage(content=message_context, role="user") chatml_messages.insert(0, reconstructed_context_message) - if chat.get("images") and role == "assistant": - # Issue: the assistant role cannot accept an image as a message content, so send it in a separate user message. - file_attachment_message = construct_structured_message( - message=prompts.generated_image_attachment.format(), - images=chat.get("images"), - model_type=model_type, - vision_enabled=vision_enabled, - ) - chatml_messages.append(ChatMessage(content=file_attachment_message, role="user")) - - message_content = construct_structured_message( - chat_message, chat.get("images") if role == "user" else [], model_type, vision_enabled - ) + if chat.get("images"): + if role == "assistant": + # Issue: the assistant role cannot accept an image as a message content, so send it in a separate user message. + file_attachment_message = construct_structured_message( + message=prompts.generated_image_attachment.format(), + images=chat.get("images"), + model_type=model_type, + vision_enabled=vision_enabled, + ) + chatml_messages.append(ChatMessage(content=file_attachment_message, role="user")) + else: + message_content = construct_structured_message( + chat_message, chat.get("images"), model_type, vision_enabled + ) reconstructed_message = ChatMessage(content=message_content, role=role) chatml_messages.insert(0, reconstructed_message) @@ -484,10 +485,10 @@ def generate_chatml_messages_with_context( if generated_excalidraw_diagram: messages.append(ChatMessage(content=prompts.generated_diagram_attachment.format(), role="assistant")) - if additional_program_context: + if program_execution_context: messages.append( ChatMessage( - content=prompts.additional_program_context.format(context="\n".join(additional_program_context)), + content=prompts.additional_program_context.format(context="\n".join(program_execution_context)), role="assistant", ) ) diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index 156658a7..68d77475 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -563,8 +563,7 @@ async def generate_chat_title( raise HTTPException(status_code=404, detail="Conversation not found") new_title = await acreate_title_from_history(request.user.object, conversation=conversation) - - conversation.slug = new_title + conversation.slug = new_title[:200] await conversation.asave() @@ -775,7 +774,7 @@ async def chat( generated_images: List[str] = [] generated_files: List[FileAttachment] = [] generated_excalidraw_diagram: str = None - additional_context_for_llm_response: List[str] = [] + program_execution_context: List[str] = [] if conversation_commands == [ConversationCommand.Default] or is_automated_task: chosen_io = await aget_data_sources_and_output_format( @@ -1081,7 +1080,7 @@ async def chat( async for result in send_event(ChatEvent.STATUS, f"**Ran code snippets**: {len(code_results)}"): yield result except ValueError as e: - additional_context_for_llm_response.append(f"Failed to run code") + program_execution_context.append(f"Failed to run code") logger.warning( f"Failed to use code tool: {e}. Attempting to respond without code results", exc_info=True, @@ -1123,7 +1122,7 @@ async def chat( inferred_queries.append(improved_image_prompt) if generated_image is None or status_code != 200: - additional_context_for_llm_response.append(f"Failed to generate image with {improved_image_prompt}") + program_execution_context.append(f"Failed to generate image with {improved_image_prompt}") async for result in send_event(ChatEvent.STATUS, f"Failed to generate image"): yield result else: @@ -1176,7 +1175,7 @@ async def chat( yield result else: error_message = "Failed to generate diagram. Please try again later." - additional_context_for_llm_response.append( + program_execution_context.append( f"AI attempted to programmatically generate a diagram but failed due to a program issue. Generally, it is able to do so, but encountered a system issue this time. AI can suggest text description or rendering of the diagram or user can try again with a simpler prompt." ) @@ -1209,7 +1208,7 @@ async def chat( generated_images, generated_files, generated_excalidraw_diagram, - additional_context_for_llm_response, + program_execution_context, tracer, ) diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index d54ae4f7..29c44d94 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -1188,7 +1188,7 @@ def generate_chat_response( generated_images: List[str] = None, raw_generated_files: List[FileAttachment] = [], generated_excalidraw_diagram: str = None, - additional_context: List[str] = [], + program_execution_context: List[str] = [], tracer: dict = {}, ) -> Tuple[Union[ThreadedGenerator, Iterator[str]], Dict[str, str]]: # Initialize Variables @@ -1280,7 +1280,7 @@ def generate_chat_response( generated_files=raw_generated_files, generated_images=generated_images, generated_excalidraw_diagram=generated_excalidraw_diagram, - additional_context=additional_context, + program_execution_context=program_execution_context, tracer=tracer, ) @@ -1307,7 +1307,7 @@ def generate_chat_response( generated_files=raw_generated_files, generated_images=generated_images, generated_excalidraw_diagram=generated_excalidraw_diagram, - additional_context=additional_context, + program_execution_context=program_execution_context, tracer=tracer, ) elif conversation_config.model_type == ChatModelOptions.ModelType.GOOGLE: @@ -1333,7 +1333,7 @@ def generate_chat_response( generated_files=raw_generated_files, generated_images=generated_images, generated_excalidraw_diagram=generated_excalidraw_diagram, - additional_context=additional_context, + program_execution_context=program_execution_context, tracer=tracer, ) diff --git a/tests/evals/eval.py b/tests/evals/eval.py index ca9c31f1..eee3656f 100644 --- a/tests/evals/eval.py +++ b/tests/evals/eval.py @@ -163,7 +163,7 @@ def load_gpqa_dataset(): correct_letter = "ABCD"[correct_index] prompt = f""" -Answer the following multiple choice question. Answer should be of the following format: 'Answer: $LETTER' (without quotes) where LETTER is one of ABCD. Think step by step before answering. +Answer the following multiple choice question. Answer should be of the following format: 'Answer: $LETTER' (without quotes) where $LETTER is one of ABCD. Think step by step before answering. {row["Question"]}