khoj 1.30.11.dev64__py3-none-any.whl → 1.30.11.dev68__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/interface/compiled/404/index.html +1 -1
- khoj/interface/compiled/_next/static/chunks/app/agents/layout-f2ea2b26fc0e78b1.js +1 -0
- khoj/interface/compiled/_next/static/chunks/app/agents/{page-8eead7920b0ff92a.js → page-2ffa7560aebff9a1.js} +1 -1
- khoj/interface/compiled/_next/static/chunks/app/automations/{page-b5800b5286306140.js → page-b0a6a6ed2267c1a2.js} +1 -1
- khoj/interface/compiled/_next/static/chunks/app/chat/{page-d7d2ab93e519f0b2.js → page-02f8616bba3e449e.js} +1 -1
- khoj/interface/compiled/_next/static/chunks/app/{page-3c32ad5472f75965.js → page-3ffd8f0934b896f3.js} +1 -1
- khoj/interface/compiled/_next/static/chunks/app/search/{page-faa998c71eb7ca8e.js → page-059f237514f77628.js} +1 -1
- khoj/interface/compiled/_next/static/chunks/app/settings/{page-cbe7f56b1f87d77a.js → page-32e9423bede5b4a1.js} +1 -1
- khoj/interface/compiled/_next/static/chunks/app/share/chat/layout-f662c9e5091603cf.js +1 -0
- khoj/interface/compiled/_next/static/chunks/app/share/chat/{page-cd5757199539bbf2.js → page-0b8d90dc57dbc1d8.js} +1 -1
- khoj/interface/compiled/_next/static/chunks/{webpack-616f0694bfe6f6c1.js → webpack-69440f9c6674390f.js} +1 -1
- khoj/interface/compiled/_next/static/css/34f2d177dfee2dd8.css +1 -0
- khoj/interface/compiled/_next/static/css/4cae6c0e5c72fb2d.css +1 -0
- khoj/interface/compiled/agents/index.html +1 -1
- khoj/interface/compiled/agents/index.txt +2 -2
- khoj/interface/compiled/automations/index.html +1 -1
- khoj/interface/compiled/automations/index.txt +2 -2
- khoj/interface/compiled/chat/index.html +1 -1
- khoj/interface/compiled/chat/index.txt +2 -2
- khoj/interface/compiled/index.html +1 -1
- khoj/interface/compiled/index.txt +2 -2
- khoj/interface/compiled/search/index.html +1 -1
- khoj/interface/compiled/search/index.txt +2 -2
- khoj/interface/compiled/settings/index.html +1 -1
- khoj/interface/compiled/settings/index.txt +2 -2
- khoj/interface/compiled/share/chat/index.html +1 -1
- khoj/interface/compiled/share/chat/index.txt +2 -2
- khoj/processor/conversation/anthropic/anthropic_chat.py +2 -4
- khoj/processor/conversation/google/gemini_chat.py +2 -4
- khoj/processor/conversation/offline/chat_model.py +3 -1
- khoj/processor/conversation/openai/gpt.py +3 -5
- khoj/processor/conversation/prompts.py +33 -21
- khoj/processor/conversation/utils.py +31 -30
- khoj/routers/api_chat.py +14 -1
- khoj/routers/helpers.py +11 -9
- {khoj-1.30.11.dev64.dist-info → khoj-1.30.11.dev68.dist-info}/METADATA +2 -2
- {khoj-1.30.11.dev64.dist-info → khoj-1.30.11.dev68.dist-info}/RECORD +42 -42
- khoj/interface/compiled/_next/static/chunks/app/agents/layout-1878cc328ea380bd.js +0 -1
- khoj/interface/compiled/_next/static/chunks/app/share/chat/layout-592e8c470f2c2084.js +0 -1
- khoj/interface/compiled/_next/static/css/592ca99f5122e75a.css +0 -1
- khoj/interface/compiled/_next/static/css/9c4221ae0779cc04.css +0 -1
- /khoj/interface/compiled/_next/static/{67DcUiU9MqkM1fhksWunh → K_yMtbMBGMl0Y_znpf-jV}/_buildManifest.js +0 -0
- /khoj/interface/compiled/_next/static/{67DcUiU9MqkM1fhksWunh → K_yMtbMBGMl0Y_znpf-jV}/_ssgManifest.js +0 -0
- {khoj-1.30.11.dev64.dist-info → khoj-1.30.11.dev68.dist-info}/WHEEL +0 -0
- {khoj-1.30.11.dev64.dist-info → khoj-1.30.11.dev68.dist-info}/entry_points.txt +0 -0
- {khoj-1.30.11.dev64.dist-info → khoj-1.30.11.dev68.dist-info}/licenses/LICENSE +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
2:I[66513,[],"ClientPageRoot"]
|
2
|
-
3:I[5506,["3954","static/chunks/d3ac728e-a9e3522eef9b6b28.js","3072","static/chunks/3072-be830e4f8412b9d2.js","4752","static/chunks/4752-554a3db270186ce3.js","7592","static/chunks/7592-a09c39a38e60634b.js","3690","static/chunks/3690-51312931ba1eae30.js","3463","static/chunks/3463-081c031e873b7966.js","1603","static/chunks/1603-13cef426e0e650ec.js","8423","static/chunks/8423-1dda16bc56236523.js","5538","static/chunks/5538-0ea2d3944ca051e1.js","3111","static/chunks/app/share/chat/page-
|
2
|
+
3:I[5506,["3954","static/chunks/d3ac728e-a9e3522eef9b6b28.js","3072","static/chunks/3072-be830e4f8412b9d2.js","4752","static/chunks/4752-554a3db270186ce3.js","7592","static/chunks/7592-a09c39a38e60634b.js","3690","static/chunks/3690-51312931ba1eae30.js","3463","static/chunks/3463-081c031e873b7966.js","1603","static/chunks/1603-13cef426e0e650ec.js","8423","static/chunks/8423-1dda16bc56236523.js","5538","static/chunks/5538-0ea2d3944ca051e1.js","3111","static/chunks/app/share/chat/page-0b8d90dc57dbc1d8.js"],"default",1]
|
3
3
|
4:I[39275,[],""]
|
4
4
|
5:I[61343,[],""]
|
5
|
-
0:["
|
5
|
+
0:["K_yMtbMBGMl0Y_znpf-jV",[[["",{"children":["share",{"children":["chat",{"children":["__PAGE__",{}]}]}]},"$undefined","$undefined",true],["",{"children":["share",{"children":["chat",{"children":["__PAGE__",{},[["$L1",["$","$L2",null,{"props":{"params":{},"searchParams":{}},"Component":"$3"}],[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/3cf13271869a4aeb.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/_next/static/css/34f2d177dfee2dd8.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","2",{"rel":"stylesheet","href":"/_next/static/css/1f293605f2871853.css","precedence":"next","crossOrigin":"$undefined"}]]],null],null]},[[null,["$","html",null,{"lang":"en","className":"__variable_f36179 __variable_702545","children":[["$","meta",null,{"httpEquiv":"Content-Security-Policy","content":"default-src 'self' https://assets.khoj.dev; media-src * blob:; script-src 'self' https://assets.khoj.dev https://app.chatwoot.com 'unsafe-inline' 'unsafe-eval'; connect-src 'self' blob: https://ipapi.co/json ws://localhost:42110; style-src 'self' https://assets.khoj.dev 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob: https://*.khoj.dev https://*.googleusercontent.com https://*.google.com/ https://*.gstatic.com; font-src 'self' https://assets.khoj.dev https://fonts.gstatic.com; child-src 'self' https://app.chatwoot.com; object-src 'none';"}],["$","body",null,{"children":[["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","share","children","chat","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}],["$","script",null,{"dangerouslySetInnerHTML":{"__html":"window.EXCALIDRAW_ASSET_PATH = 'https://assets.khoj.dev/@excalidraw/excalidraw/dist/';"}}]]}]]}]],null],null]},[null,["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children","share","children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined"}]],null]},[[[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/089de1d8526b96e9.css","precedence":"next","crossOrigin":"$undefined"}],["$","link","1",{"rel":"stylesheet","href":"/_next/static/css/3c34171b174cc381.css","precedence":"next","crossOrigin":"$undefined"}]],["$","html",null,{"lang":"en","className":"__variable_f36179 __variable_702545","children":[["$","meta",null,{"httpEquiv":"Content-Security-Policy","content":"default-src 'self' https://assets.khoj.dev; media-src * blob:; script-src 'self' https://assets.khoj.dev https://app.chatwoot.com 'unsafe-inline' 'unsafe-eval'; connect-src 'self' blob: https://ipapi.co/json ws://localhost:42110; style-src 'self' https://assets.khoj.dev 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob: https://*.khoj.dev https://*.googleusercontent.com https://*.google.com/ https://*.gstatic.com; font-src 'self' https://assets.khoj.dev https://fonts.gstatic.com; child-src 'self' https://app.chatwoot.com; object-src 'none';"}],["$","body",null,{"children":["$","$L4",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L5",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[]}]}]]}]],null],null],["$L6",null]]]]
|
6
6
|
6:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"Khoj AI - Chat"}],["$","meta","3",{"name":"description","content":"Use this page to view a chat with Khoj AI."}],["$","link","4",{"rel":"manifest","href":"/static/khoj.webmanifest","crossOrigin":"use-credentials"}],["$","meta","5",{"property":"og:title","content":"Khoj AI"}],["$","meta","6",{"property":"og:description","content":"Your Second Brain."}],["$","meta","7",{"property":"og:url","content":"https://app.khoj.dev/"}],["$","meta","8",{"property":"og:site_name","content":"Khoj AI"}],["$","meta","9",{"property":"og:image","content":"https://assets.khoj.dev/khoj_lantern_256x256.png"}],["$","meta","10",{"property":"og:image:width","content":"256"}],["$","meta","11",{"property":"og:image:height","content":"256"}],["$","meta","12",{"property":"og:image","content":"https://assets.khoj.dev/khoj_lantern_logomarktype_1200x630.png"}],["$","meta","13",{"property":"og:image:width","content":"1200"}],["$","meta","14",{"property":"og:image:height","content":"630"}],["$","meta","15",{"property":"og:type","content":"website"}],["$","meta","16",{"name":"twitter:card","content":"summary_large_image"}],["$","meta","17",{"name":"twitter:title","content":"Khoj AI"}],["$","meta","18",{"name":"twitter:description","content":"Your Second Brain."}],["$","meta","19",{"name":"twitter:image","content":"https://assets.khoj.dev/khoj_lantern_256x256.png"}],["$","meta","20",{"name":"twitter:image:width","content":"256"}],["$","meta","21",{"name":"twitter:image:height","content":"256"}],["$","meta","22",{"name":"twitter:image","content":"https://assets.khoj.dev/khoj_lantern_logomarktype_1200x630.png"}],["$","meta","23",{"name":"twitter:image:width","content":"1200"}],["$","meta","24",{"name":"twitter:image:height","content":"630"}],["$","link","25",{"rel":"icon","href":"/static/assets/icons/khoj_lantern.ico"}],["$","link","26",{"rel":"apple-touch-icon","href":"/static/assets/icons/khoj_lantern_256x256.png"}],["$","meta","27",{"name":"next-size-adjust"}]]
|
7
7
|
1:null
|
@@ -157,10 +157,9 @@ def converse_anthropic(
|
|
157
157
|
query_images: Optional[list[str]] = None,
|
158
158
|
vision_available: bool = False,
|
159
159
|
query_files: str = None,
|
160
|
-
generated_images: Optional[list[str]] = None,
|
161
160
|
generated_files: List[FileAttachment] = None,
|
162
|
-
generated_excalidraw_diagram: Optional[str] = None,
|
163
161
|
program_execution_context: Optional[List[str]] = None,
|
162
|
+
generated_asset_results: Dict[str, Dict] = {},
|
164
163
|
tracer: dict = {},
|
165
164
|
):
|
166
165
|
"""
|
@@ -221,9 +220,8 @@ def converse_anthropic(
|
|
221
220
|
vision_enabled=vision_available,
|
222
221
|
model_type=ChatModelOptions.ModelType.ANTHROPIC,
|
223
222
|
query_files=query_files,
|
224
|
-
generated_excalidraw_diagram=generated_excalidraw_diagram,
|
225
223
|
generated_files=generated_files,
|
226
|
-
|
224
|
+
generated_asset_results=generated_asset_results,
|
227
225
|
program_execution_context=program_execution_context,
|
228
226
|
)
|
229
227
|
|
@@ -167,9 +167,8 @@ def converse_gemini(
|
|
167
167
|
query_images: Optional[list[str]] = None,
|
168
168
|
vision_available: bool = False,
|
169
169
|
query_files: str = None,
|
170
|
-
generated_images: Optional[list[str]] = None,
|
171
170
|
generated_files: List[FileAttachment] = None,
|
172
|
-
|
171
|
+
generated_asset_results: Dict[str, Dict] = {},
|
173
172
|
program_execution_context: List[str] = None,
|
174
173
|
tracer={},
|
175
174
|
):
|
@@ -232,9 +231,8 @@ def converse_gemini(
|
|
232
231
|
vision_enabled=vision_available,
|
233
232
|
model_type=ChatModelOptions.ModelType.GOOGLE,
|
234
233
|
query_files=query_files,
|
235
|
-
generated_excalidraw_diagram=generated_excalidraw_diagram,
|
236
234
|
generated_files=generated_files,
|
237
|
-
|
235
|
+
generated_asset_results=generated_asset_results,
|
238
236
|
program_execution_context=program_execution_context,
|
239
237
|
)
|
240
238
|
|
@@ -3,7 +3,7 @@ import logging
|
|
3
3
|
import os
|
4
4
|
from datetime import datetime, timedelta
|
5
5
|
from threading import Thread
|
6
|
-
from typing import Any, Iterator, List, Optional, Union
|
6
|
+
from typing import Any, Dict, Iterator, List, Optional, Union
|
7
7
|
|
8
8
|
import pyjson5
|
9
9
|
from langchain.schema import ChatMessage
|
@@ -166,6 +166,7 @@ def converse_offline(
|
|
166
166
|
query_files: str = None,
|
167
167
|
generated_files: List[FileAttachment] = None,
|
168
168
|
additional_context: List[str] = None,
|
169
|
+
generated_asset_results: Dict[str, Dict] = {},
|
169
170
|
tracer: dict = {},
|
170
171
|
) -> Union[ThreadedGenerator, Iterator[str]]:
|
171
172
|
"""
|
@@ -234,6 +235,7 @@ def converse_offline(
|
|
234
235
|
model_type=ChatModelOptions.ModelType.OFFLINE,
|
235
236
|
query_files=query_files,
|
236
237
|
generated_files=generated_files,
|
238
|
+
generated_asset_results=generated_asset_results,
|
237
239
|
program_execution_context=additional_context,
|
238
240
|
)
|
239
241
|
|
@@ -137,7 +137,7 @@ def send_message_to_model(
|
|
137
137
|
)
|
138
138
|
|
139
139
|
|
140
|
-
def
|
140
|
+
def converse_openai(
|
141
141
|
references,
|
142
142
|
user_query,
|
143
143
|
online_results: Optional[Dict[str, Dict]] = None,
|
@@ -157,9 +157,8 @@ def converse(
|
|
157
157
|
query_images: Optional[list[str]] = None,
|
158
158
|
vision_available: bool = False,
|
159
159
|
query_files: str = None,
|
160
|
-
generated_images: Optional[list[str]] = None,
|
161
160
|
generated_files: List[FileAttachment] = None,
|
162
|
-
|
161
|
+
generated_asset_results: Dict[str, Dict] = {},
|
163
162
|
program_execution_context: List[str] = None,
|
164
163
|
tracer: dict = {},
|
165
164
|
):
|
@@ -223,9 +222,8 @@ def converse(
|
|
223
222
|
vision_enabled=vision_available,
|
224
223
|
model_type=ChatModelOptions.ModelType.OPENAI,
|
225
224
|
query_files=query_files,
|
226
|
-
generated_excalidraw_diagram=generated_excalidraw_diagram,
|
227
225
|
generated_files=generated_files,
|
228
|
-
|
226
|
+
generated_asset_results=generated_asset_results,
|
229
227
|
program_execution_context=program_execution_context,
|
230
228
|
)
|
231
229
|
logger.debug(f"Conversation Context for GPT: {messages_to_print(messages)}")
|
@@ -178,40 +178,41 @@ Improved Prompt:
|
|
178
178
|
""".strip()
|
179
179
|
)
|
180
180
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
)
|
181
|
+
generated_assets_context = PromptTemplate.from_template(
|
182
|
+
"""
|
183
|
+
Assets that you created have already been created to respond to the query. Below, there are references to the descriptions used to create the assets.
|
184
|
+
You can provide a summary of your reasoning from the information below or use it to respond to the original query.
|
186
185
|
|
187
|
-
|
188
|
-
|
189
|
-
|
186
|
+
Generated Assets:
|
187
|
+
{generated_assets}
|
188
|
+
|
189
|
+
Limit your response to 3 sentences max. Be succinct, clear, and informative.
|
190
190
|
""".strip()
|
191
191
|
)
|
192
192
|
|
193
|
+
|
193
194
|
## Diagram Generation
|
194
195
|
## --
|
195
196
|
|
196
197
|
improve_diagram_description_prompt = PromptTemplate.from_template(
|
197
198
|
"""
|
198
|
-
|
199
|
+
You are an architect working with a novice digital artist using a diagramming software.
|
199
200
|
{personality_context}
|
200
201
|
|
201
|
-
|
202
|
-
-
|
203
|
-
-
|
204
|
-
-
|
205
|
-
-
|
206
|
-
-
|
202
|
+
You need to convert the user's query to a description format that the novice artist can use very well. you are allowed to use primitives like
|
203
|
+
- Text
|
204
|
+
- Rectangle
|
205
|
+
- Ellipse
|
206
|
+
- Line
|
207
|
+
- Arrow
|
207
208
|
|
208
|
-
|
209
|
+
Use these primitives to describe what sort of diagram the drawer should create. The artist must recreate the diagram every time, so include all relevant prior information in your description.
|
209
210
|
|
210
|
-
-
|
211
|
-
-
|
212
|
-
-
|
213
|
-
-
|
214
|
-
-
|
211
|
+
- Include the full, exact description. the artist does not have much experience, so be precise.
|
212
|
+
- Describe the layout.
|
213
|
+
- You can only use straight lines.
|
214
|
+
- Use simple, concise language.
|
215
|
+
- Keep it simple and easy to understand. the artist is easily distracted.
|
215
216
|
|
216
217
|
Today's Date: {current_date}
|
217
218
|
User's Location: {location}
|
@@ -337,6 +338,17 @@ Diagram Description: {query}
|
|
337
338
|
""".strip()
|
338
339
|
)
|
339
340
|
|
341
|
+
failed_diagram_generation = PromptTemplate.from_template(
|
342
|
+
"""
|
343
|
+
You attempted to programmatically generate a diagram but failed due to a system issue. You are normally able to generate diagrams, but you encountered a system issue this time.
|
344
|
+
|
345
|
+
You can create an ASCII image of the diagram in response instead.
|
346
|
+
|
347
|
+
This is the diagram you attempted to make:
|
348
|
+
{attempted_diagram}
|
349
|
+
""".strip()
|
350
|
+
)
|
351
|
+
|
340
352
|
## Online Search Conversation
|
341
353
|
## --
|
342
354
|
online_search_conversation = PromptTemplate.from_template(
|
@@ -40,6 +40,7 @@ from khoj.utils.helpers import (
|
|
40
40
|
merge_dicts,
|
41
41
|
)
|
42
42
|
from khoj.utils.rawconfig import FileAttachment
|
43
|
+
from khoj.utils.yaml import yaml_dump
|
43
44
|
|
44
45
|
logger = logging.getLogger(__name__)
|
45
46
|
|
@@ -381,9 +382,8 @@ def generate_chatml_messages_with_context(
|
|
381
382
|
model_type="",
|
382
383
|
context_message="",
|
383
384
|
query_files: str = None,
|
384
|
-
generated_images: Optional[list[str]] = None,
|
385
385
|
generated_files: List[FileAttachment] = None,
|
386
|
-
|
386
|
+
generated_asset_results: Dict[str, Dict] = {},
|
387
387
|
program_execution_context: List[str] = [],
|
388
388
|
):
|
389
389
|
"""Generate chat messages with appropriate context from previous conversation to send to the chat model"""
|
@@ -403,11 +403,15 @@ def generate_chatml_messages_with_context(
|
|
403
403
|
message_context = ""
|
404
404
|
message_attached_files = ""
|
405
405
|
|
406
|
+
generated_assets = {}
|
407
|
+
|
406
408
|
chat_message = chat.get("message")
|
407
409
|
role = "user" if chat["by"] == "you" else "assistant"
|
408
410
|
|
411
|
+
# Legacy code to handle excalidraw diagrams prior to Dec 2024
|
409
412
|
if chat["by"] == "khoj" and "excalidraw" in chat["intent"].get("type", ""):
|
410
413
|
chat_message = chat["intent"].get("inferred-queries")[0]
|
414
|
+
|
411
415
|
if not is_none_or_empty(chat.get("context")):
|
412
416
|
references = "\n\n".join(
|
413
417
|
{
|
@@ -434,15 +438,23 @@ def generate_chatml_messages_with_context(
|
|
434
438
|
reconstructed_context_message = ChatMessage(content=message_context, role="user")
|
435
439
|
chatml_messages.insert(0, reconstructed_context_message)
|
436
440
|
|
437
|
-
if chat.get("images") and role == "assistant":
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
441
|
+
if not is_none_or_empty(chat.get("images")) and role == "assistant":
|
442
|
+
generated_assets["image"] = {
|
443
|
+
"query": chat.get("intent", {}).get("inferred-queries", [user_message])[0],
|
444
|
+
}
|
445
|
+
|
446
|
+
if not is_none_or_empty(chat.get("excalidrawDiagram")) and role == "assistant":
|
447
|
+
generated_assets["diagram"] = {
|
448
|
+
"query": chat.get("intent", {}).get("inferred-queries", [user_message])[0],
|
449
|
+
}
|
450
|
+
|
451
|
+
if not is_none_or_empty(generated_assets):
|
452
|
+
chatml_messages.append(
|
453
|
+
ChatMessage(
|
454
|
+
content=f"{prompts.generated_assets_context.format(generated_assets=yaml_dump(generated_assets))}\n",
|
455
|
+
role="user",
|
456
|
+
)
|
444
457
|
)
|
445
|
-
chatml_messages.append(ChatMessage(content=file_attachment_message, role="user"))
|
446
458
|
|
447
459
|
message_content = construct_structured_message(
|
448
460
|
chat_message, chat.get("images") if role == "user" else [], model_type, vision_enabled
|
@@ -465,33 +477,22 @@ def generate_chatml_messages_with_context(
|
|
465
477
|
role="user",
|
466
478
|
)
|
467
479
|
)
|
468
|
-
if not is_none_or_empty(context_message):
|
469
|
-
messages.append(ChatMessage(content=context_message, role="user"))
|
470
|
-
|
471
|
-
if generated_images:
|
472
|
-
messages.append(
|
473
|
-
ChatMessage(
|
474
|
-
content=construct_structured_message(
|
475
|
-
prompts.generated_image_attachment.format(), generated_images, model_type, vision_enabled
|
476
|
-
),
|
477
|
-
role="user",
|
478
|
-
)
|
479
|
-
)
|
480
480
|
|
481
481
|
if generated_files:
|
482
482
|
message_attached_files = gather_raw_query_files({file.name: file.content for file in generated_files})
|
483
483
|
messages.append(ChatMessage(content=message_attached_files, role="assistant"))
|
484
484
|
|
485
|
-
if
|
486
|
-
|
485
|
+
if not is_none_or_empty(generated_asset_results):
|
486
|
+
context_message += (
|
487
|
+
f"{prompts.generated_assets_context.format(generated_assets=yaml_dump(generated_asset_results))}\n\n"
|
488
|
+
)
|
487
489
|
|
488
490
|
if program_execution_context:
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
)
|
491
|
+
program_context_text = "\n".join(program_execution_context)
|
492
|
+
context_message += f"{prompts.additional_program_context.format(context=program_context_text)}\n"
|
493
|
+
|
494
|
+
if not is_none_or_empty(context_message):
|
495
|
+
messages.append(ChatMessage(content=context_message, role="user"))
|
495
496
|
|
496
497
|
if len(chatml_messages) > 0:
|
497
498
|
messages += chatml_messages
|
khoj/routers/api_chat.py
CHANGED
@@ -23,6 +23,7 @@ from khoj.database.adapters import (
|
|
23
23
|
aget_user_name,
|
24
24
|
)
|
25
25
|
from khoj.database.models import Agent, KhojUser
|
26
|
+
from khoj.processor.conversation import prompts
|
26
27
|
from khoj.processor.conversation.prompts import help_message, no_entries_found
|
27
28
|
from khoj.processor.conversation.utils import defilter_query, save_to_conversation_log
|
28
29
|
from khoj.processor.image.generate import text_to_image
|
@@ -765,6 +766,7 @@ async def chat(
|
|
765
766
|
researched_results = ""
|
766
767
|
online_results: Dict = dict()
|
767
768
|
code_results: Dict = dict()
|
769
|
+
generated_asset_results: Dict = dict()
|
768
770
|
## Extract Document References
|
769
771
|
compiled_references: List[Any] = []
|
770
772
|
inferred_queries: List[Any] = []
|
@@ -1128,6 +1130,10 @@ async def chat(
|
|
1128
1130
|
else:
|
1129
1131
|
generated_images.append(generated_image)
|
1130
1132
|
|
1133
|
+
generated_asset_results["images"] = {
|
1134
|
+
"query": improved_image_prompt,
|
1135
|
+
}
|
1136
|
+
|
1131
1137
|
async for result in send_event(
|
1132
1138
|
ChatEvent.GENERATED_ASSETS,
|
1133
1139
|
{
|
@@ -1166,6 +1172,10 @@ async def chat(
|
|
1166
1172
|
|
1167
1173
|
generated_excalidraw_diagram = diagram_description
|
1168
1174
|
|
1175
|
+
generated_asset_results["diagrams"] = {
|
1176
|
+
"query": better_diagram_description_prompt,
|
1177
|
+
}
|
1178
|
+
|
1169
1179
|
async for result in send_event(
|
1170
1180
|
ChatEvent.GENERATED_ASSETS,
|
1171
1181
|
{
|
@@ -1176,7 +1186,9 @@ async def chat(
|
|
1176
1186
|
else:
|
1177
1187
|
error_message = "Failed to generate diagram. Please try again later."
|
1178
1188
|
program_execution_context.append(
|
1179
|
-
|
1189
|
+
prompts.failed_diagram_generation.format(
|
1190
|
+
attempted_diagram=better_diagram_description_prompt
|
1191
|
+
)
|
1180
1192
|
)
|
1181
1193
|
|
1182
1194
|
async for result in send_event(ChatEvent.STATUS, error_message):
|
@@ -1209,6 +1221,7 @@ async def chat(
|
|
1209
1221
|
generated_files,
|
1210
1222
|
generated_excalidraw_diagram,
|
1211
1223
|
program_execution_context,
|
1224
|
+
generated_asset_results,
|
1212
1225
|
tracer,
|
1213
1226
|
)
|
1214
1227
|
|
khoj/routers/helpers.py
CHANGED
@@ -88,7 +88,10 @@ from khoj.processor.conversation.offline.chat_model import (
|
|
88
88
|
converse_offline,
|
89
89
|
send_message_to_model_offline,
|
90
90
|
)
|
91
|
-
from khoj.processor.conversation.openai.gpt import
|
91
|
+
from khoj.processor.conversation.openai.gpt import (
|
92
|
+
converse_openai,
|
93
|
+
send_message_to_model,
|
94
|
+
)
|
92
95
|
from khoj.processor.conversation.utils import (
|
93
96
|
ChatEvent,
|
94
97
|
ThreadedGenerator,
|
@@ -751,7 +754,7 @@ async def generate_excalidraw_diagram(
|
|
751
754
|
)
|
752
755
|
except Exception as e:
|
753
756
|
logger.error(f"Error generating Excalidraw diagram for {user.email}: {e}", exc_info=True)
|
754
|
-
yield
|
757
|
+
yield better_diagram_description_prompt, None
|
755
758
|
return
|
756
759
|
|
757
760
|
scratchpad = excalidraw_diagram_description.get("scratchpad")
|
@@ -1189,6 +1192,7 @@ def generate_chat_response(
|
|
1189
1192
|
raw_generated_files: List[FileAttachment] = [],
|
1190
1193
|
generated_excalidraw_diagram: str = None,
|
1191
1194
|
program_execution_context: List[str] = [],
|
1195
|
+
generated_asset_results: Dict[str, Dict] = {},
|
1192
1196
|
tracer: dict = {},
|
1193
1197
|
) -> Tuple[Union[ThreadedGenerator, Iterator[str]], Dict[str, str]]:
|
1194
1198
|
# Initialize Variables
|
@@ -1251,6 +1255,7 @@ def generate_chat_response(
|
|
1251
1255
|
agent=agent,
|
1252
1256
|
query_files=query_files,
|
1253
1257
|
generated_files=raw_generated_files,
|
1258
|
+
generated_asset_results=generated_asset_results,
|
1254
1259
|
tracer=tracer,
|
1255
1260
|
)
|
1256
1261
|
|
@@ -1258,7 +1263,7 @@ def generate_chat_response(
|
|
1258
1263
|
openai_chat_config = conversation_config.ai_model_api
|
1259
1264
|
api_key = openai_chat_config.api_key
|
1260
1265
|
chat_model = conversation_config.chat_model
|
1261
|
-
chat_response =
|
1266
|
+
chat_response = converse_openai(
|
1262
1267
|
compiled_references,
|
1263
1268
|
query_to_run,
|
1264
1269
|
query_images=query_images,
|
@@ -1278,8 +1283,7 @@ def generate_chat_response(
|
|
1278
1283
|
vision_available=vision_available,
|
1279
1284
|
query_files=query_files,
|
1280
1285
|
generated_files=raw_generated_files,
|
1281
|
-
|
1282
|
-
generated_excalidraw_diagram=generated_excalidraw_diagram,
|
1286
|
+
generated_asset_results=generated_asset_results,
|
1283
1287
|
program_execution_context=program_execution_context,
|
1284
1288
|
tracer=tracer,
|
1285
1289
|
)
|
@@ -1305,8 +1309,7 @@ def generate_chat_response(
|
|
1305
1309
|
vision_available=vision_available,
|
1306
1310
|
query_files=query_files,
|
1307
1311
|
generated_files=raw_generated_files,
|
1308
|
-
|
1309
|
-
generated_excalidraw_diagram=generated_excalidraw_diagram,
|
1312
|
+
generated_asset_results=generated_asset_results,
|
1310
1313
|
program_execution_context=program_execution_context,
|
1311
1314
|
tracer=tracer,
|
1312
1315
|
)
|
@@ -1331,8 +1334,7 @@ def generate_chat_response(
|
|
1331
1334
|
vision_available=vision_available,
|
1332
1335
|
query_files=query_files,
|
1333
1336
|
generated_files=raw_generated_files,
|
1334
|
-
|
1335
|
-
generated_excalidraw_diagram=generated_excalidraw_diagram,
|
1337
|
+
generated_asset_results=generated_asset_results,
|
1336
1338
|
program_execution_context=program_execution_context,
|
1337
1339
|
tracer=tracer,
|
1338
1340
|
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: khoj
|
3
|
-
Version: 1.30.11.
|
3
|
+
Version: 1.30.11.dev68
|
4
4
|
Summary: Your Second Brain
|
5
5
|
Project-URL: Homepage, https://khoj.dev
|
6
6
|
Project-URL: Documentation, https://docs.khoj.dev
|
@@ -32,7 +32,7 @@ Requires-Dist: defusedxml==0.7.1
|
|
32
32
|
Requires-Dist: django-apscheduler==0.6.2
|
33
33
|
Requires-Dist: django-phonenumber-field==7.3.0
|
34
34
|
Requires-Dist: django-unfold==0.42.0
|
35
|
-
Requires-Dist: django==5.0.
|
35
|
+
Requires-Dist: django==5.0.10
|
36
36
|
Requires-Dist: docx2txt==0.8
|
37
37
|
Requires-Dist: einops==0.8.0
|
38
38
|
Requires-Dist: fastapi>=0.110.0
|