Skip to content

Commit 2b309b0

Browse files
committed
.
1 parent 9634870 commit 2b309b0

File tree

3 files changed

+74
-6
lines changed

3 files changed

+74
-6
lines changed

backend/onyx/chat/turn/fast_chat_turn.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def fast_chat_turn(messages: list[dict], dependencies: RunDependencies) -> None:
3939

4040
bridge = OnyxRunner().run_streamed(agent, messages, context=ctx, max_turns=100)
4141
for ev in bridge.events():
42+
ctx.current_run_step
4243
if isinstance(ev, RunItemStreamEvent):
4344
pass
4445
elif isinstance(ev, RawResponsesStreamEvent):

backend/onyx/tools/tool_implementations_v2/internal_search.py

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
from onyx.chat.turn.models import MyContext
77
from onyx.db.engine.sql_engine import get_session_with_current_tenant
8+
from onyx.server.query_and_chat.streaming_models import Packet
9+
from onyx.server.query_and_chat.streaming_models import SavedSearchDoc
10+
from onyx.server.query_and_chat.streaming_models import SearchToolDelta
11+
from onyx.server.query_and_chat.streaming_models import SearchToolStart
12+
from onyx.server.query_and_chat.streaming_models import SectionEnd
813
from onyx.tools.models import SearchToolOverrideKwargs
914
from onyx.tools.tool_implementations.search.search_tool import (
1015
SEARCH_RESPONSE_SUMMARY_ID,
@@ -13,7 +18,7 @@
1318

1419

1520
@function_tool
16-
def internal_search(context_wrapper: RunContextWrapper[MyContext], query: str) -> str:
21+
def internal_search(run_context: RunContextWrapper[MyContext], query: str) -> str:
1722
"""
1823
Search the internal knowledge base and documents.
1924
@@ -24,10 +29,23 @@ def internal_search(context_wrapper: RunContextWrapper[MyContext], query: str) -
2429
Args:
2530
query: The natural-language search query.
2631
"""
27-
context_wrapper.context.run_dependencies.emitter.emit(
28-
kind="tool-progress", data={"query": query}
32+
run_context.context.run_dependencies.emitter.emit(
33+
Packet(
34+
ind=run_context.context.current_run_step + 1,
35+
obj=SearchToolStart(
36+
type="internal_search_tool_start", is_internet_search=False
37+
),
38+
)
39+
)
40+
run_context.context.run_dependencies.emitter.emit(
41+
Packet(
42+
ind=run_context.context.current_run_step + 1,
43+
obj=SearchToolDelta(
44+
type="internal_search_tool_delta", queries=[query], documents=None
45+
),
46+
)
2947
)
30-
search_tool = context_wrapper.context.run_dependencies.search_tool
48+
search_tool = run_context.context.run_dependencies.search_tool
3149
if search_tool is None:
3250
raise RuntimeError("Search tool not available in context")
3351

@@ -45,6 +63,46 @@ def internal_search(context_wrapper: RunContextWrapper[MyContext], query: str) -
4563
if tool_response.id == SEARCH_RESPONSE_SUMMARY_ID:
4664
response = cast(SearchResponseSummary, tool_response.response)
4765
retrieved_docs = response.top_sections
48-
66+
run_context.context.run_dependencies.emitter.emit(
67+
Packet(
68+
ind=run_context.context.current_run_step + 1,
69+
obj=SearchToolDelta(
70+
type="internal_search_tool_delta",
71+
queries=None,
72+
documents=[
73+
SavedSearchDoc(
74+
db_doc_id=0,
75+
document_id=doc.center_chunk.document_id,
76+
chunk_ind=0,
77+
semantic_identifier=doc.center_chunk.semantic_identifier,
78+
link=doc.center_chunk.semantic_identifier,
79+
blurb=doc.center_chunk.blurb,
80+
source_type=doc.center_chunk.source_type,
81+
boost=doc.center_chunk.boost,
82+
hidden=doc.center_chunk.hidden,
83+
metadata=doc.center_chunk.metadata,
84+
score=doc.center_chunk.score,
85+
is_relevant=doc.center_chunk.is_relevant,
86+
relevance_explanation=doc.center_chunk.relevance_explanation,
87+
match_highlights=doc.center_chunk.match_highlights,
88+
updated_at=doc.center_chunk.updated_at,
89+
primary_owners=doc.center_chunk.primary_owners,
90+
secondary_owners=doc.center_chunk.secondary_owners,
91+
is_internet=False,
92+
)
93+
for doc in retrieved_docs
94+
],
95+
),
96+
)
97+
)
4998
break
99+
run_context.context.run_dependencies.emitter.emit(
100+
Packet(
101+
ind=run_context.context.current_run_step + 1,
102+
obj=SectionEnd(
103+
type="section_end",
104+
),
105+
)
106+
)
107+
run_context.context.current_run_step += 2
50108
return retrieved_docs

backend/onyx/tools/tool_implementations_v2/web.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from onyx.server.query_and_chat.streaming_models import SavedSearchDoc
1414
from onyx.server.query_and_chat.streaming_models import SearchToolDelta
1515
from onyx.server.query_and_chat.streaming_models import SearchToolStart
16+
from onyx.server.query_and_chat.streaming_models import SectionEnd
1617

1718

1819
def short_tag(link: str, i: int) -> str:
@@ -65,6 +66,7 @@ def web_search(run_context: RunContextWrapper[MyContext], query: str) -> str:
6566
)
6667
saved_search_docs = [
6768
SavedSearchDoc(
69+
db_doc_id=0,
6870
document_id=hit.link,
6971
chunk_ind=0,
7072
semantic_identifier=hit.link,
@@ -85,7 +87,6 @@ def web_search(run_context: RunContextWrapper[MyContext], query: str) -> str:
8587
)
8688
for hit in hits
8789
]
88-
print(saved_search_docs)
8990
run_context.context.run_dependencies.emitter.emit(
9091
Packet(
9192
ind=run_context.context.current_run_step + 1,
@@ -96,6 +97,14 @@ def web_search(run_context: RunContextWrapper[MyContext], query: str) -> str:
9697
),
9798
)
9899
)
100+
run_context.context.run_dependencies.emitter.emit(
101+
Packet(
102+
ind=run_context.context.current_run_step + 1,
103+
obj=SectionEnd(
104+
type="section_end",
105+
),
106+
)
107+
)
99108
run_context.context.current_run_step += 2
100109
return json.dumps({"results": results})
101110

0 commit comments

Comments
 (0)