File size: 25,185 Bytes
1921c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3db3fd3
 
 
1921c84
 
 
 
 
 
3db3fd3
 
1921c84
3db3fd3
1921c84
 
 
 
 
 
3db3fd3
 
1921c84
3db3fd3
1921c84
 
 
 
 
 
3db3fd3
 
1921c84
3db3fd3
1921c84
 
 
 
 
 
3db3fd3
 
1921c84
3db3fd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d0eb81e
 
 
b345460
d0eb81e
 
 
 
 
 
1921c84
 
 
 
 
 
 
 
 
 
 
3db3fd3
 
d0eb81e
 
1921c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3db3fd3
 
 
 
 
 
 
 
d0eb81e
 
1921c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b345460
1921c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b345460
1921c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b345460
1921c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b345460
1921c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3db3fd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b345460
3db3fd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b345460
3db3fd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b345460
3db3fd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b345460
3db3fd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d0eb81e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1921c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
"""
Model Manager Module
Supports multiple AI models for semantic analysis of papers
"""

import os
from typing import Dict, List, Optional
import requests


class ModelManager:
    """Manage multiple AI models for semantic paper analysis"""
    
    def __init__(self):
        self.current_model = "keyword"  # Default to keyword-based
        self.model_configs = {
            "keyword": {
                "name": "Keyword-Based",
                "description": "Fast keyword matching without AI models",
                "requires_api_key": False,
                "cost": "Free",
                "speed": "Fastest",
                "accuracy": "Basic"
            },
            "openai": {
                "name": "OpenAI GPT",
                "description": "GPT-4/GPT-3.5 for semantic understanding",
                "requires_api_key": True,
                "cost": "Paid",
                "speed": "Fast",
                "accuracy": "Excellent",
                "api_key_env": "OPENAI_API_KEY",
                "models": ["gpt-4", "gpt-4-turbo", "gpt-3.5-turbo", "gpt-4o"]
            },
            "anthropic": {
                "name": "Anthropic Claude",
                "description": "Claude for advanced semantic analysis",
                "requires_api_key": True,
                "cost": "Paid",
                "speed": "Fast",
                "accuracy": "Excellent",
                "api_key_env": "ANTHROPIC_API_KEY",
                "models": ["claude-3-opus", "claude-3-sonnet", "claude-3-haiku", "claude-3.5-sonnet"]
            },
            "ollama": {
                "name": "Ollama (Local)",
                "description": "Local models via Ollama (free, requires installation)",
                "requires_api_key": False,
                "cost": "Free",
                "speed": "Medium",
                "accuracy": "Good",
                "base_url": "http://localhost:11434",
                "models": ["llama2", "llama3", "mistral", "neural-chat", "codellama", "phi3", "gemma", "qwen"]
            },
            "huggingface": {
                "name": "Hugging Face Inference",
                "description": "Hugging Face inference API for various models",
                "requires_api_key": True,
                "cost": "Free tier available",
                "speed": "Medium",
                "accuracy": "Good",
                "api_key_env": "HUGGINGFACE_API_KEY",
                "models": [
                    "meta-llama/Llama-2-7b-chat-hf",
                    "meta-llama/Llama-3-8b-chat-hf",
                    "mistralai/Mistral-7B-Instruct-v0.2",
                    "google/gemma-7b-it",
                    "microsoft/Phi-3-mini-4k-instruct",
                    "Qwen/Qwen2-7B-Instruct"
                ]
            },
            "cohere": {
                "name": "Cohere Command",
                "description": "Cohere's Command models for text analysis",
                "requires_api_key": True,
                "cost": "Paid (free tier available)",
                "speed": "Fast",
                "accuracy": "Good",
                "api_key_env": "COHERE_API_KEY",
                "models": ["command", "command-light", "command-nightly"]
            },
            "google": {
                "name": "Google Gemini",
                "description": "Google's Gemini models for semantic understanding",
                "requires_api_key": True,
                "cost": "Paid (free tier available)",
                "speed": "Fast",
                "accuracy": "Excellent",
                "api_key_env": "GOOGLE_API_KEY",
                "models": ["gemini-pro", "gemini-pro-vision", "gemini-1.5-pro"]
            },
            "together": {
                "name": "Together AI",
                "description": "Together AI's hosted open-source models",
                "requires_api_key": True,
                "cost": "Paid (free tier available)",
                "speed": "Fast",
                "accuracy": "Good",
                "api_key_env": "TOGETHER_API_KEY",
                "models": [
                    "meta-llama/Llama-2-70b-chat-hf",
                    "mistralai/Mixtral-8x7B-Instruct-v0.1",
                    "togethercomputer/RedPajama-INCITE-Chat-7B"
                ]
            },
            "replicate": {
                "name": "Replicate",
                "description": "Replicate's hosted models API",
                "requires_api_key": True,
                "cost": "Pay-per-use",
                "speed": "Variable",
                "accuracy": "Good",
                "api_key_env": "REPLICATE_API_KEY",
                "models": [
                    "meta/llama-2-70b-chat",
                    "mistralai/mixtral-8x7b-instruct-v0.1",
                    "stabilityai/stable-diffusion-xl-base-1.0"
                ]
            },
            "deepseek": {
                "name": "DeepSeek-R1",
                "description": "DeepSeek-R1 with Chain of Thought reasoning for AI intelligence classification",
                "requires_api_key": False,
                "cost": "Free (Hugging Face Inference)",
                "speed": "Medium",
                "accuracy": "Excellent",
                "reasoning": True,
                "model_id": "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"
            }
        }
    
    def get_available_models(self) -> List[Dict]:
        """Get list of available models with their configurations"""
        return [
            {
                "id": model_id,
                "name": config["name"],
                "description": config["description"],
                "requires_api_key": config["requires_api_key"],
                "cost": config["cost"],
                "speed": config.get("speed", "N/A"),
                "accuracy": config.get("accuracy", "N/A"),
                "reasoning": config.get("reasoning", False)
            }
            for model_id, config in self.model_configs.items()
        ]
    
    def set_model(self, model_id: str) -> bool:
        """Set the current model for analysis"""
        if model_id in self.model_configs:
            self.current_model = model_id
            return True
        return False
    
    def get_current_model(self) -> str:
        """Get the current model ID"""
        return self.current_model
    
    def check_api_key(self, model_id: str) -> bool:
        """Check if API key is available for a model"""
        config = self.model_configs.get(model_id, {})
        if not config.get("requires_api_key", False):
            return True
        
        api_key_env = config.get("api_key_env")
        if api_key_env:
            return bool(os.getenv(api_key_env))
        return False
    
    def analyze_paper_semantic(self, paper_data: Dict, model_id: Optional[str] = None) -> Dict:
        """
        Analyze a paper using semantic understanding with the specified model
        
        Args:
            paper_data: Paper dictionary with title, summary, etc.
            model_id: Model to use (defaults to current model)
            
        Returns:
            Dictionary with semantic analysis results
        """
        model_id = model_id or self.current_model
        
        if model_id == "keyword":
            # Fall back to keyword-based analysis
            return self._keyword_analysis(paper_data)
        elif model_id == "openai":
            return self._openai_analysis(paper_data)
        elif model_id == "anthropic":
            return self._anthropic_analysis(paper_data)
        elif model_id == "ollama":
            return self._ollama_analysis(paper_data)
        elif model_id == "huggingface":
            return self._huggingface_analysis(paper_data)
        elif model_id == "cohere":
            return self._cohere_analysis(paper_data)
        elif model_id == "google":
            return self._google_analysis(paper_data)
        elif model_id == "together":
            return self._together_analysis(paper_data)
        elif model_id == "replicate":
            return self._replicate_analysis(paper_data)
        elif model_id == "deepseek":
            return self._deepseek_analysis(paper_data)
        else:
            return self._keyword_analysis(paper_data)
    
    def _keyword_analysis(self, paper_data: Dict) -> Dict:
        """Keyword-based analysis (fallback)"""
        return {
            "model_used": "keyword",
            "semantic_relevance": 0.0,
            "key_concepts": [],
            "reasoning": "Keyword-based analysis only"
        }
    
    def _openai_analysis(self, paper_data: Dict) -> Dict:
        """Analyze using OpenAI API"""
        try:
            import openai
            api_key = os.getenv("OPENAI_API_KEY")
            if not api_key:
                return self._keyword_analysis(paper_data)
            
            client = openai.OpenAI(api_key=api_key)
            
            prompt = f"""
            Analyze this AI paper for AGI (Artificial General Intelligence) and ASI (Artificial Super Intelligence) relevance.
            
            Title: {paper_data.get('title', '')}
            Summary: {paper_data.get('summary', '')}
            
            Provide:
            1. Semantic relevance score (0-100)
            2. Key concepts related to AI intelligence spectrum
            3. Brief reasoning
            
            Format as JSON with keys: semantic_relevance, key_concepts, reasoning
            """
            
            response = client.chat.completions.create(
                model="gpt-3.5-turbo",
                messages=[{"role": "user", "content": prompt}],
                temperature=0.3
            )
            
            import json
            result = json.loads(response.choices[0].message.content)
            result["model_used"] = "openai"
            return result
            
        except Exception as e:
            print(f"OpenAI analysis error: {e}")
            return self._keyword_analysis(paper_data)
    
    def _anthropic_analysis(self, paper_data: Dict) -> Dict:
        """Analyze using Anthropic Claude API"""
        try:
            import anthropic
            api_key = os.getenv("ANTHROPIC_API_KEY")
            if not api_key:
                return self._keyword_analysis(paper_data)
            
            client = anthropic.Anthropic(api_key=api_key)
            
            prompt = f"""
            Analyze this AI paper for AGI (Artificial General Intelligence) and ASI (Artificial Super Intelligence) relevance.
            
            Title: {paper_data.get('title', '')}
            Summary: {paper_data.get('summary', '')}
            
            Provide:
            1. Semantic relevance score (0-100)
            2. Key concepts related to AI intelligence spectrum
            3. Brief reasoning
            
            Format your response as JSON with keys: semantic_relevance, key_concepts, reasoning
            """
            
            response = client.messages.create(
                model="claude-3-haiku-20240307",
                max_tokens=1024,
                messages=[{"role": "user", "content": prompt}]
            )
            
            import json
            result = json.loads(response.content[0].text)
            result["model_used"] = "anthropic"
            return result
            
        except Exception as e:
            print(f"Anthropic analysis error: {e}")
            return self._keyword_analysis(paper_data)
    
    def _ollama_analysis(self, paper_data: Dict) -> Dict:
        """Analyze using local Ollama model"""
        try:
            base_url = self.model_configs["ollama"]["base_url"]
            prompt = f"""
            Analyze this AI paper for AGI (Artificial General Intelligence) and ASI (Artificial Super Intelligence) relevance.
            
            Title: {paper_data.get('title', '')}
            Summary: {paper_data.get('summary', '')}
            
            Provide:
            1. Semantic relevance score (0-100)
            2. Key concepts related to AI intelligence spectrum
            3. Brief reasoning
            
            Format as JSON with keys: semantic_relevance, key_concepts, reasoning
            """
            
            response = requests.post(
                f"{base_url}/api/generate",
                json={
                    "model": "llama2",
                    "prompt": prompt,
                    "stream": False
                },
                timeout=30
            )
            
            if response.status_code == 200:
                import json
                result = json.loads(response.json()["response"])
                result["model_used"] = "ollama"
                return result
            else:
                return self._keyword_analysis(paper_data)
                
        except Exception as e:
            print(f"Ollama analysis error: {e}")
            return self._keyword_analysis(paper_data)
    
    def _huggingface_analysis(self, paper_data: Dict) -> Dict:
        """Analyze using Hugging Face Inference API"""
        try:
            api_key = os.getenv("HUGGINGFACE_API_KEY")
            if not api_key:
                return self._keyword_analysis(paper_data)
            
            model_id = "mistralai/Mistral-7B-Instruct-v0.2"
            api_url = f"https://api-inference.huggingface.co/models/{model_id}"
            
            prompt = f"""
            Analyze this AI paper for AGI (Artificial General Intelligence) and ASI (Artificial Super Intelligence) relevance.
            
            Title: {paper_data.get('title', '')}
            Summary: {paper_data.get('summary', '')}
            
            Provide:
            1. Semantic relevance score (0-100)
            2. Key concepts related to AI intelligence spectrum
            3. Brief reasoning
            
            Format as JSON with keys: semantic_relevance, key_concepts, reasoning
            """
            
            response = requests.post(
                api_url,
                headers={"Authorization": f"Bearer {api_key}"},
                json={"inputs": prompt},
                timeout=30
            )
            
            if response.status_code == 200:
                import json
                result = json.loads(response.json()[0]["generated_text"])
                result["model_used"] = "huggingface"
                return result
            else:
                return self._keyword_analysis(paper_data)
                
        except Exception as e:
            print(f"Hugging Face analysis error: {e}")
            return self._keyword_analysis(paper_data)
    
    def _cohere_analysis(self, paper_data: Dict) -> Dict:
        """Analyze using Cohere Command API"""
        try:
            import cohere
            api_key = os.getenv("COHERE_API_KEY")
            if not api_key:
                return self._keyword_analysis(paper_data)
            
            client = cohere.Client(api_key)
            
            prompt = f"""
            Analyze this AI paper for AGI (Artificial General Intelligence) and ASI (Artificial Super Intelligence) relevance.
            
            Title: {paper_data.get('title', '')}
            Summary: {paper_data.get('summary', '')}
            
            Provide:
            1. Semantic relevance score (0-100)
            2. Key concepts related to AI intelligence spectrum
            3. Brief reasoning
            
            Format your response as JSON with keys: semantic_relevance, key_concepts, reasoning
            """
            
            response = client.chat(
                message=prompt,
                model="command"
            )
            
            import json
            result = json.loads(response.text)
            result["model_used"] = "cohere"
            return result
            
        except Exception as e:
            print(f"Cohere analysis error: {e}")
            return self._keyword_analysis(paper_data)
    
    def _google_analysis(self, paper_data: Dict) -> Dict:
        """Analyze using Google Gemini API"""
        try:
            import google.generativeai as genai
            api_key = os.getenv("GOOGLE_API_KEY")
            if not api_key:
                return self._keyword_analysis(paper_data)
            
            genai.configure(api_key=api_key)
            model = genai.GenerativeModel('gemini-pro')
            
            prompt = f"""
            Analyze this AI paper for AGI (Artificial General Intelligence) and ASI (Artificial Super Intelligence) relevance.
            
            Title: {paper_data.get('title', '')}
            Summary: {paper_data.get('summary', '')}
            
            Provide:
            1. Semantic relevance score (0-100)
            2. Key concepts related to AI intelligence spectrum
            3. Brief reasoning
            
            Format your response as JSON with keys: semantic_relevance, key_concepts, reasoning
            """
            
            response = model.generate_content(prompt)
            
            import json
            result = json.loads(response.text)
            result["model_used"] = "google"
            return result
            
        except Exception as e:
            print(f"Google analysis error: {e}")
            return self._keyword_analysis(paper_data)
    
    def _together_analysis(self, paper_data: Dict) -> Dict:
        """Analyze using Together AI API"""
        try:
            api_key = os.getenv("TOGETHER_API_KEY")
            if not api_key:
                return self._keyword_analysis(paper_data)
            
            model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
            api_url = "https://api.together.xyz/v1/chat/completions"
            
            prompt = f"""
            Analyze this AI paper for AGI (Artificial General Intelligence) and ASI (Artificial Super Intelligence) relevance.
            
            Title: {paper_data.get('title', '')}
            Summary: {paper_data.get('summary', '')}
            
            Provide:
            1. Semantic relevance score (0-100)
            2. Key concepts related to AI intelligence spectrum
            3. Brief reasoning
            
            Format as JSON with keys: semantic_relevance, key_concepts, reasoning
            """
            
            response = requests.post(
                api_url,
                headers={
                    "Authorization": f"Bearer {api_key}",
                    "Content-Type": "application/json"
                },
                json={
                    "model": model_id,
                    "messages": [{"role": "user", "content": prompt}]
                },
                timeout=30
            )
            
            if response.status_code == 200:
                import json
                result = json.loads(response.json()["choices"][0]["message"]["content"])
                result["model_used"] = "together"
                return result
            else:
                return self._keyword_analysis(paper_data)
                
        except Exception as e:
            print(f"Together AI analysis error: {e}")
            return self._keyword_analysis(paper_data)
    
    def _replicate_analysis(self, paper_data: Dict) -> Dict:
        """Analyze using Replicate API"""
        try:
            api_key = os.getenv("REPLICATE_API_KEY")
            if not api_key:
                return self._keyword_analysis(paper_data)
            
            # Using a simple text model for analysis
            model_id = "meta/llama-2-70b-chat"
            api_url = f"https://api.replicate.com/v1/models/{model_id}/predictions"
            
            prompt = f"""
            Analyze this AI paper for AGI (Artificial General Intelligence) and ASI (Artificial Super Intelligence) relevance.
            
            Title: {paper_data.get('title', '')}
            Summary: {paper_data.get('summary', '')}
            
            Provide:
            1. Semantic relevance score (0-100)
            2. Key concepts related to AI intelligence spectrum
            3. Brief reasoning
            
            Format as JSON with keys: semantic_relevance, key_concepts, reasoning
            """
            
            response = requests.post(
                api_url,
                headers={
                    "Authorization": f"Token {api_key}",
                    "Content-Type": "application/json"
                },
                json={
                    "input": {
                        "prompt": prompt
                    }
                },
                timeout=30
            )
            
            if response.status_code == 200:
                import json
                result = json.loads(response.json()["output"])
                result["model_used"] = "replicate"
                return result
            else:
                return self._keyword_analysis(paper_data)
                
        except Exception as e:
            print(f"Replicate analysis error: {e}")
            return self._keyword_analysis(paper_data)
    
    def _deepseek_analysis(self, paper_data: Dict) -> Dict:
        """Analyze using DeepSeek-R1 with Chain of Thought reasoning"""
        try:
            from huggingface_hub import InferenceClient
            
            model_id = self.model_configs["deepseek"]["model_id"]
            client = InferenceClient(model_id)
            
            system_instruction = (
                "You are an AI Research Scientist specializing in AGI, ASI, and ACI taxonomies. "
                "Your task is to analyze research paper abstracts and categorize them.\n\n"
                "CRITERIA:\n"
                "- AGI (Artificial General Intelligence): Focus on cross-domain reasoning, System 2 thinking, and 'generality.'\n"
                "- ASI (Artificial Superintelligence): Focus on recursive self-improvement, alignment at scale, and superhuman capabilities.\n"
                "- ACI (Artificial Collective Intelligence): Focus on multi-agent systems, swarm intelligence, and human-AI collaboration.\n"
                "- Narrow AI: Focus on specific, single-domain optimizations (e.g., just 'faster vision' or 'better LLM weights').\n\n"
                "OUTPUT FORMAT (JSON):\n"
                "{\n"
                '  "category": "AGI | ASI | ACI | Narrow AI",\n'
                '  "confidence_score": 0-100,\n'
                '  "analysis": "A brief technical justification of why this fits the category based on architectural depth.",\n'
                '  "aci_potential": "High/Low"\n'
                "}\n"
            )
            
            # Combine title and summary for analysis
            title = paper_data.get('title', '')
            summary = paper_data.get('summary', '')
            user_input = f"Analyze this abstract: {title}. {summary}"
            
            response = client.chat_completion(
                messages=[
                    {"role": "system", "content": system_instruction},
                    {"role": "user", "content": user_input}
                ],
                max_tokens=500,
                temperature=0.1
            )
            
            content = response.choices[0].message.content
            
            # DeepSeek-R1 sometimes includes <think> tags; we strip them for JSON parsing
            if "<think>" in content:
                content = content.split("<think>")[-1].strip()
            
            import json
            result = json.loads(content)
            result["model_used"] = "deepseek"
            return result
            
        except Exception as e:
            print(f"DeepSeek analysis error: {e}")
            return self._keyword_analysis(paper_data)
    
    def batch_analyze(self, papers: List[Dict], model_id: Optional[str] = None) -> List[Dict]:
        """
        Analyze multiple papers in batch
        
        Args:
            papers: List of paper dictionaries
            model_id: Model to use
            
        Returns:
            List of papers with added semantic analysis
        """
        analyzed_papers = []
        
        for paper in papers:
            semantic_result = self.analyze_paper_semantic(paper, model_id)
            paper['semantic_analysis'] = semantic_result
            analyzed_papers.append(paper)
        
        return analyzed_papers


# Test the model manager
if __name__ == "__main__":
    manager = ModelManager()
    
    # Test available models
    print("Available Models:")
    for model in manager.get_available_models():
        print(f"- {model['id']}: {model['name']} ({model['cost']})")
    
    # Test keyword analysis
    test_paper = {
        'title': 'Neural Computers: A New Computing Paradigm',
        'summary': 'Researchers propose Neural Computers that unify computation, memory, and I/O in a single learned runtime state, potentially leading to artificial general intelligence.'
    }
    
    print("\nTesting keyword analysis:")
    result = manager.analyze_paper_semantic(test_paper, "keyword")
    print(result)