Commit Graph

4965 Commits

Author SHA1 Message Date
Debanjum
48e21d9f0f Release Khoj version 2.0.0-beta.10 2025-07-19 21:32:14 -05:00
Debanjum
e57acf617a Convert websocket rate limiter to async method
Fixes calling websocket rate limiter from async chat_ws method.

Not sure why the issue did not trigger in local setups. Maybe has to
do with gunicorn vs uvicorn / multi-workers setup in prod vs local.
2025-07-19 21:15:51 -05:00
Debanjum
76a1b0b686 Release Khoj version 2.0.0-beta.9 2025-07-19 20:20:50 -05:00
Debanjum
43d7e65a49 Limit chat message interrupt queue size to limit performance impact 2025-07-19 20:16:53 -05:00
Debanjum
749160e38d Validate websocket origin before establishing connection 2025-07-19 20:07:21 -05:00
Debanjum
69a7d332fc Limit number of new websocket connections allowed per user 2025-07-19 20:04:36 -05:00
Debanjum
76ddf8645c Improve rate limit and interrupt messages for user, admin 2025-07-19 19:13:51 -05:00
Debanjum
de7668daec Add websocket chat api to ease bi-directional communication (#1207)
- Add a websocket api endpoint for chat. Reuse most of the existing chat
logic.
- Communicate from web app using the websocket chat api endpoint.
- Pass interrupt messages using websocket to guide research, operator
trajectory
Previously we were using the abort and send new POST /api/chat
mechanism.
This didn't scale well to multi-worker setups as a different worker
could pick up the new interrupt message request.
  Using websocket to send messages in the middle of long running tasks
  should work more naturally.
2025-07-17 18:06:43 -07:00
Debanjum
b90e2367d5 Fix interrupt UX and research when using websocket via web app 2025-07-17 17:09:21 -07:00
Debanjum
0ecd5f497d Show more informative title for semantic search train of thought 2025-07-17 17:09:21 -07:00
Debanjum
7b7b1830b7 Make callers only share new messages to append to chat logs
- Chat history is retrieved and updated with new messages just before
  write. This is to reduce chance of message loss due to conflicting
  writes making last to save to conversation win conflict.
- This was problematic artifact of old code. Removing it should reduce
  conflict surface area.
- Interrupts and live chat could hit this issue due to different reasons
2025-07-17 17:09:18 -07:00
Debanjum
eaed0c839e Use websocket chat api endpoint to communicate from web app
- Use websocket library to handle setup, reconnection from web app
Use react-use-websocket library to handle websocket connection and
reconnection logic. Previously connection wasn't re-established on
disconnects.

- Send interrupt messages with ws to update research, operator trajectory

Previously we were using the abort and send new POST /api/chat
mechanism.

But now we can use the websocket's bi-directional messaging capability
to send users messages in the middle of a research, operator run.

This change should
1. Allow for a faster, more interactive interruption to shift the
research direction without breaking the conversation flow. As
previously we were using the DB to communicate interrupts across
workers, this would take time and feel sluggish on the UX.

2. Be a more robust interrupt mechanism that'll work in multi worker
setups. As same worker is interacted with to send interrupt messages
instead of potentially new worker receiving the POST /api/chat with
the interrupt user message.

On the server we're using an asyncio Queue to pass messages down from
websocket api to researcher via event generator. This can be extended
to pass to other iterative agents like operator.
2025-07-17 17:06:55 -07:00
Debanjum
9f0eff6541 Handle passing interrupt messages from api to chat actors on server 2025-07-17 17:06:55 -07:00
Debanjum
38dd85c91f Add websocket chat api endpoint to ease bi-directional communication 2025-07-17 17:06:55 -07:00
Debanjum
99ed796c00 Release Khoj version 2.0.0-beta.8 2025-07-15 16:42:44 -07:00
Debanjum
0a05a5709e Use agent chat model to generate code instead of default chat model
This is consistent with chat model preference order for other tools
2025-07-15 16:22:29 -07:00
Debanjum
238bd66c42 Fix to map user tool names to equivalent tool sets for research mode
Fix using research tool names instead of slash command tool names
(exposed to user) in research mode conversation history construction.

Map agent input tools to relevant research tools. Previously
using agents with a limited set of tools in research mode reduces
tools available to agent in research mode.

Fix checks to skip tools if not configured.
2025-07-15 16:22:29 -07:00
Debanjum
76ed97d066 Set friendly name for auto loaded chat models during first run
The chat model friendly name field was introduced in a8c47a70f. But
we weren't setting the friendly name for ollama models, which get
automatically loaded on first run.

This broke setting chat model options, server admin settings and
creating new chat pages (at least) as they display the chat model's
friendly name.

This change ensures the friendly name for auto loaded chat models is
set to resolve these issues. We also add a null ref check to web app
model selector as an additional safeguard to prevent new chat page
crash due to missing friendly name going forward.

Resolves #1208
2025-07-15 14:27:04 -07:00
Debanjum
0a06f5b41a Release Khoj version 2.0.0-beta.7 2025-07-11 00:04:56 -07:00
Debanjum
d42176fa7e Drop tool call, result without tool id on call to Anthropic, Openai APIs 2025-07-11 00:00:05 -07:00
Debanjum
d27aac7f13 Suppress non-actionable pdf indexing warning from logs 2025-07-11 00:00:05 -07:00
Debanjum
05176cd62b Log dropping messages with invalid content as warnings, not errors
They are expected when conversation got interrupted.
2025-07-11 00:00:05 -07:00
Debanjum
b2952236c4 Log conversation id to help troubleshoot errors faster 2025-07-10 23:56:42 -07:00
Debanjum
25db59e49c Fix to return openai formatted messages in the correct order
We'd reversed the formatting of openai messages to drop invalid
messages without affecting the other messages being appended . But we
need to reverse the final formatted list to return in the right order.
2025-07-10 23:56:22 -07:00
Debanjum
c8ec29551f Drop invalid messages in reverse order to continue interrupted chats
Previously
- message with invalid content were getting dropped in normal order
  which would change the item index being iterated for gemini and
  anthropic models
- messages with empty content weren't getting dropped for openai
  compatible api models. While openai api is resilient to this, it's
  better to drop these invalid messages as other openai compatible
  APIs may not handle this.

We see messages with empty or no content when chat gets interrupted
due to disconnections, interrupt messages or explicit aborts by user.

This changes should now drop invalid messages and not mess formatting
of the other messages in a conversation. It should allow continuing
interrupted conversations with any ai model.
2025-07-10 22:39:52 -07:00
Debanjum
f1a3ddf2ca Release Khoj version 2.0.0-beta.6 2025-07-10 13:41:06 -07:00
Debanjum
7b637d3432 Use document style ux when print conversations to pdf
Inspired by my previous turnstyle ux explorations.

But basically user message becomes section title and khoj message
becomes section body with the timestamp being used a section title,
body divider.
2025-07-10 13:27:04 -07:00
Debanjum
c28e90f388 Revert to use standard 1.0 temperature for gemini models
Using temp of 1.2 didn't help eliminate the repetition loops the
gemini models go into sometimes.
2025-07-09 18:22:05 -07:00
Debanjum
b763dbfb2b Timeout web search and webpage read requests to providers 2025-07-09 18:12:07 -07:00
Debanjum
1988a8d023 Fix to delete agent by slug in DB via API 2025-07-09 18:12:07 -07:00
Debanjum
69336565b1 Do not show research mode tools as slash commands options on clients
These are tools meant for the research agent, not for users to use.
2025-07-09 18:12:07 -07:00
Debanjum
cc6da4c440 Drop unsupported additionalProperties field from gemini tool definitions 2025-07-09 18:06:40 -07:00
Debanjum
3141035f48 Handle unexpected chunks streamed from Openai (compatible) APIs 2025-07-09 17:54:42 -07:00
Debanjum
a601cca79b Handle cases where no organic online search results found
Previous organic results enumerator only handled the scenario where
organic key wasn't present in online search results.

It did not handle the case where there were no organic online search
results.
2025-07-09 00:25:10 -07:00
Debanjum
f2b86aa7c8 Release Khoj version 2.0.0-beta.5 2025-07-08 23:45:29 -07:00
Debanjum
0f0cfba624 Ignore vscode settings.json from pre-commit json check
Vscode settings.json follows jsonc (json with comments) format
2025-07-08 23:27:10 -07:00
Debanjum
f0513cbbb1 Fix to run new automation api tests in ci 2025-07-08 23:27:09 -07:00
Debanjum
c144aa9c90 Handle automation calling url of both url and string type
Calling url can be of url type in production but locally it is of
string type. Unclear why. But this change should mitigate the issue
for now.
2025-07-08 21:10:54 -07:00
Debanjum
fad6a638bd Release Khoj version 2.0.0-beta.4 2025-07-08 19:34:52 -07:00
Debanjum
8d9e75f580 Fix automation url parsing, response handling. Test automations api
- Methods calling send_message_to_model_wrapper_sync handn't been
  update to handle the function returning new ResponseWithThought
- Store, load request.url to DB as, from string to avoid serialization
  issues
2025-07-08 17:40:19 -07:00
Debanjum
254207b010 Make chats print friendly to share via print to PDF etc. from browser
Add print specific styling to hide side panels and chat input footers.
Add heading with khoj logo, conversation title, agent and date.
2025-07-08 12:20:19 -07:00
Debanjum
8fb38d9e1e Make vscode pylint only analyse khoj server directory for efficiency 2025-07-08 12:20:19 -07:00
Debanjum
9a215141f0 Release Khoj version 2.0.0-beta.3 2025-07-06 12:50:27 -07:00
Debanjum
da9a78e79b Make URI field optional for now to handle previously saved documents
For files not synced after the previous release, context uri is unset.
This results in failure to save chat messages that retrieve documents
as the uri field cannot be unset so pre save validation fails.

We'd use a db migration to handle this but this is a quick mitigation
for now.
2025-07-06 12:49:07 -07:00
Debanjum
bc6bbb4c96 Release Khoj version 2.0.0-beta.2 2025-07-06 12:10:32 -07:00
Debanjum
4c33d1a526 Fallback to file based URI when document context URI is unset
For files not synced after the previous release, context uri is unset.
This results in failure to save chat messages that retrieve documents
as the uri field cannot be unset so pre save validation fails
2025-07-06 12:06:02 -07:00
Debanjum
9dc146bb08 Bump rapidocr dependency version 2025-07-06 12:06:02 -07:00
Debanjum
b27ba1d24b Early init chat_history in chat api to avoid unbound in edge case
Monitor disconnect can trigger earlier than chat history is
initialized. This can cause unbound chat history exception.
2025-07-06 12:06:02 -07:00
Debanjum
8cd2a1a961 Release Khoj version 2.0.0-beta.1 2025-07-06 10:39:56 -07:00
Debanjum
6bda8dc20b Fix file upload size limit client test after max upload bump 2025-07-06 10:24:44 -07:00