khoj 1.42.1.dev10__py3-none-any.whl → 1.42.2.dev16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- khoj/configure.py +2 -0
- khoj/database/adapters/__init__.py +9 -7
- khoj/database/models/__init__.py +9 -9
- khoj/interface/compiled/404/index.html +2 -2
- khoj/interface/compiled/_next/static/chunks/7127-79a3af5138960272.js +1 -0
- khoj/interface/compiled/_next/static/chunks/{5138-2cce449fd2454abf.js → 7211-7fedd2ee3655239c.js} +1 -1
- khoj/interface/compiled/_next/static/chunks/app/automations/page-ef89ac958e78aa81.js +1 -0
- khoj/interface/compiled/_next/static/chunks/app/chat/page-db0fbea54ccea62f.js +1 -0
- khoj/interface/compiled/_next/static/chunks/app/share/chat/{page-9a167dc9b5fcd464.js → page-da90c78180a86040.js} +1 -1
- khoj/interface/compiled/_next/static/chunks/{webpack-964e8ed3380daff1.js → webpack-0f15e6b51732b337.js} +1 -1
- khoj/interface/compiled/_next/static/css/{9c223d337a984468.css → 7017ee76c2f2cd87.css} +1 -1
- khoj/interface/compiled/_next/static/css/9a460202d29476e5.css +1 -0
- khoj/interface/compiled/agents/index.html +2 -2
- khoj/interface/compiled/agents/index.txt +1 -1
- khoj/interface/compiled/automations/index.html +2 -2
- khoj/interface/compiled/automations/index.txt +2 -2
- khoj/interface/compiled/chat/index.html +2 -2
- khoj/interface/compiled/chat/index.txt +2 -2
- khoj/interface/compiled/index.html +2 -2
- khoj/interface/compiled/index.txt +1 -1
- khoj/interface/compiled/search/index.html +2 -2
- khoj/interface/compiled/search/index.txt +1 -1
- khoj/interface/compiled/settings/index.html +2 -2
- khoj/interface/compiled/settings/index.txt +1 -1
- khoj/interface/compiled/share/chat/index.html +2 -2
- khoj/interface/compiled/share/chat/index.txt +2 -2
- khoj/processor/conversation/anthropic/anthropic_chat.py +19 -134
- khoj/processor/conversation/anthropic/utils.py +1 -1
- khoj/processor/conversation/google/gemini_chat.py +20 -141
- khoj/processor/conversation/offline/chat_model.py +23 -153
- khoj/processor/conversation/openai/gpt.py +14 -128
- khoj/processor/conversation/prompts.py +2 -63
- khoj/processor/conversation/utils.py +94 -89
- khoj/processor/image/generate.py +16 -11
- khoj/processor/operator/__init__.py +2 -3
- khoj/processor/operator/operator_agent_binary.py +11 -11
- khoj/processor/tools/online_search.py +9 -3
- khoj/processor/tools/run_code.py +5 -5
- khoj/routers/api.py +5 -527
- khoj/routers/api_automation.py +243 -0
- khoj/routers/api_chat.py +48 -129
- khoj/routers/helpers.py +371 -121
- khoj/routers/research.py +11 -43
- khoj/utils/helpers.py +0 -6
- {khoj-1.42.1.dev10.dist-info → khoj-1.42.2.dev16.dist-info}/METADATA +1 -1
- {khoj-1.42.1.dev10.dist-info → khoj-1.42.2.dev16.dist-info}/RECORD +51 -50
- khoj/interface/compiled/_next/static/chunks/7127-d3199617463d45f0.js +0 -1
- khoj/interface/compiled/_next/static/chunks/app/automations/page-465741d9149dfd48.js +0 -1
- khoj/interface/compiled/_next/static/chunks/app/chat/page-898079bcea5376f4.js +0 -1
- khoj/interface/compiled/_next/static/css/fca983d49c3dd1a3.css +0 -1
- /khoj/interface/compiled/_next/static/{2niR8lV9_OpGs1vdb2yMp → OTsOjbrtuaYMukpuJS4sy}/_buildManifest.js +0 -0
- /khoj/interface/compiled/_next/static/{2niR8lV9_OpGs1vdb2yMp → OTsOjbrtuaYMukpuJS4sy}/_ssgManifest.js +0 -0
- {khoj-1.42.1.dev10.dist-info → khoj-1.42.2.dev16.dist-info}/WHEEL +0 -0
- {khoj-1.42.1.dev10.dist-info → khoj-1.42.2.dev16.dist-info}/entry_points.txt +0 -0
- {khoj-1.42.1.dev10.dist-info → khoj-1.42.2.dev16.dist-info}/licenses/LICENSE +0 -0
khoj/processor/image/generate.py
CHANGED
@@ -10,7 +10,12 @@ from google import genai
|
|
10
10
|
from google.genai import types as gtypes
|
11
11
|
|
12
12
|
from khoj.database.adapters import ConversationAdapters
|
13
|
-
from khoj.database.models import
|
13
|
+
from khoj.database.models import (
|
14
|
+
Agent,
|
15
|
+
ChatMessageModel,
|
16
|
+
KhojUser,
|
17
|
+
TextToImageModelConfig,
|
18
|
+
)
|
14
19
|
from khoj.routers.helpers import ChatEvent, generate_better_image_prompt
|
15
20
|
from khoj.routers.storage import upload_generated_image_to_bucket
|
16
21
|
from khoj.utils import state
|
@@ -23,7 +28,7 @@ logger = logging.getLogger(__name__)
|
|
23
28
|
async def text_to_image(
|
24
29
|
message: str,
|
25
30
|
user: KhojUser,
|
26
|
-
|
31
|
+
chat_history: List[ChatMessageModel],
|
27
32
|
location_data: LocationData,
|
28
33
|
references: List[Dict[str, Any]],
|
29
34
|
online_results: Dict[str, Any],
|
@@ -46,14 +51,14 @@ async def text_to_image(
|
|
46
51
|
return
|
47
52
|
|
48
53
|
text2image_model = text_to_image_config.model_name
|
49
|
-
|
50
|
-
for chat in
|
51
|
-
if chat
|
52
|
-
|
53
|
-
|
54
|
-
elif chat
|
55
|
-
|
56
|
-
|
54
|
+
chat_history_str = ""
|
55
|
+
for chat in chat_history[-4:]:
|
56
|
+
if chat.by == "khoj" and chat.intent and chat.intent.type in ["remember", "reminder"]:
|
57
|
+
chat_history_str += f"Q: {chat.intent.query or ''}\n"
|
58
|
+
chat_history_str += f"A: {chat.message}\n"
|
59
|
+
elif chat.by == "khoj" and chat.images:
|
60
|
+
chat_history_str += f"Q: {chat.intent.query}\n"
|
61
|
+
chat_history_str += f"A: Improved Prompt: {chat.intent.inferred_queries[0]}\n"
|
57
62
|
|
58
63
|
if send_status_func:
|
59
64
|
async for event in send_status_func("**Enhancing the Painting Prompt**"):
|
@@ -63,7 +68,7 @@ async def text_to_image(
|
|
63
68
|
# Use the user's message, chat history, and other context
|
64
69
|
image_prompt = await generate_better_image_prompt(
|
65
70
|
message,
|
66
|
-
|
71
|
+
chat_history_str,
|
67
72
|
location_data=location_data,
|
68
73
|
note_references=references,
|
69
74
|
online_results=online_results,
|
@@ -5,10 +5,9 @@ import os
|
|
5
5
|
from typing import Callable, List, Optional
|
6
6
|
|
7
7
|
from khoj.database.adapters import AgentAdapters, ConversationAdapters
|
8
|
-
from khoj.database.models import Agent, ChatModel, KhojUser
|
8
|
+
from khoj.database.models import Agent, ChatMessageModel, ChatModel, KhojUser
|
9
9
|
from khoj.processor.conversation.utils import (
|
10
10
|
OperatorRun,
|
11
|
-
construct_chat_history,
|
12
11
|
construct_chat_history_for_operator,
|
13
12
|
)
|
14
13
|
from khoj.processor.operator.operator_actions import *
|
@@ -34,7 +33,7 @@ logger = logging.getLogger(__name__)
|
|
34
33
|
async def operate_environment(
|
35
34
|
query: str,
|
36
35
|
user: KhojUser,
|
37
|
-
conversation_log:
|
36
|
+
conversation_log: List[ChatMessageModel],
|
38
37
|
location_data: LocationData,
|
39
38
|
previous_trajectory: Optional[OperatorRun] = None,
|
40
39
|
environment_type: EnvironmentType = EnvironmentType.COMPUTER,
|
@@ -4,7 +4,7 @@ from datetime import datetime
|
|
4
4
|
from textwrap import dedent
|
5
5
|
from typing import List, Optional
|
6
6
|
|
7
|
-
from khoj.database.models import ChatModel
|
7
|
+
from khoj.database.models import ChatMessageModel, ChatModel
|
8
8
|
from khoj.processor.conversation.utils import (
|
9
9
|
AgentMessage,
|
10
10
|
OperatorRun,
|
@@ -119,13 +119,13 @@ class BinaryOperatorAgent(OperatorAgent):
|
|
119
119
|
query_screenshot = self._get_message_images(current_message)
|
120
120
|
|
121
121
|
# Construct input for visual reasoner history
|
122
|
-
visual_reasoner_history =
|
122
|
+
visual_reasoner_history = self._format_message_for_api(self.messages)
|
123
123
|
try:
|
124
124
|
natural_language_action = await send_message_to_model_wrapper(
|
125
125
|
query=query_text,
|
126
126
|
query_images=query_screenshot,
|
127
127
|
system_message=reasoning_system_prompt,
|
128
|
-
|
128
|
+
chat_history=visual_reasoner_history,
|
129
129
|
agent_chat_model=self.reasoning_model,
|
130
130
|
tracer=self.tracer,
|
131
131
|
)
|
@@ -238,11 +238,11 @@ class BinaryOperatorAgent(OperatorAgent):
|
|
238
238
|
|
239
239
|
async def summarize(self, env_state: EnvState, summarize_prompt: str = None) -> str:
|
240
240
|
summarize_prompt = summarize_prompt or self.summarize_prompt
|
241
|
-
conversation_history =
|
241
|
+
conversation_history = self._format_message_for_api(self.messages)
|
242
242
|
try:
|
243
243
|
summary = await send_message_to_model_wrapper(
|
244
244
|
query=summarize_prompt,
|
245
|
-
|
245
|
+
chat_history=conversation_history,
|
246
246
|
agent_chat_model=self.reasoning_model,
|
247
247
|
tracer=self.tracer,
|
248
248
|
)
|
@@ -296,14 +296,14 @@ class BinaryOperatorAgent(OperatorAgent):
|
|
296
296
|
images = [item["image_url"]["url"] for item in message.content if item["type"] == "image_url"]
|
297
297
|
return images
|
298
298
|
|
299
|
-
def _format_message_for_api(self, messages: list[AgentMessage]) -> List[
|
299
|
+
def _format_message_for_api(self, messages: list[AgentMessage]) -> List[ChatMessageModel]:
|
300
300
|
"""Format operator agent messages into the Khoj conversation history format."""
|
301
301
|
formatted_messages = [
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
302
|
+
ChatMessageModel(
|
303
|
+
message=self._get_message_text(message),
|
304
|
+
images=self._get_message_images(message),
|
305
|
+
by="you" if message.role in ["user", "environment"] else message.role,
|
306
|
+
)
|
307
307
|
for message in messages
|
308
308
|
]
|
309
309
|
return formatted_messages
|
@@ -10,7 +10,13 @@ from bs4 import BeautifulSoup
|
|
10
10
|
from markdownify import markdownify
|
11
11
|
|
12
12
|
from khoj.database.adapters import ConversationAdapters
|
13
|
-
from khoj.database.models import
|
13
|
+
from khoj.database.models import (
|
14
|
+
Agent,
|
15
|
+
ChatMessageModel,
|
16
|
+
KhojUser,
|
17
|
+
ServerChatSettings,
|
18
|
+
WebScraper,
|
19
|
+
)
|
14
20
|
from khoj.processor.conversation import prompts
|
15
21
|
from khoj.routers.helpers import (
|
16
22
|
ChatEvent,
|
@@ -59,7 +65,7 @@ OLOSTEP_QUERY_PARAMS = {
|
|
59
65
|
|
60
66
|
async def search_online(
|
61
67
|
query: str,
|
62
|
-
conversation_history:
|
68
|
+
conversation_history: List[ChatMessageModel],
|
63
69
|
location: LocationData,
|
64
70
|
user: KhojUser,
|
65
71
|
send_status_func: Optional[Callable] = None,
|
@@ -361,7 +367,7 @@ async def search_with_serper(query: str, location: LocationData) -> Tuple[str, D
|
|
361
367
|
|
362
368
|
async def read_webpages(
|
363
369
|
query: str,
|
364
|
-
conversation_history:
|
370
|
+
conversation_history: List[ChatMessageModel],
|
365
371
|
location: LocationData,
|
366
372
|
user: KhojUser,
|
367
373
|
send_status_func: Optional[Callable] = None,
|
khoj/processor/tools/run_code.py
CHANGED
@@ -20,7 +20,7 @@ from tenacity import (
|
|
20
20
|
)
|
21
21
|
|
22
22
|
from khoj.database.adapters import FileObjectAdapters
|
23
|
-
from khoj.database.models import Agent, FileObject, KhojUser
|
23
|
+
from khoj.database.models import Agent, ChatMessageModel, FileObject, KhojUser
|
24
24
|
from khoj.processor.conversation import prompts
|
25
25
|
from khoj.processor.conversation.utils import (
|
26
26
|
ChatEvent,
|
@@ -50,7 +50,7 @@ class GeneratedCode(NamedTuple):
|
|
50
50
|
|
51
51
|
async def run_code(
|
52
52
|
query: str,
|
53
|
-
conversation_history:
|
53
|
+
conversation_history: List[ChatMessageModel],
|
54
54
|
context: str,
|
55
55
|
location_data: LocationData,
|
56
56
|
user: KhojUser,
|
@@ -116,7 +116,7 @@ async def run_code(
|
|
116
116
|
|
117
117
|
async def generate_python_code(
|
118
118
|
q: str,
|
119
|
-
|
119
|
+
chat_history: List[ChatMessageModel],
|
120
120
|
context: str,
|
121
121
|
location_data: LocationData,
|
122
122
|
user: KhojUser,
|
@@ -127,7 +127,7 @@ async def generate_python_code(
|
|
127
127
|
) -> GeneratedCode:
|
128
128
|
location = f"{location_data}" if location_data else "Unknown"
|
129
129
|
username = prompts.user_name.format(name=user.get_full_name()) if user.get_full_name() else ""
|
130
|
-
|
130
|
+
chat_history_str = construct_chat_history(chat_history)
|
131
131
|
|
132
132
|
utc_date = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d")
|
133
133
|
personality_context = (
|
@@ -143,7 +143,7 @@ async def generate_python_code(
|
|
143
143
|
|
144
144
|
code_generation_prompt = prompts.python_code_generation_prompt.format(
|
145
145
|
query=q,
|
146
|
-
chat_history=
|
146
|
+
chat_history=chat_history_str,
|
147
147
|
context=context,
|
148
148
|
has_network_access=network_access_context,
|
149
149
|
current_date=utc_date,
|