Skip to content

Commit d647795

Browse files
Merge pull request volcengine#41 from luminghao-bytedance/feat/add_deep_research_ui
feat(deep_research): add webui
2 parents c77408f + ecf65e4 commit d647795

File tree

16 files changed

+1546
-627
lines changed

16 files changed

+1546
-627
lines changed

demohouse/deep_research/README.md

Lines changed: 103 additions & 214 deletions
Large diffs are not rendered by default.

demohouse/deep_research/config.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
2+
# Licensed under the 【火山方舟】原型应用软件自用许可协议
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
# https://www.volcengine.com/docs/82379/1433703
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
11+
12+
import os
13+
14+
"""
15+
for server
16+
"""
17+
18+
# recommend to use DeepSeek-R1 model
19+
REASONING_MODEL = os.getenv('REASONING_MODEL') or "deepseek-r1-250120"
20+
# default set to volc bot, if using tavily, change it into "tavily"
21+
SEARCH_ENGINE = os.getenv('SEARCH_ENGINE') or "volc_bot"
22+
# optional, if you select tavily as search engine, please configure this
23+
TAVILY_API_KEY = os.getenv('TAVILY_API_KEY') or "{YOUR_TAVILY_API_KEY}"
24+
# optional, if you select volc bot as search engine, please configure this
25+
SEARCH_BOT_ID = os.getenv('SEARCH_BOT_ID') or "{YOUR_SEARCH_BOT_ID}"
26+
27+
"""
28+
for webui
29+
"""
30+
31+
# ark api key
32+
ARK_API_KEY = os.getenv('ARK_API_KEY') or "{YOUR_ARK_API_KEY}"
33+
# api server address for web ui
34+
API_ADDR = os.getenv("API_ADDR") or "https://ark.cn-beijing.volces.com/api/v3/bots"
35+
# while using remote api, need bot id
36+
API_BOT_ID = os.getenv("API_BOT_ID") or "{YOUR_API_BOT_ID}"

demohouse/deep_research/deep_research.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from pydantic import BaseModel, Field
1616
from typing_extensions import Optional
1717

18+
import volcenginesdkarkruntime.types.chat.chat_completion_chunk as completion_chunk
1819
from arkitect.core.component.llm import BaseChatLanguageModel
1920
from arkitect.core.component.llm.model import ArkMessage, ArkChatRequest, ArkChatResponse, ArkChatCompletionChunk
2021
from arkitect.core.component.prompts import CustomPromptTemplate
@@ -23,7 +24,7 @@
2324
from search_engine import SearchEngine, SearchResult
2425
from search_engine.volc_bot import VolcBotSearchEngine
2526
from prompt import DEFAULT_PLANNING_PROMPT, DEFAULT_SUMMARY_PROMPT
26-
from utils import get_current_date, cast_content_to_reasoning_content
27+
from utils import get_current_date, cast_content_to_reasoning_content, gen_metadata_chunk
2728

2829
"""
2930
ResultsSummary is using to store the result searched so far
@@ -110,7 +111,8 @@ async def arun_deep_research(self, request: ArkChatRequest, question: str) -> Ar
110111
references=references
111112
)
112113
# append the reasoning buffer
113-
resp.choices[0].message.reasoning_content = (buffered_reasoning_content + resp.choices[0].message.reasoning_content)
114+
resp.choices[0].message.reasoning_content = (
115+
buffered_reasoning_content + resp.choices[0].message.reasoning_content)
114116
return resp
115117

116118
async def astream_deep_research(self, request: ArkChatRequest, question: str) \
@@ -153,8 +155,8 @@ async def astream_planning(
153155
references: ResultsSummary
154156
) -> AsyncIterable[ArkChatCompletionChunk]:
155157

156-
planned_rounds = 0
157-
while planned_rounds < self.extra_config.max_planning_rounds:
158+
planned_rounds = 1
159+
while planned_rounds <= self.extra_config.max_planning_rounds:
158160
planned_rounds += 1
159161

160162
llm = BaseChatLanguageModel(
@@ -184,12 +186,35 @@ async def astream_planning(
184186

185187
new_queries = self.check_query(planning_result)
186188
if not new_queries:
189+
# YIELD state with metadata
190+
yield gen_metadata_chunk(
191+
metadata={
192+
'search_state': 'finished'
193+
}
194+
)
187195
INFO("planning finished")
188196
break
189197
else:
190198
INFO(f"searching: {new_queries}")
199+
# YIELD state with metadata
200+
yield gen_metadata_chunk(
201+
metadata={
202+
'search_rounds': planned_rounds,
203+
'search_state': 'searching',
204+
'search_keywords': new_queries
205+
}
206+
)
191207
search_results = await self.search_engine.asearch(new_queries)
192208
INFO(f"search result: {search_results}")
209+
# YIELD state with metadata
210+
yield gen_metadata_chunk(
211+
metadata={
212+
'search_rounds': planned_rounds,
213+
'search_state': 'searched',
214+
'search_keywords': new_queries,
215+
'search_results': search_results
216+
}
217+
)
193218
for search_result in search_results:
194219
references.add_result(query=search_result.query, results=[search_result])
195220

382 KB
Loading
266 KB
Loading
217 KB
Loading
134 KB
Loading
286 KB
Loading

0 commit comments

Comments
 (0)