cite-agent 1.0.3__py3-none-any.whl → 1.0.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cite-agent might be problematic. Click here for more details.
- cite_agent/__init__.py +1 -1
- cite_agent/agent_backend_only.py +30 -4
- cite_agent/cli.py +24 -26
- cite_agent/cli_conversational.py +294 -0
- cite_agent/enhanced_ai_agent.py +2776 -118
- cite_agent/streaming_ui.py +252 -0
- {cite_agent-1.0.3.dist-info → cite_agent-1.0.5.dist-info}/METADATA +4 -3
- cite_agent-1.0.5.dist-info/RECORD +50 -0
- {cite_agent-1.0.3.dist-info → cite_agent-1.0.5.dist-info}/top_level.txt +1 -0
- src/__init__.py +1 -0
- src/services/__init__.py +132 -0
- src/services/auth_service/__init__.py +3 -0
- src/services/auth_service/auth_manager.py +33 -0
- src/services/graph/__init__.py +1 -0
- src/services/graph/knowledge_graph.py +194 -0
- src/services/llm_service/__init__.py +5 -0
- src/services/llm_service/llm_manager.py +495 -0
- src/services/paper_service/__init__.py +5 -0
- src/services/paper_service/openalex.py +231 -0
- src/services/performance_service/__init__.py +1 -0
- src/services/performance_service/rust_performance.py +395 -0
- src/services/research_service/__init__.py +23 -0
- src/services/research_service/chatbot.py +2056 -0
- src/services/research_service/citation_manager.py +436 -0
- src/services/research_service/context_manager.py +1441 -0
- src/services/research_service/conversation_manager.py +597 -0
- src/services/research_service/critical_paper_detector.py +577 -0
- src/services/research_service/enhanced_research.py +121 -0
- src/services/research_service/enhanced_synthesizer.py +375 -0
- src/services/research_service/query_generator.py +777 -0
- src/services/research_service/synthesizer.py +1273 -0
- src/services/search_service/__init__.py +5 -0
- src/services/search_service/indexer.py +186 -0
- src/services/search_service/search_engine.py +342 -0
- src/services/simple_enhanced_main.py +287 -0
- cite_agent/__distribution__.py +0 -7
- cite_agent-1.0.3.dist-info/RECORD +0 -23
- {cite_agent-1.0.3.dist-info → cite_agent-1.0.5.dist-info}/WHEEL +0 -0
- {cite_agent-1.0.3.dist-info → cite_agent-1.0.5.dist-info}/entry_points.txt +0 -0
- {cite_agent-1.0.3.dist-info → cite_agent-1.0.5.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Simple Enhanced Main Application - Working version with core capabilities
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import logging
|
|
7
|
+
import os
|
|
8
|
+
import time
|
|
9
|
+
from datetime import datetime, timezone
|
|
10
|
+
from fastapi import FastAPI, Request, HTTPException
|
|
11
|
+
from fastapi.middleware.cors import CORSMiddleware
|
|
12
|
+
from fastapi.responses import JSONResponse
|
|
13
|
+
from pydantic import BaseModel
|
|
14
|
+
from typing import Optional, Dict, Any
|
|
15
|
+
|
|
16
|
+
# Import our enhanced services
|
|
17
|
+
from services.reasoning_engine.reasoning_engine import ReasoningEngine
|
|
18
|
+
from services.tool_framework.tool_manager import ToolManager
|
|
19
|
+
from services.context_manager.advanced_context import AdvancedContextManager
|
|
20
|
+
|
|
21
|
+
# Configure logging
|
|
22
|
+
logging.basicConfig(level=logging.INFO)
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
# Initialize FastAPI app
|
|
26
|
+
app = FastAPI(
|
|
27
|
+
title="Nocturnal Archive API - Enhanced",
|
|
28
|
+
description="Production-grade AI-powered research platform with advanced reasoning capabilities",
|
|
29
|
+
version="3.0.0",
|
|
30
|
+
docs_url="/docs",
|
|
31
|
+
redoc_url="/redoc"
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _utc_timestamp() -> str:
|
|
36
|
+
return datetime.now(timezone.utc).isoformat()
|
|
37
|
+
|
|
38
|
+
# Add CORS middleware
|
|
39
|
+
app.add_middleware(
|
|
40
|
+
CORSMiddleware,
|
|
41
|
+
allow_origins=["*"], # Configure for production
|
|
42
|
+
allow_credentials=True,
|
|
43
|
+
allow_methods=["*"],
|
|
44
|
+
allow_headers=["*"],
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# Initialize enhanced services
|
|
48
|
+
tool_manager = ToolManager()
|
|
49
|
+
context_manager = AdvancedContextManager()
|
|
50
|
+
reasoning_engine = ReasoningEngine()
|
|
51
|
+
|
|
52
|
+
# Pydantic models for request/response
|
|
53
|
+
class ChatRequest(BaseModel):
|
|
54
|
+
message: str
|
|
55
|
+
session_id: Optional[str] = None
|
|
56
|
+
use_advanced_reasoning: Optional[bool] = True
|
|
57
|
+
|
|
58
|
+
class ResearchRequest(BaseModel):
|
|
59
|
+
topic: str
|
|
60
|
+
max_results: Optional[int] = 10
|
|
61
|
+
use_advanced_reasoning: Optional[bool] = True
|
|
62
|
+
|
|
63
|
+
class ReasoningRequest(BaseModel):
|
|
64
|
+
problem_description: str
|
|
65
|
+
context: Optional[Dict[str, Any]] = None
|
|
66
|
+
user_id: Optional[str] = None
|
|
67
|
+
|
|
68
|
+
class ToolExecutionRequest(BaseModel):
|
|
69
|
+
tool_name: Optional[str] = None
|
|
70
|
+
task_description: str
|
|
71
|
+
context: Optional[Dict[str, Any]] = None
|
|
72
|
+
auto_select_tool: Optional[bool] = True
|
|
73
|
+
|
|
74
|
+
# Health check endpoints
|
|
75
|
+
@app.get("/")
|
|
76
|
+
async def root():
|
|
77
|
+
"""Root endpoint with service information."""
|
|
78
|
+
return {
|
|
79
|
+
"service": "Nocturnal Archive API - Enhanced",
|
|
80
|
+
"version": "3.0.0",
|
|
81
|
+
"status": "healthy",
|
|
82
|
+
"environment": os.getenv("ENVIRONMENT", "development"),
|
|
83
|
+
"capabilities": [
|
|
84
|
+
"Advanced Reasoning Engine",
|
|
85
|
+
"Dynamic Tool Framework",
|
|
86
|
+
"Code Execution Environment",
|
|
87
|
+
"Advanced Context Management",
|
|
88
|
+
"Academic Research & Synthesis",
|
|
89
|
+
"Multi-LLM Integration"
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@app.get("/health")
|
|
94
|
+
async def health_check():
|
|
95
|
+
"""Health check endpoint."""
|
|
96
|
+
return {
|
|
97
|
+
"status": "healthy",
|
|
98
|
+
"timestamp": _utc_timestamp(),
|
|
99
|
+
"services": {
|
|
100
|
+
"reasoning_engine": "operational",
|
|
101
|
+
"tool_framework": "operational",
|
|
102
|
+
"context_manager": "operational"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@app.get("/api/status")
|
|
107
|
+
async def api_status():
|
|
108
|
+
"""API status endpoint."""
|
|
109
|
+
return {
|
|
110
|
+
"status": "operational",
|
|
111
|
+
"services": {
|
|
112
|
+
"reasoning": "operational",
|
|
113
|
+
"tools": "operational",
|
|
114
|
+
"context": "operational"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
# Enhanced Reasoning Endpoints
|
|
119
|
+
@app.post("/api/reasoning/solve")
|
|
120
|
+
async def solve_problem(request: ReasoningRequest):
|
|
121
|
+
"""Solve complex problems using advanced reasoning."""
|
|
122
|
+
try:
|
|
123
|
+
# Solve the problem using reasoning engine
|
|
124
|
+
result = await reasoning_engine.solve_problem(
|
|
125
|
+
problem_description=request.problem_description,
|
|
126
|
+
context=request.context,
|
|
127
|
+
user_id=request.user_id
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
"status": "success",
|
|
132
|
+
"result": result
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
except Exception as e:
|
|
136
|
+
logger.error(f"Reasoning error: {str(e)}")
|
|
137
|
+
raise HTTPException(status_code=500, detail=f"Reasoning failed: {str(e)}")
|
|
138
|
+
|
|
139
|
+
# Enhanced Tool Framework Endpoints
|
|
140
|
+
@app.post("/api/tools/execute")
|
|
141
|
+
async def execute_tool(request: ToolExecutionRequest):
|
|
142
|
+
"""Execute a tool with dynamic selection."""
|
|
143
|
+
try:
|
|
144
|
+
# Execute tool
|
|
145
|
+
if request.auto_select_tool:
|
|
146
|
+
result = await tool_manager.execute_with_auto_selection(
|
|
147
|
+
task_description=request.task_description,
|
|
148
|
+
context=request.context
|
|
149
|
+
)
|
|
150
|
+
else:
|
|
151
|
+
if not request.tool_name:
|
|
152
|
+
raise HTTPException(status_code=400, detail="Tool name required when auto_select_tool is False")
|
|
153
|
+
|
|
154
|
+
result = await tool_manager.execute_tool(
|
|
155
|
+
tool_name=request.tool_name,
|
|
156
|
+
task_description=request.task_description,
|
|
157
|
+
context=request.context
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
"status": "success",
|
|
162
|
+
"result": result
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
except Exception as e:
|
|
166
|
+
logger.error(f"Tool execution error: {str(e)}")
|
|
167
|
+
raise HTTPException(status_code=500, detail=f"Tool execution failed: {str(e)}")
|
|
168
|
+
|
|
169
|
+
@app.get("/api/tools/available")
|
|
170
|
+
async def get_available_tools():
|
|
171
|
+
"""Get list of available tools."""
|
|
172
|
+
try:
|
|
173
|
+
tools = tool_manager.get_available_tools()
|
|
174
|
+
tool_capabilities = {}
|
|
175
|
+
|
|
176
|
+
for tool in tools:
|
|
177
|
+
tool_capabilities[tool] = tool_manager.get_tool_capabilities(tool)
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
"status": "success",
|
|
181
|
+
"tools": tools,
|
|
182
|
+
"capabilities": tool_capabilities
|
|
183
|
+
}
|
|
184
|
+
except Exception as e:
|
|
185
|
+
logger.error(f"Failed to get available tools: {str(e)}")
|
|
186
|
+
raise HTTPException(status_code=500, detail=f"Failed to get available tools: {str(e)}")
|
|
187
|
+
|
|
188
|
+
# Enhanced Context Management Endpoints
|
|
189
|
+
@app.post("/api/context/process")
|
|
190
|
+
async def process_context(request: ChatRequest):
|
|
191
|
+
"""Process interaction and update context."""
|
|
192
|
+
try:
|
|
193
|
+
session_id = request.session_id or "default_session"
|
|
194
|
+
|
|
195
|
+
# Generate response (this would integrate with existing chat logic)
|
|
196
|
+
response = f"Enhanced response to: {request.message}"
|
|
197
|
+
|
|
198
|
+
# Process interaction in context manager
|
|
199
|
+
result = await context_manager.process_interaction(
|
|
200
|
+
user_input=request.message,
|
|
201
|
+
response=response,
|
|
202
|
+
session_id=session_id,
|
|
203
|
+
user_id="anonymous"
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
"status": "success",
|
|
208
|
+
"response": response,
|
|
209
|
+
"context_result": result
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
except Exception as e:
|
|
213
|
+
logger.error(f"Context processing error: {str(e)}")
|
|
214
|
+
raise HTTPException(status_code=500, detail=f"Context processing failed: {str(e)}")
|
|
215
|
+
|
|
216
|
+
@app.get("/api/context/retrieve")
|
|
217
|
+
async def retrieve_context(query: str, session_id: Optional[str] = None):
|
|
218
|
+
"""Retrieve relevant context for a query."""
|
|
219
|
+
try:
|
|
220
|
+
result = await context_manager.retrieve_relevant_context(
|
|
221
|
+
query=query,
|
|
222
|
+
session_id=session_id,
|
|
223
|
+
user_id="anonymous"
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
"status": "success",
|
|
228
|
+
"result": result
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
except Exception as e:
|
|
232
|
+
logger.error(f"Context retrieval error: {str(e)}")
|
|
233
|
+
raise HTTPException(status_code=500, detail=f"Context retrieval failed: {str(e)}")
|
|
234
|
+
|
|
235
|
+
# Enhanced Chat Endpoint with Advanced Reasoning
|
|
236
|
+
@app.post("/api/enhanced-chat")
|
|
237
|
+
async def enhanced_chat_endpoint(request: ChatRequest):
|
|
238
|
+
"""Enhanced chat endpoint with advanced reasoning capabilities."""
|
|
239
|
+
try:
|
|
240
|
+
session_id = request.session_id or "enhanced_session"
|
|
241
|
+
|
|
242
|
+
# Use advanced reasoning if requested
|
|
243
|
+
if request.use_advanced_reasoning:
|
|
244
|
+
# Solve as a reasoning problem
|
|
245
|
+
reasoning_result = await reasoning_engine.solve_problem(
|
|
246
|
+
problem_description=request.message,
|
|
247
|
+
context={"session_id": session_id, "user_id": "anonymous"},
|
|
248
|
+
user_id="anonymous"
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
response = reasoning_result.get("solution", "No solution generated")
|
|
252
|
+
else:
|
|
253
|
+
# Use simple response
|
|
254
|
+
response = f"Standard response to: {request.message}"
|
|
255
|
+
|
|
256
|
+
# Process interaction in context manager
|
|
257
|
+
await context_manager.process_interaction(
|
|
258
|
+
user_input=request.message,
|
|
259
|
+
response=str(response),
|
|
260
|
+
session_id=session_id,
|
|
261
|
+
user_id="anonymous"
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
"response": response,
|
|
266
|
+
"session_id": session_id,
|
|
267
|
+
"timestamp": _utc_timestamp(),
|
|
268
|
+
"mode": "enhanced_reasoning" if request.use_advanced_reasoning else "standard"
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
except Exception as e:
|
|
272
|
+
logger.error(f"Enhanced chat error: {str(e)}")
|
|
273
|
+
raise HTTPException(status_code=500, detail=f"Chat failed: {str(e)}")
|
|
274
|
+
|
|
275
|
+
# Error handling
|
|
276
|
+
@app.exception_handler(Exception)
|
|
277
|
+
async def global_exception_handler(request: Request, exc: Exception):
|
|
278
|
+
"""Global exception handler."""
|
|
279
|
+
logger.error(f"Unhandled exception: {str(exc)}")
|
|
280
|
+
return JSONResponse(
|
|
281
|
+
status_code=500,
|
|
282
|
+
content={"detail": "Internal server error"}
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
if __name__ == "__main__":
|
|
286
|
+
import uvicorn
|
|
287
|
+
uvicorn.run(app, host="127.0.0.1", port=8003)
|
cite_agent/__distribution__.py
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
cite_agent/__distribution__.py,sha256=U7-p-qBMX7WrQD6WWjRC5b-PswXnlrqAox7EYnLogqI,178
|
|
2
|
-
cite_agent/__init__.py,sha256=bIPMfQXuaDOCAZE9pWvqpRbuBlgOvfh9uLQ3pakBMOY,1643
|
|
3
|
-
cite_agent/account_client.py,sha256=yLuzhIJoIZuXHXGbaVMzDxRATQwcy-wiaLnUrDuwUhI,5725
|
|
4
|
-
cite_agent/agent_backend_only.py,sha256=Rmi3cUCcTMSHRxZu6MK2rZwme5SCfilxqn0BsoIds_U,5375
|
|
5
|
-
cite_agent/ascii_plotting.py,sha256=lk8BaECs6fmjtp4iH12G09-frlRehAN7HLhHt2crers,8570
|
|
6
|
-
cite_agent/auth.py,sha256=CYBNv8r1_wfdhsx-YcWOiXCiKvPBymaMca6w7JV__FQ,9809
|
|
7
|
-
cite_agent/backend_only_client.py,sha256=WqLF8x7aXTro2Q3ehqKMsdCg53s6fNk9Hy86bGxqmmw,2561
|
|
8
|
-
cite_agent/cli.py,sha256=NYg-gCdV8M6WhUN9Y6TawsjdITfo_7WPOa6ZIknN4dc,18564
|
|
9
|
-
cite_agent/cli_enhanced.py,sha256=EAaSw9qtiYRWUXF6_05T19GCXlz9cCSz6n41ASnXIPc,7407
|
|
10
|
-
cite_agent/dashboard.py,sha256=VGV5XQU1PnqvTsxfKMcue3j2ri_nvm9Be6O5aVays_w,10502
|
|
11
|
-
cite_agent/enhanced_ai_agent.py,sha256=Rmi3cUCcTMSHRxZu6MK2rZwme5SCfilxqn0BsoIds_U,5375
|
|
12
|
-
cite_agent/rate_limiter.py,sha256=-0fXx8Tl4zVB4O28n9ojU2weRo-FBF1cJo9Z5jC2LxQ,10908
|
|
13
|
-
cite_agent/setup_config.py,sha256=kNZNr5cZmCXr43rGWNenNJXZ1Kfz7PrdLXpAqxM7WgM,16404
|
|
14
|
-
cite_agent/telemetry.py,sha256=55kXdHvI24ZsEkbFtihcjIfJt2oiSXcEpLzTxQ3KCdQ,2916
|
|
15
|
-
cite_agent/ui.py,sha256=r1OAeY3NSeqhAjJYmEBH9CaennBuibFAz1Mur6YF80E,6134
|
|
16
|
-
cite_agent/updater.py,sha256=kL2GYL1AKoZ9JoTXxFT5_AkvYvObcCrO2sIVyBw9JgU,7057
|
|
17
|
-
cite_agent/web_search.py,sha256=j-BRhT8EBC6BEPgACQPeVwB1SVGKDz4XLM7sowacvSc,6587
|
|
18
|
-
cite_agent-1.0.3.dist-info/licenses/LICENSE,sha256=XJkyO4IymhSUniN1ENY6lLrL2729gn_rbRlFK6_Hi9M,1074
|
|
19
|
-
cite_agent-1.0.3.dist-info/METADATA,sha256=Ajj8pUFoOsTBQuNMRB6dELRoGhFi90CYbPSq1wQuO0I,6856
|
|
20
|
-
cite_agent-1.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
21
|
-
cite_agent-1.0.3.dist-info/entry_points.txt,sha256=bJ0u28nFIxQKH1PWQ2ak4PV-FAjhoxTC7YADEdDenFw,83
|
|
22
|
-
cite_agent-1.0.3.dist-info/top_level.txt,sha256=NNfD8pxDZzBK8tjDIpCs2BW9Va-OQ5qUFbEx0SgmyIE,11
|
|
23
|
-
cite_agent-1.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|