Commit Graph

5134 Commits

Author SHA1 Message Date
Debanjum
2423db0186 Remove broken link to deprecated summarize slash command in docs 2025-06-07 13:31:21 -07:00
Debanjum
b6ceaeeffc Execute doc search in parallel using asyncio instead of threadpool 2025-06-07 13:06:49 -07:00
Debanjum
dc1c3561fe Make search type comparison in document search more robust 2025-06-07 12:52:10 -07:00
Debanjum
b9c6252a4a Increase scroll amount on horizontal scroll in computer environment 2025-06-07 11:17:52 -07:00
Debanjum
3fc175d27b Restrict Khoj to work with python <3.13
Python 3.13 not supported by all dependencies yet
2025-06-07 00:44:04 -07:00
Debanjum
1bbf719b04 Apply migrations to db for test runs to install pgvector 2025-06-06 15:47:28 -07:00
Debanjum
77caf183ee Patch update django, next.js dependencies 2025-06-06 15:39:39 -07:00
Debanjum
c4cc70bcc9 Delete file summarization slash commands docs page
File summarization slash commands have been deprecated. Folks can
upload files and ask their questions directly
2025-06-06 15:30:21 -07:00
Debanjum
257c238a88 Improve DB clean up after test runs 2025-06-06 15:09:39 -07:00
Debanjum
6ac1530816 More robustly default to searching all content type 2025-06-06 15:09:39 -07:00
Debanjum
b21706aa45 Drop help, summarize and automation /slash commands from chat api
Clean non useful slash commands to make chat API more maintanable.
- App version, chat model via /help is visible in other parts of the
  UX. Asking help questions with site:docs.khoj.dev filter isn't used
  or known to folks
- /summarize is esoterically tuned. Should be rewritten if add back.
  It wasn't being used by /research already
- Automations can be configured via UX. It wasn't being shown in UX
  already
2025-06-06 15:09:39 -07:00
Debanjum
7f6db526c3 Enforce json for non reasoning anthropic models even in deepthought 2025-06-06 13:28:18 -07:00
Debanjum
d2c7e5516f Fix online chat actor tests, improve offline chat actor tests
The chat actor (and director) tests haven't been looked into in a long
while. They'd gone stale in how they were calling thee functions. And
what was required to run them. Now the online chat actor tests work
again.
2025-06-06 13:28:18 -07:00
Debanjum
2f4160e24b Use single extract questions method across all LLMs for doc search
Using model specific extract questions was an artifact from older
times, with less guidable models.

New changes collate and reuse logic
- Rely on send_message_to_model_wrapper for model specific formatting.
- Use same prompt, context for all LLMs as can handle prompt variation.
- Use response schema enforcer to ensure response consistency across models.

Extract questions (because of its age) was the only tool directly within
each provider code. Put it into helpers to have all the (mini) tools
in one place.
2025-06-06 13:28:18 -07:00
Debanjum
c2cd92a454 [Breaking] Move automation api into new router with consistent routes
- Rename GET /api/automations to GET /api/automation
- Rename POST /api/trigger/automation to POST /api/automation/trigger
- Update calls to the automations API from the web app.
2025-06-06 13:28:18 -07:00
Debanjum
7dfa710cb4 Log invalid automation ids for investigation and clean-up 2025-06-06 13:28:18 -07:00
Debanjum
7d59688729 Move document search tool into helpers module with other tools
Document search (because of its age) was the only tool directly within
an api router. Put it into helpers to have all the (mini) tools in one
place.
2025-06-06 13:28:18 -07:00
Debanjum
1dbe60a8a2 Give more readable name to document search tool 2025-06-06 13:28:18 -07:00
Debanjum
38fa34a861 Simplify ai provider converse methods
- Add context based on information provided rather than conversation
  commands. Let caller handle passing appropriate context to ai
  provider converse methods
2025-06-06 13:28:18 -07:00
Debanjum
bfd4695705 Save conversation in common chat api func instead of each ai provider 2025-06-06 13:28:18 -07:00
Debanjum
e7584bc29d Remove old "Notes" stop keyword for openai api based models
They were when passing notes context to dumber models. Not required
for most models now.
2025-06-06 13:28:18 -07:00
Debanjum
a9b1a26089 Update gunicorn default timeouts, workers. Configure via env vars
Increase timeout to 180 (from 120s previous) and graceful timeout to
90 (from 30s default) to reduce

Increase default gunicorn workers and make it configurable to better
utilize (v)CPUs. This is manually configured (instead of using
multiprocessing.cpu_count()) as VMs/containers may read cpu count of
host machine instead of their VMs/containers.
2025-06-06 13:28:18 -07:00
Debanjum
d16f9f272b Add ability to retry a query from the web app 2025-06-06 13:28:18 -07:00
Debanjum
05d4e19cb8 Pass deep typed chat history for more ergonomic, readable, safe code
The chat dictionary is an artifact from earlier non-db chat history
storage. We've been ensuring new chat messages have valid type before
being written to DB for more than 6 months now.

Move to using the deeply typed chat history helps avoids null refs,
makes code more readable and easier to reason about.

Next Steps:
The current update entangles chat_history written to DB
with any virtual chat history message generated for intermediate
steps. The chat message type written to DB should be decoupled from
type that can be passed to AI model APIs (maybe?).

For now we've made the ChatMessage.message type looser to allow
for list[dict] type (apart from string). But later maybe a good idea
to decouple the chat_history recieved by send_message_to_model from
the chat_history saved to DB (which can then have its stricter type check)
2025-06-04 00:03:14 -07:00
Debanjum
430459a338 Release Khoj version 1.42.1 2025-06-03 21:46:16 -07:00
Debanjum
f6e2eebecc Ignore devcontainer, launch.json from json pre-commit validation
They follow jsonc format and allow comments but fail the json
validator. This is a spurious error and should be ignored
2025-06-03 21:45:11 -07:00
Debanjum
d618f2d650 Raise value error if research pick next tool isn't a dictionary
This will give a better error message with response content than the
failed to get errors from non dictionary response we were getting
earlier.
2025-06-03 21:45:11 -07:00
Debanjum
65d9ad6cb2 Use tool calls to enforce response schema for anthropic models
- Converts response schema into a anthropic tool call definition.
- Works with simple enums without needing to rely on $defs, $refs as
  unsupported by Anthropic API
- Do not force specific tool use as not supported with deep thought

This puts anthropic models on parity with openai, gemini models for
response schema following. Reduces need for complex json response
parsing on khoj end.
2025-06-03 21:05:29 -07:00
Debanjum
d45d9d4cfb Fix malformed user uuids to fix automations [automations data loss]
- **Malformed automations will be dropped**
  They can't run with malformed user uuid anyway.
2025-06-03 21:05:29 -07:00
Debanjum
4892e73323 Remove unsuppported NUL char from file, chat before save to DB 2025-06-03 21:05:29 -07:00
Debanjum
27534f6533 Make query field in context optional
Query field isn't set for all context. The current change was
preventing save to conversation errors when query unset in context.
2025-06-03 19:59:05 -07:00
Debanjum
6e48f4de84 Fix to switch text to speech model via API 2025-06-03 19:59:05 -07:00
Debanjum
63a1a8e91f Try pre-install deps, use custom launch.json for dev container
Previous attempts have not been sufficient. Let's see if this works
2025-06-03 05:00:05 -07:00
Debanjum
29b973e748 Fix building server and web app dev container 2025-06-03 03:46:08 -07:00
Debanjum
50f37d541a Pre-install server deps for fast devcontainer start. Fix dev launch.json
There seems to be a more standard mechanism of specifying launch.json
params for devcontainers. Previous mechanism to write launch.json to
.vscode/launch.json in post creation step does not work.

Improve default launch.json to include khoj admin username, password
with placeholder values to get started with local development faster.

Define dockerfile for devcontainer to pre-built server, web app
dependencies during dev container image creation stage. So install on
dev container startup is sped up as no need to install dependencies.
2025-06-03 01:43:23 -07:00
Debanjum
f3a5fe1ae8 Release Khoj version 1.42.0 2025-06-01 20:52:25 -07:00
Debanjum
82ee0f5451 Revert computer dockerfile startup command to fix operating it 2025-06-01 20:39:58 -07:00
Debanjum
a236288ca9 Fixes to enable dockerized khoj to operate its computer 2025-06-01 19:19:01 -07:00
Debanjum
f95d352eb9 Ensure profile is right border aligned on khoj obsidian settings page
On wide screens it wasn't taking up the header wasn't taking up the
full width, so profile picture could hang out in the middle somewhere.
2025-06-01 17:02:08 -07:00
Debanjum
759ffc46b0 Default to read currently open file when chat with Khoj from Obsidian
Vault is already indexed, this should ease engaging with current
context more easily.
2025-06-01 16:56:19 -07:00
Debanjum
3fb8f77cd5 Fix terminal tool passed to claude 3.7 sonnet as anthropic operator 2025-06-01 16:55:17 -07:00
Debanjum
ddf028f7af Fix khoj computer image name used in docker-compose.yml instead 2025-06-01 16:44:28 -07:00
Debanjum
257bdfadef Setup vscode launch.json and configure pytests for dev container 2025-06-01 16:36:46 -07:00
Debanjum
a98525be01 Add default vscode config for khoj to ease development setup 2025-06-01 16:36:46 -07:00
Debanjum
c6cc709f62 Fix khoj computer image name and only build it once for each arch 2025-06-01 16:36:46 -07:00
Debanjum
a4eb85ac41 Reduce (superficial) xdg dir permissions errors on khoj computer start 2025-06-01 16:36:20 -07:00
sabaimran
e9a107cc06 fix spelling of development 2025-06-01 13:41:39 -07:00
Henri Jamet
dbfac89a0c Major updates to Obsidian Khoj plugin chat interface and editing features (#1109)
## Description
This PR introduces significant improvements to the Obsidian Khoj
plugin's chat interface and editing capabilities, enhancing the overall
user experience and content management functionality.

## Features

### 🔍 Enhanced Communication Mode
I've implemented radio buttons below the chat window for easier
communication mode selection. The modes are now displayed as emojis in
the conversation for a cleaner interface, replacing the previous
text-based system (e.g., /default, /research). I've also documented the
search mode functionality in the help command.

#### Screenshots
- Radio buttons for mode selection
- Emoji display in conversations
![Recording 2025-02-11 at 18 56
10](https://github.com/user-attachments/assets/798d15df-ad32-45bd-b03f-581f6093575a)

### 💬 Revamped Message Interaction
I've redesigned the message buttons with improved spacing and color
coding for better visual differentiation. The new edit button allows
quick message modifications - clicking it removes the conversation up to
that point and copies the message to the input field for easy editing or
retrying questions.

#### Screenshots
- New message styling and color scheme
![Recording 2025-02-11 at 18 44
48](https://github.com/user-attachments/assets/159ece3d-2d80-4583-a7a8-2ef1f253adcc)
- Edit button functionality
![Recording 2025-02-11 at 18 47
52](https://github.com/user-attachments/assets/82ee7221-bc49-4088-9a98-744ef74d1e58)

### 🤖 Advanced Agent Selection System
I've added a new chat creation button with agent selection capability.
Users can now choose from their available agents when starting a new
chat. While agents can't be switched mid-conversation to maintain
context, users can easily start fresh conversations with different
agents.

#### Screenshots
- Agent selection dropdown
![Recording 2025-02-11 at 18 51
27](https://github.com/user-attachments/assets/be4208df-224c-45bf-a5b4-cf0a8068b102)

### 👁️ Real-Time Context Awareness
I've added a button that gives Khoj access to read Obsidian opened tabs.
This allows Khoj to read open notes and track changes in real-time,
maintaining a history of previous versions to provide more contextual
assistance.

#### Screenshots
- Window access toggle
![Recording 2025-02-11 at 18 59
01](https://github.com/user-attachments/assets/b596bfca-f622-41b7-b826-25a8e254d4a2)

### ✏️ Smart Document Editing
Inspired by Cursor IDE's intelligent editing and ChatGPT's Canvas
functionality, I've implemented a first version of a content creation
system we've been discussing. Using a JSON-based modification system,
Khoj can now make precise changes to specific parts of files, with
changes previewed in yellow highlighting before application.
Modification code blocks are neatly organized in collapsible sections
with clear action summaries. While this is just a first step, it's
working remarkably well and I have several ideas for expanding this
functionality to make Khoj an even more powerful content creation
assistant.

#### Screenshots
- JSON modification preview
- Change highlighting system
- Collapsible code blocks
- Accept/cancel controls
![Recording 2025-02-11 at 19 02
32](https://github.com/user-attachments/assets/88826c9e-d0c9-40da-ab78-9976c786aa9e)

---------

Co-authored-by: Debanjum <debanjum@gmail.com>
2025-06-01 10:42:36 +05:30
Debanjum
dee767042e Operate Computer with Khoj Operator (#1190)
## Summary
- Enable Khoj to operate computers: Add experimental computer operator
functionality that allows Khoj to interact with desktop environments,
browsers, and terminals to accomplish complex tasks
- Multi-environment support: Implement computer environments with GUI,
file system, and terminal access. Can control host computer or Docker
container computer

## Key Features
### Computer Operation Capabilities
- Desktop control (screenshots, clicking, typing, keyboard shortcuts)
- File editing and management
- Terminal/bash command execution
- Web browser automation
- Visual feedback via train-of-thought video playback

### Infrastructure & Architecture:
- Docker container (ghcr.io/khoj-ai/computer:latest) with Ubuntu 24.04,
XFCE desktop, VNC access
- Local computer environment support with pyautogui
- Modular operator agent system supporting multiple environment types
- Trajectory compression and context management for long-running tasks

###  Model Integration:
- Anthropic models only (Claude Sonnet 4, Claude 3.7 Sonnet, Claude Opus
4)
- OpenAI and binary operator agents temporarily disabled
- Enhanced caching and context management for operator conversations

### User Experience:
- `/operator` command or just ask Khoj to use operator tool to invoke
computer operation
- Integrate with research mode for extended 30+ minute task execution
- Video of computer operation in train of thought for transparency

### Configuration
- Set `KHOJ_OPERATOR_ENABLED=True` in `docker-compose.yml`
- Requires Anthropic API key
- Computer container runs on port 5900 (VNC)
2025-05-31 22:04:12 -07:00
Debanjum
fa2e370ce6 Document how to enable and use computer operator in operator readme 2025-05-31 21:41:23 -07:00