Skip to content

Commit

Permalink
minor additions
Browse files Browse the repository at this point in the history
  • Loading branch information
TanGentleman committed Nov 20, 2024
1 parent c53fbe7 commit c8ba0f5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/core/core_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# Third-party imports
from langchain_core.utils.function_calling import convert_to_openai_tool
from openai import OpenAI
from openai.types.chat import ChatCompletion
from pydantic import BaseModel, Field

# Local imports
Expand Down Expand Up @@ -70,6 +71,7 @@ def __init__(self):
self.searcher = None
self.search_params = None
self.search_results = None
# NOTE: The convert_to_openai_tool should have strict=True, but error is handled differently.

# NOTE: Should this return anything?
def set_valves(self, valves: Optional[dict] = None) -> None:
Expand Down Expand Up @@ -180,13 +182,14 @@ def _get_search_results_from_params(

def _make_tool_api_call(self, messages):
print("Using tool model:", self.valves.FILTER_MODEL)
return self.client.chat.completions.create(
response: ChatCompletion = self.client.chat.completions.create(
model=self.valves.FILTER_MODEL,
messages=messages,
tools=self.tools,
tool_choice="auto",
stream=False
)
return response

def _process_tool_calls(self, tool_calls: list[dict]) -> dict | str:
"""Process tool calls and return results"""
Expand Down
22 changes: 16 additions & 6 deletions src/utils/owui_utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,31 @@
Focus on making connections between the user's intent and the retrieved data to provide meaningful analysis."""


DEFAULT_QUERY = "Search the past 10 days for audio. Try your best to contextualize my conversations with a limit of 2 results."
DEFAULT_QUERY = "Search the past 10 days for audio and screen content. Try your best to contextualize my conversations with a limit of 2 results."
DEFAULT_STREAM = True

EXAMPLE_SEARCH_RESULTS = [
{
"content": "Hey Jason, can you help me with the project deadline?",
"timestamp": "2024-03-20T14:30:00Z",
"source": "Team Meeting - Zoom (audio)"
"timestamp": "11/19/24 00:07",
"type": "Audio",
"device_name": "MacBook Pro Microphone ",
},
{
"content": "Project Status: In Progress\nDeadline: March 25, 2024",
"timestamp": "2024-03-20T14:31:00Z",
"source": "Project Management Dashboard (ocr)"
"content": "Project Status: In Progress\nDeadline: March 25, 2024",
"timestamp": "11/13/24 14:31",
"type": "OCR",
"app_name": "Project Management Dashboard"
}
]
EXAMPLE_SEARCH_PARAMS = {
"content_type": "AUDIO",
"from_time": "2024-07-10T00:00:00Z",
"to_time": "2024-12-01T23:59:59Z",
"limit": 2,
"search_substring": None,
"application": None
}

FINAL_RESPONSE_USER_MESSAGE = """\
<user_query>
Expand Down
10 changes: 5 additions & 5 deletions src/utils/owui_utils/pipeline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import requests
import json

from .constants import DEFAULT_QUERY, DEFAULT_STREAM, EXAMPLE_SEARCH_RESULTS, FINAL_RESPONSE_SYSTEM_MESSAGE, FINAL_RESPONSE_USER_MESSAGE
from .constants import DEFAULT_QUERY, DEFAULT_STREAM, EXAMPLE_SEARCH_PARAMS, EXAMPLE_SEARCH_RESULTS, FINAL_RESPONSE_SYSTEM_MESSAGE, FINAL_RESPONSE_USER_MESSAGE

MAX_SEARCH_LIMIT = 99

Expand Down Expand Up @@ -35,8 +35,8 @@ def get_pipe_body(
return {
"user_message_content": query or DEFAULT_QUERY,
"search_results": search_results or EXAMPLE_SEARCH_RESULTS,
"search_params": search_params or EXAMPLE_SEARCH_RESULTS,
"stream": DEFAULT_STREAM if stream is None else stream,
"search_params": search_params or EXAMPLE_SEARCH_PARAMS,
"stream": stream if stream is not None else DEFAULT_STREAM,
"inlet_error": None
}

Expand Down Expand Up @@ -484,8 +484,8 @@ def format_results_as_string(search_results: List[dict]) -> str:
"""Formats search results as a string"""
response_string = ""
for i, result in enumerate(search_results, 1):
content = result["content"].strip()
result_type = result["type"]
content = result.get("content", "").strip()
result_type = result.get("type", "")
metadata = {
"device_name": result.get("device_name", ""),
"app_name": result.get("app_name", ""),
Expand Down

0 comments on commit c8ba0f5

Please sign in to comment.