Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/chat_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class ChatMessage(BaseModel):
role: str # 'user' or 'assistant'
content: str
mode: Literal["normal", "deep_research"] = Field(default="normal")

class ChatCompletionRequest(BaseModel):
"""
Expand All @@ -26,6 +27,13 @@ class ChatCompletionRequest(BaseModel):
model: Optional[str] = Field(None, description="Model name for the specified provider")

language: Optional[str] = Field("en", description="Language for content generation (e.g., 'en', 'ja', 'zh', 'es', 'kr', 'vi')")

research_iteration: int = Field(
default=1,
ge=1,
description="Current deep research iteration (1-based). Only used when the request is in deep_research mode.",
)

excluded_dirs: List[str] = Field(
default_factory=list,
description="List or newline-separated string of directories to exclude from processing",
Expand Down
23 changes: 6 additions & 17 deletions api/simple_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,19 @@ async def chat_completions_stream(request: ChatCompletionRequest):
)

# Check if this is a Deep Research request
is_deep_research = False
research_iteration = 1

# Process messages to detect Deep Research requests
for msg in request.messages:
if hasattr(msg, 'content') and msg.content and "[DEEP RESEARCH]" in msg.content:
is_deep_research = True
# Only remove the tag from the last message
if msg == request.messages[-1]:
# Remove the Deep Research tag
msg.content = msg.content.replace("[DEEP RESEARCH]", "").strip()
is_deep_research = last_message.mode == "deep_research"

# Count research iterations if this is a Deep Research request
if is_deep_research:
research_iteration = sum(1 for msg in request.messages if msg.role == 'assistant') + 1
logger.info(f"Deep Research request detected - iteration {research_iteration}")
logger.info("Deep Research request detected - iteration %d",request.research_iteration)

# Check if this is a continuation request
if "continue" in last_message.content.lower() and "research" in last_message.content.lower():
# Find the original topic from the first user message
original_topic = None
for msg in request.messages:
if msg.role == "user" and "continue" not in msg.content.lower():
original_topic = msg.content.replace("[DEEP RESEARCH]", "").strip()
original_topic = msg.content.strip()
logger.info(f"Found original research topic: {original_topic}")
break

Expand Down Expand Up @@ -219,10 +208,10 @@ async def chat_completions_stream(request: ChatCompletionRequest):
# Create system prompt
if is_deep_research:
# Check if this is the first iteration
is_first_iteration = research_iteration == 1
is_first_iteration = request.research_iteration == 1

# Check if this is the final iteration
is_final_iteration = research_iteration >= 5
is_final_iteration = request.research_iteration >= 5

if is_first_iteration:
system_prompt = DEEP_RESEARCH_FIRST_ITERATION_PROMPT.format(
Expand All @@ -243,7 +232,7 @@ async def chat_completions_stream(request: ChatCompletionRequest):
repo_type=repo_type,
repo_url=repo_url,
repo_name=repo_name,
research_iteration=research_iteration,
research_iteration=request.research_iteration,
language_name=language_name
)
else:
Expand Down
23 changes: 6 additions & 17 deletions api/websocket_wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,19 @@ async def handle_websocket_chat(websocket: WebSocket):
)

# Check if this is a Deep Research request
is_deep_research = False
research_iteration = 1

# Process messages to detect Deep Research requests
for msg in request.messages:
if hasattr(msg, 'content') and msg.content and "[DEEP RESEARCH]" in msg.content:
is_deep_research = True
# Only remove the tag from the last message
if msg == request.messages[-1]:
# Remove the Deep Research tag
msg.content = msg.content.replace("[DEEP RESEARCH]", "").strip()
is_deep_research = last_message.mode == "deep_research"

# Count research iterations if this is a Deep Research request
if is_deep_research:
research_iteration = sum(1 for msg in request.messages if msg.role == 'assistant') + 1
logger.info(f"Deep Research request detected - iteration {research_iteration}")
logger.info("Deep Research request detected - iteration %d", request.research_iteration)

# Check if this is a continuation request
if "continue" in last_message.content.lower() and "research" in last_message.content.lower():
# Find the original topic from the first user message
original_topic = None
for msg in request.messages:
if msg.role == "user" and "continue" not in msg.content.lower():
original_topic = msg.content.replace("[DEEP RESEARCH]", "").strip()
original_topic = msg.content.strip()
logger.info(f"Found original research topic: {original_topic}")
break

Expand Down Expand Up @@ -222,10 +211,10 @@ async def handle_websocket_chat(websocket: WebSocket):
# Create system prompt
if is_deep_research:
# Check if this is the first iteration
is_first_iteration = research_iteration == 1
is_first_iteration = request.research_iteration == 1

# Check if this is the final iteration
is_final_iteration = research_iteration >= 5
is_final_iteration = request.research_iteration >= 5

if is_first_iteration:
system_prompt = DEEP_RESEARCH_FIRST_ITERATION_PROMPT.format(
Expand All @@ -246,7 +235,7 @@ async def handle_websocket_chat(websocket: WebSocket):
repo_type=repo_type,
repo_url=repo_url,
repo_name=repo_name,
research_iteration=research_iteration,
research_iteration=request.research_iteration,
language_name=language_name
)
else:
Expand Down
25 changes: 19 additions & 6 deletions src/components/Ask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface Provider {
interface Message {
role: 'user' | 'assistant' | 'system';
content: string;
mode?: 'normal' | 'deep_research';
}

interface ResearchStage {
Expand Down Expand Up @@ -299,7 +300,8 @@ const Ask: React.FC<AskProps> = ({
},
{
role: 'user',
content: '[DEEP RESEARCH] Continue the research'
content: 'Continue the research',
mode: 'deep_research'
}
];

Expand All @@ -317,10 +319,15 @@ const Ask: React.FC<AskProps> = ({
const requestBody: ChatCompletionRequest = {
repo_url: getRepoUrl(repoInfo),
type: repoInfo.type,
messages: newHistory.map(msg => ({ role: msg.role as 'user' | 'assistant', content: msg.content })),
messages: newHistory.map(msg => ({
role: msg.role as 'user' | 'assistant',
content: msg.content,
mode: msg.mode ?? 'normal',
})),
provider: selectedProvider,
model: isCustomSelectedModel ? customSelectedModel : selectedModel,
language: language
language: language,
research_iteration: newIteration
};

// Add tokens if available
Expand Down Expand Up @@ -548,7 +555,8 @@ const Ask: React.FC<AskProps> = ({
// Create initial message
const initialMessage: Message = {
role: 'user',
content: deepResearch ? `[DEEP RESEARCH] ${question}` : question
content: question,
mode: deepResearch ? 'deep_research' : 'normal'
};

// Set initial conversation history
Expand All @@ -559,10 +567,15 @@ const Ask: React.FC<AskProps> = ({
const requestBody: ChatCompletionRequest = {
repo_url: getRepoUrl(repoInfo),
type: repoInfo.type,
messages: newHistory.map(msg => ({ role: msg.role as 'user' | 'assistant', content: msg.content })),
messages: newHistory.map(msg => ({
role: msg.role as 'user' | 'assistant',
content: msg.content,
mode: msg.mode ?? 'normal'
})),
provider: selectedProvider,
model: isCustomSelectedModel ? customSelectedModel : selectedModel,
language: language
language: language,
research_iteration: deepResearch ? 1 : undefined
};

// Add tokens if available
Expand Down
2 changes: 2 additions & 0 deletions src/utils/websocketClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const getWebSocketUrl = () => {
export interface ChatMessage {
role: 'user' | 'assistant' | 'system';
content: string;
mode?: 'normal' | 'deep_research';
}

export interface ChatCompletionRequest {
Expand All @@ -28,6 +29,7 @@ export interface ChatCompletionRequest {
provider?: string;
model?: string;
language?: string;
research_iteration?: number;
excluded_dirs?: string;
excluded_files?: string;
}
Expand Down
Loading