-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.py
More file actions
163 lines (119 loc) · 4.84 KB
/
Copy pathexample_usage.py
File metadata and controls
163 lines (119 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"""Example usage of the data processing framework."""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from src.logging import setup_logging
from src.pipeline import PipelineOrchestrator
def example_1_process_single_source():
"""Example: Process data from a single source."""
print("\n=== Example 1: Process Single Source ===\n")
# Setup
setup_logging(log_level="INFO")
pipeline = PipelineOrchestrator(config_dir="config")
# Process a specific source
result = pipeline.process_source("job_api_single")
print(f"Success: {result['success']}")
if result['success']:
print(f"Raw Data ID: {result['raw_data_id']}")
print(f"Entries Created: {result['layer2'].get('num_entries', 0)}")
pipeline.shutdown()
def example_2_process_with_custom_data():
"""Example: Process custom data without fetching from source."""
print("\n=== Example 2: Process Custom Data ===\n")
setup_logging(log_level="INFO")
pipeline = PipelineOrchestrator(config_dir="config")
# Custom data to process
custom_data = {
"title": "Marine Biology PhD Position",
"organization": "Ocean Research Institute",
"location": "California, USA",
"description": "Seeking PhD student for kelp forest ecosystem research",
"requirements": [
"Masters degree in marine biology or related field",
"Scuba diving certification",
"Experience with underwater surveys",
],
"deadline": "2025-03-31",
"url": "https://example.com/positions/marine-phd",
}
# Process through the pipeline
result = pipeline.process_source("job_api_single", data=custom_data)
print(f"Success: {result['success']}")
if result['success']:
print(f"Entry created and will be evaluated for relevance")
pipeline.shutdown()
def example_3_batch_relevance_filtering():
"""Example: Manually trigger Layer 3 batch processing."""
print("\n=== Example 3: Batch Relevance Filtering ===\n")
setup_logging(log_level="INFO")
pipeline = PipelineOrchestrator(config_dir="config")
# Run Layer 3 on pending entries
result = pipeline.run_layer3_batch(batch_size=20)
print(f"Success: {result['success']}")
if result['success']:
print(f"Processed: {result.get('processed', 0)}")
print(f"Relevant: {result.get('relevant', 0)}")
print(f"Not Relevant: {result.get('not_relevant', 0)}")
print(f"Quarantined: {result.get('quarantined', 0)}")
pipeline.shutdown()
def example_4_process_all_sources():
"""Example: Process all enabled sources."""
print("\n=== Example 4: Process All Sources ===\n")
setup_logging(log_level="INFO")
pipeline = PipelineOrchestrator(config_dir="config")
# Process all sources
result = pipeline.process_all_sources()
print(f"Total Sources: {result['total_sources']}")
print(f"Successful: {result['successful']}")
print(f"Failed: {result['failed']}")
pipeline.shutdown()
def example_5_direct_api_integration():
"""Example: Direct integration with components."""
print("\n=== Example 5: Direct Component Integration ===\n")
setup_logging(log_level="DEBUG")
from src.core import ConfigLoader, LLMClient, DatabaseManager
from src.layer2 import PromptBuilder
# Load configuration
config = ConfigLoader("config")
# Initialize database
db_config = config.get_database_config()
db = DatabaseManager(db_config)
# Initialize LLM client
llm = LLMClient()
# Test LLM call with validation
messages = [{"role": "user", "content": "What is marine biology?"}]
validation_config = {
"enabled": True,
"parallel_calls": 3,
"agreement_threshold": "majority",
}
llm_settings = {
"endpoint": "http://localhost:10006",
"intelligence_level": "low",
"max_wait_seconds": 20,
"options": {"max_tokens": 100, "temperature": 0.3},
}
result, metadata = llm.call_with_validation(
messages=messages,
validation_config=validation_config,
llm_settings=llm_settings,
)
print(f"Success: {result.get('success')}")
print(f"Validation Enabled: {metadata.get('validation_enabled')}")
print(f"Agreement Achieved: {metadata.get('agreement_achieved')}")
print(f"Response: {result.get('content', '')[:200]}...")
if __name__ == "__main__":
print("=" * 60)
print("Data Processing Framework - Usage Examples")
print("=" * 60)
# Run examples
try:
example_1_process_single_source()
# example_2_process_with_custom_data()
# example_3_batch_relevance_filtering()
# example_4_process_all_sources()
# example_5_direct_api_integration()
except Exception as e:
print(f"\nError running examples: {e}")
import traceback
traceback.print_exc()