#!/usr/bin/env python3
"""
Test the Query Processor with Claude Function Calling
This demonstrates how natural language queries are processed into
optimized Google Scholar searches.
"""
from query_processor import QueryProcessor, demo_claude_function_calling
import json
def test_specific_query():
"""Test the specific query from the user"""
print("🔬 Testing User's Specific Query")
print("=" * 60)
# The user's example query
user_query = "I'm interested in computer vision papers from CVPR 2023 that have been highly cited. Can you find them and summarize the main trends"
processor = QueryProcessor()
print(f"📝 Original Query:")
print(f" '{user_query}'")
print()
# Process the query
optimized_query, search_params = processor.process_query(user_query)
strategy = processor.create_search_strategy(search_params)
print(f"🎯 Extracted Keywords:")
print(f" Primary: {search_params.get('primary_keywords', [])}")
print(f" Venues: {search_params.get('venue_filters', [])}")
print(f" Years: {search_params.get('year_range', {})}")
print(f" Citation Criteria: {search_params.get('citation_criteria', 'any')}")
print()
print(f"🔍 Optimized Search Query:")
print(f" '{optimized_query}'")
print()
print(f"📊 Complete Search Strategy:")
print(f" Query: {strategy['primary_search']}")
print(f" Results: {strategy['num_results']}")
print(f" Filters: {strategy['filters']}")
if 'min_citations' in strategy:
print(f" Min Citations: {strategy['min_citations']}")
print()
return optimized_query, strategy
def demonstrate_function_calling_schema():
"""Show the function calling schema that would be sent to Claude/OpenAI"""
print("⚙️ Function Calling Schema")
print("=" * 60)
processor = QueryProcessor()
print("📋 Function Definition (sent to LLM):")
print("```json")
print(json.dumps(processor.extraction_function, indent=2))
print("```")
print()
print("💡 How it works:")
print("1. Send user query + function schema to Claude/OpenAI")
print("2. LLM calls the function with extracted parameters")
print("3. We get structured data back")
print("4. Use structured data to build optimized Google Scholar query")
print()
def show_real_claude_function_call_example():
"""Show what a real Claude API call would look like"""
print("🤖 Real Claude API Function Call Example")
print("=" * 60)
example_payload = {
"model": "claude-3-sonnet-20240229",
"max_tokens": 1000,
"tools": [{
"name": "extract_search_keywords",
"description": "Extract optimal keywords and filters for academic paper search",
"input_schema": {
"type": "object",
"properties": {
"primary_keywords": {
"type": "array",
"items": {"type": "string"},
"description": "Main search terms (2-4 words max each)"
},
"venue_filters": {
"type": "array",
"items": {"type": "string"},
"description": "Conference/journal names"
},
"optimized_query": {
"type": "string",
"description": "Final optimized search query"
}
},
"required": ["primary_keywords", "optimized_query"]
}
}],
"tool_choice": {"type": "tool", "name": "extract_search_keywords"},
"messages": [
{
"role": "user",
"content": "Extract search keywords from: 'I'm interested in computer vision papers from CVPR 2023 that have been highly cited'"
}
]
}
print("📤 Request to Claude API:")
print("```json")
print(json.dumps(example_payload, indent=2))
print("```")
print()
# Expected response
expected_response = {
"primary_keywords": ["computer vision", "CVPR"],
"venue_filters": ["CVPR 2023"],
"year_range": {"start_year": 2023, "end_year": 2023},
"citation_criteria": "highly_cited",
"optimized_query": "computer vision CVPR 2023"
}
print("📥 Expected Claude Response:")
print("```json")
print(json.dumps(expected_response, indent=2))
print("```")
if __name__ == "__main__":
# Run all demonstrations
test_specific_query()
print("\n" + "="*60 + "\n")
demonstrate_function_calling_schema()
print("\n" + "="*60 + "\n")
show_real_claude_function_call_example()
print("\n" + "="*60 + "\n")
# Run the full demo
demo_claude_function_calling()