mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Misc. fixes to prompting, admin, and others (#658)
* Simplify and clarify prompt for selecting toolset dynamically * Add error handling around call to OLOSTEP api * Fix conversation admin page * Skip adding none or empty entries in the chunking method
This commit is contained in:
@@ -60,7 +60,7 @@ class ConversationAdmin(admin.ModelAdmin):
|
||||
"updated_at",
|
||||
"client",
|
||||
)
|
||||
search_fields = ("conversation_id",)
|
||||
search_fields = ("id", "user__email", "user__username", "client__name")
|
||||
ordering = ("-created_at",)
|
||||
|
||||
actions = ["export_selected_objects", "export_selected_minimal_objects"]
|
||||
|
||||
@@ -41,6 +41,9 @@ class TextToEntries(ABC):
|
||||
"Split entries if compiled entry length exceeds the max tokens supported by the ML model."
|
||||
chunked_entries: List[Entry] = []
|
||||
for entry in entries:
|
||||
if is_none_or_empty(entry.compiled):
|
||||
continue
|
||||
|
||||
# Split entry into words
|
||||
compiled_entry_words = [word for word in entry.compiled.split(" ") if word != ""]
|
||||
|
||||
|
||||
@@ -302,7 +302,7 @@ You are Khoj, a smart and helpful personal assistant. You have access to a varie
|
||||
|
||||
Here are some example responses:
|
||||
|
||||
Example 1:
|
||||
Example:
|
||||
Chat History:
|
||||
User: I'm thinking of moving to a new city. I'm trying to decide between New York and San Francisco.
|
||||
AI: Moving to a new city can be challenging. Both New York and San Francisco are great cities to live in. New York is known for its diverse culture and San Francisco is known for its tech scene.
|
||||
@@ -310,15 +310,7 @@ AI: Moving to a new city can be challenging. Both New York and San Francisco are
|
||||
Q: What is the population of each of those cities?
|
||||
Khoj: ["online"]
|
||||
|
||||
Example 2:
|
||||
Chat History:
|
||||
User: I've been having a hard time at work. I'm thinking of quitting.
|
||||
AI: I'm sorry to hear that. It's important to take care of your mental health. Have you considered talking to your manager about your concerns?
|
||||
|
||||
Q: What are the best ways to quit a job?
|
||||
Khoj: ["default"]
|
||||
|
||||
Example 3:
|
||||
Example:
|
||||
Chat History:
|
||||
User: I'm thinking of my next vacation idea. Ideally, I want to see something new and exciting.
|
||||
AI: Excellent! Taking a vacation is a great way to relax and recharge.
|
||||
@@ -326,14 +318,16 @@ AI: Excellent! Taking a vacation is a great way to relax and recharge.
|
||||
Q: Where did Grandma grow up?
|
||||
Khoj: ["notes"]
|
||||
|
||||
Example 4:
|
||||
Example:
|
||||
Chat History:
|
||||
|
||||
Q: What's the latest news with the first company I worked for?
|
||||
Khoj: ["notes", "online"]
|
||||
|
||||
Example 5:
|
||||
Example:
|
||||
Chat History:
|
||||
User: I want to start a new hobby. I'm thinking of learning to play the guitar.
|
||||
AI: Learning to play the guitar is a great hobby. It can be a lot of fun and a great way to express yourself.
|
||||
|
||||
Q: Who is Sandra?
|
||||
Khoj: ["default"]
|
||||
@@ -344,7 +338,7 @@ Chat History:
|
||||
{chat_history}
|
||||
|
||||
Q: {query}
|
||||
A:
|
||||
Khoj:
|
||||
""".strip()
|
||||
)
|
||||
|
||||
|
||||
@@ -103,10 +103,14 @@ def search_with_olostep(web_url: str) -> str:
|
||||
web_scraping_params: Dict[str, Union[str, int, bool]] = OLOSTEP_QUERY_PARAMS.copy() # type: ignore
|
||||
web_scraping_params["url"] = web_url
|
||||
|
||||
response = requests.request("GET", OLOSTEP_API_URL, params=web_scraping_params, headers=headers)
|
||||
try:
|
||||
response = requests.request("GET", OLOSTEP_API_URL, params=web_scraping_params, headers=headers)
|
||||
|
||||
if response.status_code != 200:
|
||||
logger.error(response, exc_info=True)
|
||||
if response.status_code != 200:
|
||||
logger.error(response, exc_info=True)
|
||||
return None
|
||||
except Exception as e:
|
||||
logger.error(f"Error while searching with Olostep: {e}", exc_info=True)
|
||||
return None
|
||||
|
||||
return response.json()["markdown_content"]
|
||||
|
||||
Reference in New Issue
Block a user