Add --quick and --deep flags for research depth
- quick: 8-12 sources each, faster response - default: 20-30 sources each (unchanged behavior) - deep: 50-70 Reddit, 40-60 X for comprehensive research Adjusts API timeouts based on depth. Cache keys include depth so different depths are cached separately. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,9 +8,16 @@ from . import http
|
||||
|
||||
OPENAI_RESPONSES_URL = "https://api.openai.com/v1/responses"
|
||||
|
||||
# Depth configurations: (min, max) threads to request
|
||||
DEPTH_CONFIG = {
|
||||
"quick": (8, 12),
|
||||
"default": (20, 30),
|
||||
"deep": (50, 70),
|
||||
}
|
||||
|
||||
REDDIT_SEARCH_PROMPT = """Search Reddit for discussions about: {topic}
|
||||
|
||||
Focus on threads from the last 30 days. Find 15-30 high-quality, relevant threads.
|
||||
Focus on threads from the last 30 days. Find {min_items}-{max_items} high-quality, relevant threads.
|
||||
|
||||
IMPORTANT: Return ONLY valid JSON in this exact format, no other text:
|
||||
{{
|
||||
@@ -38,6 +45,7 @@ def search_reddit(
|
||||
api_key: str,
|
||||
model: str,
|
||||
topic: str,
|
||||
depth: str = "default",
|
||||
mock_response: Optional[Dict] = None,
|
||||
) -> Dict[str, Any]:
|
||||
"""Search Reddit for relevant threads using OpenAI Responses API.
|
||||
@@ -46,6 +54,7 @@ def search_reddit(
|
||||
api_key: OpenAI API key
|
||||
model: Model to use
|
||||
topic: Search topic
|
||||
depth: Research depth - "quick", "default", or "deep"
|
||||
mock_response: Mock response for testing
|
||||
|
||||
Returns:
|
||||
@@ -54,11 +63,16 @@ def search_reddit(
|
||||
if mock_response is not None:
|
||||
return mock_response
|
||||
|
||||
min_items, max_items = DEPTH_CONFIG.get(depth, DEPTH_CONFIG["default"])
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {api_key}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
# Adjust timeout based on depth
|
||||
timeout = 60 if depth == "quick" else 90 if depth == "default" else 120
|
||||
|
||||
payload = {
|
||||
"model": model,
|
||||
"tools": [
|
||||
@@ -70,10 +84,10 @@ def search_reddit(
|
||||
}
|
||||
],
|
||||
"include": ["web_search_call.action.sources"],
|
||||
"input": REDDIT_SEARCH_PROMPT.format(topic=topic),
|
||||
"input": REDDIT_SEARCH_PROMPT.format(topic=topic, min_items=min_items, max_items=max_items),
|
||||
}
|
||||
|
||||
return http.post(OPENAI_RESPONSES_URL, payload, headers=headers, timeout=60)
|
||||
return http.post(OPENAI_RESPONSES_URL, payload, headers=headers, timeout=timeout)
|
||||
|
||||
|
||||
def parse_reddit_response(response: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||
|
||||
+18
-2
@@ -9,9 +9,16 @@ from . import http
|
||||
# xAI uses chat completions endpoint
|
||||
XAI_CHAT_URL = "https://api.x.ai/v1/chat/completions"
|
||||
|
||||
# Depth configurations: (min, max) posts to request
|
||||
DEPTH_CONFIG = {
|
||||
"quick": (8, 12),
|
||||
"default": (20, 30),
|
||||
"deep": (40, 60),
|
||||
}
|
||||
|
||||
X_SEARCH_PROMPT = """You have access to real-time X (Twitter) data. Search for posts about: {topic}
|
||||
|
||||
Focus on posts from {from_date} to {to_date}. Find 15-30 high-quality, relevant posts.
|
||||
Focus on posts from {from_date} to {to_date}. Find {min_items}-{max_items} high-quality, relevant posts.
|
||||
|
||||
IMPORTANT: Return ONLY valid JSON in this exact format, no other text:
|
||||
{{
|
||||
@@ -47,6 +54,7 @@ def search_x(
|
||||
topic: str,
|
||||
from_date: str,
|
||||
to_date: str,
|
||||
depth: str = "default",
|
||||
mock_response: Optional[Dict] = None,
|
||||
) -> Dict[str, Any]:
|
||||
"""Search X for relevant posts using xAI API with live search.
|
||||
@@ -57,6 +65,7 @@ def search_x(
|
||||
topic: Search topic
|
||||
from_date: Start date (YYYY-MM-DD)
|
||||
to_date: End date (YYYY-MM-DD)
|
||||
depth: Research depth - "quick", "default", or "deep"
|
||||
mock_response: Mock response for testing
|
||||
|
||||
Returns:
|
||||
@@ -65,11 +74,16 @@ def search_x(
|
||||
if mock_response is not None:
|
||||
return mock_response
|
||||
|
||||
min_items, max_items = DEPTH_CONFIG.get(depth, DEPTH_CONFIG["default"])
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {api_key}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
# Adjust timeout based on depth
|
||||
timeout = 60 if depth == "quick" else 90 if depth == "default" else 120
|
||||
|
||||
# Use chat completions format with search enabled
|
||||
payload = {
|
||||
"model": model,
|
||||
@@ -84,6 +98,8 @@ def search_x(
|
||||
topic=topic,
|
||||
from_date=from_date,
|
||||
to_date=to_date,
|
||||
min_items=min_items,
|
||||
max_items=max_items,
|
||||
),
|
||||
}
|
||||
],
|
||||
@@ -95,7 +111,7 @@ def search_x(
|
||||
},
|
||||
}
|
||||
|
||||
return http.post(XAI_CHAT_URL, payload, headers=headers, timeout=90)
|
||||
return http.post(XAI_CHAT_URL, payload, headers=headers, timeout=timeout)
|
||||
|
||||
|
||||
def parse_x_response(response: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||
|
||||
Reference in New Issue
Block a user