Commit Graph

4895 Commits

Author SHA1 Message Date
Debanjum
9b767438e2 Update model pricing, default models, context and version metadata 2025-06-10 23:49:04 -07:00
Debanjum
753972997f Enable non-streaming response via openai api to support o3 models 2025-06-10 23:49:04 -07:00
Debanjum
5110a06085 Fix GET agents API to return agent specific chat model
There had been a regression that made all agents display the default
chat model instead of the actual chat model associated with the agent.

This change resolves that issue by prioritizing agent specific chat
model from DB (over user or server chat model).
2025-06-10 15:29:46 -07:00
Debanjum
0cd709caf4 Release Khoj version 1.42.3 2025-06-10 10:20:44 -07:00
Debanjum
313f648bd7 Compile ai message content into single string when using DeepInfra
DeepInfra only accepts assistant message.content of string type
2025-06-10 01:58:43 -07:00
Debanjum
9e73309d01 Add no think tag for qwen models msgs over api when no deepthought 2025-06-10 01:58:43 -07:00
Debanjum
64886cd0dd Fix storing code results on server and rendering them on web app
- Fix code context data type for validation on server. This would
  prevent the chat message from being written to history
- Handle null code results on web app
2025-06-09 23:46:12 -07:00
Debanjum
b1a6e53d77 Fix populating chat message history to continue interrupted research
We now pass deeply typed chat messages throughout the application to
construct tool specific chat history views since 05d4e19cb.

This ChatMessageModel didn't allow intent.query to be unset. But
interrupted research iteration history can have unset query. This
changes allows makes intent.query optional.

It also uses message by user entry to populate user message in tool
chat history views. Using query from khoj intent was an earlier
shortcut used to not have to deal with message by user. But that
doesn't scale to current scenario where turns are not always required
to have a single user, assistant message pair.

Specifically a chat history can now contain multiple user messages
followed by a single khoj message. The new change constructs a chat
history that handles this scenario naturally and makes the code more
readable.

Also now only previous research iterations that completed are
populated. Else they do not serve much purpose.
2025-06-09 23:46:12 -07:00
Debanjum
bd928b9f3c Handle unset agent slug, name. E.g when chat with user created agents 2025-06-09 18:11:25 -07:00
Debanjum
5dd8a9cb24 Only add cache control to last Claude text block if exists, non-empty
Otherwise Claude API throws error
2025-06-08 19:41:21 -07:00
Debanjum
d638a49cd9 Release Khoj version 1.42.2 2025-06-07 13:32:12 -07:00
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