prado-os 0.1.0__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.
- prado/__init__.py +9 -0
- prado/__main__.py +12 -0
- prado/ai/__init__.py +76 -0
- prado/ai/base.py +145 -0
- prado/ai/deterministic.py +168 -0
- prado/ai/external.py +103 -0
- prado/ai/ollama.py +110 -0
- prado/auth/__init__.py +19 -0
- prado/auth/credentials.py +376 -0
- prado/auth/mfa.py +361 -0
- prado/auth/saml.py +230 -0
- prado/auth/session.py +221 -0
- prado/cli.py +1489 -0
- prado/config.py +458 -0
- prado/core/__init__.py +108 -0
- prado/core/adoption.py +244 -0
- prado/core/discovery.py +508 -0
- prado/core/downloader.py +411 -0
- prado/core/overwrite.py +217 -0
- prado/core/parser.py +436 -0
- prado/core/router.py +286 -0
- prado/discovery.py +30 -0
- prado/downloader.py +34 -0
- prado/exceptions.py +93 -0
- prado/exporters/__init__.py +59 -0
- prado/exporters/calendar.py +239 -0
- prado/exporters/changelog.py +177 -0
- prado/exporters/dashboard.py +273 -0
- prado/exporters/gcalendar.py +336 -0
- prado/i18n.py +302 -0
- prado/mail/__init__.py +32 -0
- prado/mail/client.py +817 -0
- prado/mail/tui.py +584 -0
- prado/notifications/__init__.py +49 -0
- prado/notifications/desktop.py +171 -0
- prado/notifications/dispatcher.py +186 -0
- prado/notifications/email.py +103 -0
- prado/notifications/webhooks.py +221 -0
- prado/onboarding/__init__.py +37 -0
- prado/onboarding/star.py +241 -0
- prado/onboarding/wizard.py +609 -0
- prado/parser.py +26 -0
- prado/routing.py +26 -0
- prado/scheduler/__init__.py +41 -0
- prado/scheduler/daemon.py +596 -0
- prado/scheduler/doctor.py +594 -0
- prado/state.py +476 -0
- prado_os-0.1.0.dist-info/METADATA +263 -0
- prado_os-0.1.0.dist-info/RECORD +52 -0
- prado_os-0.1.0.dist-info/WHEEL +4 -0
- prado_os-0.1.0.dist-info/entry_points.txt +2 -0
- prado_os-0.1.0.dist-info/licenses/LICENSE +661 -0
prado/__init__.py
ADDED
prado/__main__.py
ADDED
prado/ai/__init__.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pluggable BYO-AI Layer for PradoOS.
|
|
3
|
+
|
|
4
|
+
Provides:
|
|
5
|
+
- 100% Free & Deterministic rule-based fallback by default
|
|
6
|
+
- Local Ollama integration
|
|
7
|
+
- External OpenAI / DeepSeek / Gemini compatible completions
|
|
8
|
+
- Factory function get_ai_provider()
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from typing import Optional
|
|
14
|
+
|
|
15
|
+
from prado.ai.base import (
|
|
16
|
+
AIConfig,
|
|
17
|
+
AIProvider,
|
|
18
|
+
DailyStudyPlan,
|
|
19
|
+
ForumSummary,
|
|
20
|
+
StudyBlock,
|
|
21
|
+
StudyPlan,
|
|
22
|
+
)
|
|
23
|
+
from prado.ai.deterministic import DeterministicFallbackProvider
|
|
24
|
+
from prado.ai.external import ExternalAIProvider
|
|
25
|
+
from prado.ai.ollama import OllamaProvider
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_ai_provider(config: Optional[AIConfig] = None) -> AIProvider:
|
|
29
|
+
"""
|
|
30
|
+
Factory creating configured AIProvider with guaranteed deterministic fallback.
|
|
31
|
+
Free by default if no configuration or key is provided.
|
|
32
|
+
"""
|
|
33
|
+
if config is None or not config.enabled or config.provider == "none":
|
|
34
|
+
return DeterministicFallbackProvider()
|
|
35
|
+
|
|
36
|
+
if config.provider == "ollama":
|
|
37
|
+
provider = OllamaProvider(
|
|
38
|
+
base_url=config.base_url or "http://localhost:11434",
|
|
39
|
+
model=config.model or "llama3.2",
|
|
40
|
+
timeout_seconds=config.timeout_seconds,
|
|
41
|
+
)
|
|
42
|
+
if provider.is_available():
|
|
43
|
+
return provider
|
|
44
|
+
return DeterministicFallbackProvider()
|
|
45
|
+
|
|
46
|
+
if config.provider in ("openai", "deepseek", "gemini", "custom"):
|
|
47
|
+
if not config.api_key:
|
|
48
|
+
return DeterministicFallbackProvider()
|
|
49
|
+
base_urls = {
|
|
50
|
+
"openai": "https://api.openai.com/v1",
|
|
51
|
+
"deepseek": "https://api.deepseek.com/v1",
|
|
52
|
+
"gemini": "https://generativelanguage.googleapis.com/v1beta/openai",
|
|
53
|
+
}
|
|
54
|
+
target_url = config.base_url or base_urls.get(config.provider, "https://api.openai.com/v1")
|
|
55
|
+
return ExternalAIProvider(
|
|
56
|
+
api_key=config.api_key,
|
|
57
|
+
base_url=target_url,
|
|
58
|
+
model=config.model or "gpt-4o-mini",
|
|
59
|
+
timeout_seconds=config.timeout_seconds,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
return DeterministicFallbackProvider()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
__all__ = [
|
|
66
|
+
"AIConfig",
|
|
67
|
+
"AIProvider",
|
|
68
|
+
"DailyStudyPlan",
|
|
69
|
+
"DeterministicFallbackProvider",
|
|
70
|
+
"ExternalAIProvider",
|
|
71
|
+
"ForumSummary",
|
|
72
|
+
"OllamaProvider",
|
|
73
|
+
"StudyBlock",
|
|
74
|
+
"StudyPlan",
|
|
75
|
+
"get_ai_provider",
|
|
76
|
+
]
|
prado/ai/base.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Abstract Base Layer & DTOs for Pluggable BYO-AI in PradoOS.
|
|
3
|
+
|
|
4
|
+
Supports:
|
|
5
|
+
- Abstract contract for LLM generation, forum summarization, and study plan synthesis
|
|
6
|
+
- Structured DTOs (ForumSummary, StudyBlock, DailyStudyPlan, StudyPlan)
|
|
7
|
+
- AI configuration dataclass
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from abc import ABC, abstractmethod
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
import datetime
|
|
15
|
+
from typing import Any, Dict, List, Optional
|
|
16
|
+
|
|
17
|
+
from prado.core.downloader import DeadlineItem, ForumPost
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class AIConfig:
|
|
22
|
+
"""Configuration for pluggable BYO-AI providers."""
|
|
23
|
+
enabled: bool = False
|
|
24
|
+
provider: str = "none" # "none", "ollama", "openai", "deepseek", "gemini", "custom"
|
|
25
|
+
model: Optional[str] = None
|
|
26
|
+
base_url: Optional[str] = None
|
|
27
|
+
api_key: Optional[str] = None
|
|
28
|
+
temperature: float = 0.3
|
|
29
|
+
max_tokens: int = 1000
|
|
30
|
+
timeout_seconds: float = 30.0
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class ForumSummary:
|
|
35
|
+
"""Structured extraction of key items from forum announcements."""
|
|
36
|
+
forum_id: str
|
|
37
|
+
subject: str
|
|
38
|
+
author: str
|
|
39
|
+
executive_summary: str
|
|
40
|
+
key_dates: List[str] = field(default_factory=list)
|
|
41
|
+
action_items: List[str] = field(default_factory=list)
|
|
42
|
+
urgency: str = "normal" # "low", "normal", "urgent"
|
|
43
|
+
is_ai_generated: bool = False
|
|
44
|
+
|
|
45
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
46
|
+
return {
|
|
47
|
+
"forum_id": self.forum_id,
|
|
48
|
+
"subject": self.subject,
|
|
49
|
+
"author": self.author,
|
|
50
|
+
"executive_summary": self.executive_summary,
|
|
51
|
+
"key_dates": self.key_dates,
|
|
52
|
+
"action_items": self.action_items,
|
|
53
|
+
"urgency": self.urgency,
|
|
54
|
+
"is_ai_generated": self.is_ai_generated,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass
|
|
59
|
+
class StudyBlock:
|
|
60
|
+
"""An individual study block assigned to a specific course and task."""
|
|
61
|
+
course: str
|
|
62
|
+
task: str
|
|
63
|
+
priority: str # "high", "medium", "low"
|
|
64
|
+
estimated_hours: float
|
|
65
|
+
deadline_countdown_days: Optional[int] = None
|
|
66
|
+
rationale: str = ""
|
|
67
|
+
|
|
68
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
69
|
+
return {
|
|
70
|
+
"course": self.course,
|
|
71
|
+
"task": self.task,
|
|
72
|
+
"priority": self.priority,
|
|
73
|
+
"estimated_hours": self.estimated_hours,
|
|
74
|
+
"deadline_countdown_days": self.deadline_countdown_days,
|
|
75
|
+
"rationale": self.rationale,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@dataclass
|
|
80
|
+
class DailyStudyPlan:
|
|
81
|
+
"""Study blocks scheduled for a single calendar day."""
|
|
82
|
+
date: datetime.date
|
|
83
|
+
blocks: List[StudyBlock] = field(default_factory=list)
|
|
84
|
+
total_hours: float = 0.0
|
|
85
|
+
|
|
86
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
87
|
+
return {
|
|
88
|
+
"date": self.date.isoformat(),
|
|
89
|
+
"blocks": [b.to_dict() for b in self.blocks],
|
|
90
|
+
"total_hours": self.total_hours,
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@dataclass
|
|
95
|
+
class StudyPlan:
|
|
96
|
+
"""Full multi-day study schedule generated from upcoming deadlines."""
|
|
97
|
+
generated_at: datetime.datetime
|
|
98
|
+
horizon_days: int
|
|
99
|
+
days: List[DailyStudyPlan] = field(default_factory=list)
|
|
100
|
+
is_ai_generated: bool = False
|
|
101
|
+
notes: str = ""
|
|
102
|
+
|
|
103
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
104
|
+
return {
|
|
105
|
+
"generated_at": self.generated_at.isoformat(),
|
|
106
|
+
"horizon_days": self.horizon_days,
|
|
107
|
+
"days": [d.to_dict() for d in self.days],
|
|
108
|
+
"is_ai_generated": self.is_ai_generated,
|
|
109
|
+
"notes": self.notes,
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class AIProvider(ABC):
|
|
114
|
+
"""Abstract base class for all pluggable AI providers in PradoOS."""
|
|
115
|
+
|
|
116
|
+
@abstractmethod
|
|
117
|
+
def is_available(self) -> bool:
|
|
118
|
+
"""Checks if the provider endpoint is reachable and configured."""
|
|
119
|
+
pass
|
|
120
|
+
|
|
121
|
+
@abstractmethod
|
|
122
|
+
def generate(
|
|
123
|
+
self,
|
|
124
|
+
prompt: str,
|
|
125
|
+
system_prompt: Optional[str] = None,
|
|
126
|
+
max_tokens: int = 1000,
|
|
127
|
+
temperature: float = 0.3,
|
|
128
|
+
) -> str:
|
|
129
|
+
"""Generates raw text completion from the provider."""
|
|
130
|
+
pass
|
|
131
|
+
|
|
132
|
+
@abstractmethod
|
|
133
|
+
def summarize_forum_post(self, post: ForumPost) -> ForumSummary:
|
|
134
|
+
"""Summarizes forum announcements into structured findings."""
|
|
135
|
+
pass
|
|
136
|
+
|
|
137
|
+
@abstractmethod
|
|
138
|
+
def generate_study_plan(
|
|
139
|
+
self,
|
|
140
|
+
deadlines: List[DeadlineItem],
|
|
141
|
+
horizon_days: int = 7,
|
|
142
|
+
start_date: Optional[datetime.date] = None,
|
|
143
|
+
) -> StudyPlan:
|
|
144
|
+
"""Generates actionable daily study schedule based on deadlines."""
|
|
145
|
+
pass
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Deterministic Rule-Based Fallback Provider for PradoOS AI Layer.
|
|
3
|
+
|
|
4
|
+
Operates 100% offline, free, and deterministically without external models or API tokens.
|
|
5
|
+
Extracts dates, urgency tags, and synthesizes deadline-driven study schedules using pure logic.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import datetime
|
|
11
|
+
import re
|
|
12
|
+
from typing import List, Optional
|
|
13
|
+
|
|
14
|
+
from prado.ai.base import (
|
|
15
|
+
AIProvider,
|
|
16
|
+
DailyStudyPlan,
|
|
17
|
+
ForumSummary,
|
|
18
|
+
StudyBlock,
|
|
19
|
+
StudyPlan,
|
|
20
|
+
)
|
|
21
|
+
from prado.core.downloader import DeadlineItem, ForumPost
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DeterministicFallbackProvider(AIProvider):
|
|
25
|
+
"""
|
|
26
|
+
100% Free, deterministic, offline academic intelligence layer.
|
|
27
|
+
Requires ZERO API keys, tokens, or network connectivity.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
URGENT_KEYWORDS = {
|
|
31
|
+
"urgente",
|
|
32
|
+
"examen",
|
|
33
|
+
"prueba",
|
|
34
|
+
"evaluación",
|
|
35
|
+
"parcial",
|
|
36
|
+
"plazo",
|
|
37
|
+
"entrega",
|
|
38
|
+
"práctica",
|
|
39
|
+
"obligatorio",
|
|
40
|
+
"deadline",
|
|
41
|
+
"urgent",
|
|
42
|
+
"submission",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
DATE_REGEX = re.compile(
|
|
46
|
+
r"\b(?:\d{1,2}/\d{1,2}(?:/\d{2,4})?|\d{1,2}\s+de\s+[a-zA-Z]+(?:\s+de\s+\d{4})?)\b",
|
|
47
|
+
re.IGNORECASE,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
def is_available(self) -> bool:
|
|
51
|
+
return True
|
|
52
|
+
|
|
53
|
+
def generate(
|
|
54
|
+
self,
|
|
55
|
+
prompt: str,
|
|
56
|
+
system_prompt: Optional[str] = None,
|
|
57
|
+
max_tokens: int = 1000,
|
|
58
|
+
temperature: float = 0.3,
|
|
59
|
+
) -> str:
|
|
60
|
+
clean = " ".join(prompt.split())
|
|
61
|
+
return clean[:max_tokens] if len(clean) > max_tokens else clean
|
|
62
|
+
|
|
63
|
+
def summarize_forum_post(self, post: ForumPost) -> ForumSummary:
|
|
64
|
+
combined_text = f"{post.subject} {post.content}".lower()
|
|
65
|
+
|
|
66
|
+
# Urgency keyword detection
|
|
67
|
+
urgency = "normal"
|
|
68
|
+
if any(kw in combined_text for kw in self.URGENT_KEYWORDS):
|
|
69
|
+
urgency = "urgent"
|
|
70
|
+
|
|
71
|
+
# Regex key dates detection
|
|
72
|
+
dates = self.DATE_REGEX.findall(post.content)
|
|
73
|
+
|
|
74
|
+
# Action items extraction
|
|
75
|
+
action_items: List[str] = []
|
|
76
|
+
for line in post.content.splitlines():
|
|
77
|
+
line_str = line.strip()
|
|
78
|
+
if not line_str:
|
|
79
|
+
continue
|
|
80
|
+
if line_str.startswith(("-", "*", "•")) or any(
|
|
81
|
+
kw in line_str.lower() for kw in self.URGENT_KEYWORDS
|
|
82
|
+
):
|
|
83
|
+
action_items.append(line_str.lstrip("-*• "))
|
|
84
|
+
|
|
85
|
+
# Executive summary: take first 2 non-empty sentences
|
|
86
|
+
# Strip HTML tags first
|
|
87
|
+
text_without_html = re.sub(r"<[^>]+>", " ", post.content)
|
|
88
|
+
cleaned_content = " ".join(text_without_html.split())
|
|
89
|
+
sentences = re.split(r"(?<=[.!?])\s+", cleaned_content)
|
|
90
|
+
summary_sentences = [s.strip() for s in sentences if s.strip()][:2]
|
|
91
|
+
exec_summary = " ".join(summary_sentences) or post.subject
|
|
92
|
+
|
|
93
|
+
return ForumSummary(
|
|
94
|
+
forum_id=post.forum_id,
|
|
95
|
+
subject=post.subject,
|
|
96
|
+
author=post.author,
|
|
97
|
+
executive_summary=exec_summary,
|
|
98
|
+
key_dates=list(dict.fromkeys(dates)),
|
|
99
|
+
action_items=action_items[:5],
|
|
100
|
+
urgency=urgency,
|
|
101
|
+
is_ai_generated=False,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
def generate_study_plan(
|
|
105
|
+
self,
|
|
106
|
+
deadlines: List[DeadlineItem],
|
|
107
|
+
horizon_days: int = 7,
|
|
108
|
+
start_date: Optional[datetime.date] = None,
|
|
109
|
+
) -> StudyPlan:
|
|
110
|
+
start = start_date or datetime.date.today()
|
|
111
|
+
sorted_deadlines = sorted(deadlines, key=lambda d: d.due_date)
|
|
112
|
+
|
|
113
|
+
days_list: List[DailyStudyPlan] = []
|
|
114
|
+
for day_offset in range(horizon_days):
|
|
115
|
+
current_day = start + datetime.timedelta(days=day_offset)
|
|
116
|
+
blocks: List[StudyBlock] = []
|
|
117
|
+
|
|
118
|
+
for d in sorted_deadlines:
|
|
119
|
+
due_day = d.due_date.date()
|
|
120
|
+
delta_days = (due_day - current_day).days
|
|
121
|
+
|
|
122
|
+
if delta_days < 0:
|
|
123
|
+
continue # Already passed
|
|
124
|
+
|
|
125
|
+
if delta_days <= 3:
|
|
126
|
+
blocks.append(
|
|
127
|
+
StudyBlock(
|
|
128
|
+
course=d.course,
|
|
129
|
+
task=f"Intensive Sprint: {d.title}",
|
|
130
|
+
priority="high",
|
|
131
|
+
estimated_hours=2.5,
|
|
132
|
+
deadline_countdown_days=delta_days,
|
|
133
|
+
rationale=f"Due in {delta_days} day(s) on {due_day.strftime('%d/%m')}",
|
|
134
|
+
)
|
|
135
|
+
)
|
|
136
|
+
elif delta_days <= 7:
|
|
137
|
+
blocks.append(
|
|
138
|
+
StudyBlock(
|
|
139
|
+
course=d.course,
|
|
140
|
+
task=f"Core Work: {d.title}",
|
|
141
|
+
priority="medium",
|
|
142
|
+
estimated_hours=1.5,
|
|
143
|
+
deadline_countdown_days=delta_days,
|
|
144
|
+
rationale=f"Approaching deadline in {delta_days} days",
|
|
145
|
+
)
|
|
146
|
+
)
|
|
147
|
+
elif delta_days <= 14 and day_offset in (0, 3, 6):
|
|
148
|
+
blocks.append(
|
|
149
|
+
StudyBlock(
|
|
150
|
+
course=d.course,
|
|
151
|
+
task=f"Preparation: {d.title}",
|
|
152
|
+
priority="low",
|
|
153
|
+
estimated_hours=1.0,
|
|
154
|
+
deadline_countdown_days=delta_days,
|
|
155
|
+
rationale="Long-term preparation",
|
|
156
|
+
)
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
total_h = sum(b.estimated_hours for b in blocks)
|
|
160
|
+
days_list.append(DailyStudyPlan(date=current_day, blocks=blocks, total_hours=total_h))
|
|
161
|
+
|
|
162
|
+
return StudyPlan(
|
|
163
|
+
generated_at=datetime.datetime.now(),
|
|
164
|
+
horizon_days=horizon_days,
|
|
165
|
+
days=days_list,
|
|
166
|
+
is_ai_generated=False,
|
|
167
|
+
notes="Algorithmic deadline-driven study plan (deterministic, zero token cost).",
|
|
168
|
+
)
|
prado/ai/external.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""
|
|
2
|
+
External API Provider for OpenAI / DeepSeek / Gemini / Groq Compatible Endpoints.
|
|
3
|
+
|
|
4
|
+
Interacts via standard /v1/chat/completions REST endpoint with Bearer authentication.
|
|
5
|
+
Gracefully degrades to deterministic rule-based intelligence upon missing keys or network errors.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import datetime
|
|
11
|
+
from typing import List, Optional
|
|
12
|
+
|
|
13
|
+
import requests
|
|
14
|
+
|
|
15
|
+
from prado.ai.base import AIProvider, ForumSummary, StudyPlan
|
|
16
|
+
from prado.ai.deterministic import DeterministicFallbackProvider
|
|
17
|
+
from prado.core.downloader import DeadlineItem, ForumPost
|
|
18
|
+
from prado.exceptions import PradoError
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ExternalAIProvider(AIProvider):
|
|
22
|
+
"""External API client for OpenAI, DeepSeek, Gemini, and compatible endpoints."""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
api_key: str,
|
|
27
|
+
base_url: str = "https://api.openai.com/v1",
|
|
28
|
+
model: str = "gpt-4o-mini",
|
|
29
|
+
timeout_seconds: float = 30.0,
|
|
30
|
+
):
|
|
31
|
+
self.api_key = api_key
|
|
32
|
+
self.base_url = base_url.rstrip("/")
|
|
33
|
+
self.model = model
|
|
34
|
+
self.timeout_seconds = timeout_seconds
|
|
35
|
+
self._fallback = DeterministicFallbackProvider()
|
|
36
|
+
|
|
37
|
+
def is_available(self) -> bool:
|
|
38
|
+
return bool(self.api_key and self.api_key.strip())
|
|
39
|
+
|
|
40
|
+
def generate(
|
|
41
|
+
self,
|
|
42
|
+
prompt: str,
|
|
43
|
+
system_prompt: Optional[str] = None,
|
|
44
|
+
max_tokens: int = 1000,
|
|
45
|
+
temperature: float = 0.3,
|
|
46
|
+
) -> str:
|
|
47
|
+
url = f"{self.base_url}/chat/completions"
|
|
48
|
+
headers = {
|
|
49
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
}
|
|
52
|
+
messages = []
|
|
53
|
+
if system_prompt:
|
|
54
|
+
messages.append({"role": "system", "content": system_prompt})
|
|
55
|
+
messages.append({"role": "user", "content": prompt})
|
|
56
|
+
|
|
57
|
+
payload = {
|
|
58
|
+
"model": self.model,
|
|
59
|
+
"messages": messages,
|
|
60
|
+
"max_tokens": max_tokens,
|
|
61
|
+
"temperature": temperature,
|
|
62
|
+
}
|
|
63
|
+
try:
|
|
64
|
+
resp = requests.post(url, headers=headers, json=payload, timeout=self.timeout_seconds)
|
|
65
|
+
resp.raise_for_status()
|
|
66
|
+
data = resp.json()
|
|
67
|
+
return data["choices"][0]["message"]["content"].strip()
|
|
68
|
+
except (requests.RequestException, KeyError, IndexError) as e:
|
|
69
|
+
raise PradoError(f"External AI generation failed: {e}") from e
|
|
70
|
+
|
|
71
|
+
def summarize_forum_post(self, post: ForumPost) -> ForumSummary:
|
|
72
|
+
if not self.is_available():
|
|
73
|
+
return self._fallback.summarize_forum_post(post)
|
|
74
|
+
|
|
75
|
+
sys_prompt = "You are an academic assistant. Summarize this forum notice in 2 concise sentences."
|
|
76
|
+
try:
|
|
77
|
+
summary = self.generate(post.content, system_prompt=sys_prompt, max_tokens=250)
|
|
78
|
+
res = self._fallback.summarize_forum_post(post)
|
|
79
|
+
res.executive_summary = summary
|
|
80
|
+
res.is_ai_generated = True
|
|
81
|
+
return res
|
|
82
|
+
except Exception:
|
|
83
|
+
return self._fallback.summarize_forum_post(post)
|
|
84
|
+
|
|
85
|
+
def generate_study_plan(
|
|
86
|
+
self,
|
|
87
|
+
deadlines: List[DeadlineItem],
|
|
88
|
+
horizon_days: int = 7,
|
|
89
|
+
start_date: Optional[datetime.date] = None,
|
|
90
|
+
) -> StudyPlan:
|
|
91
|
+
plan = self._fallback.generate_study_plan(deadlines, horizon_days, start_date)
|
|
92
|
+
if not self.is_available():
|
|
93
|
+
return plan
|
|
94
|
+
try:
|
|
95
|
+
tip = self.generate(
|
|
96
|
+
f"Provide a 1-sentence productivity tip for {len(deadlines)} academic deadlines.",
|
|
97
|
+
max_tokens=100,
|
|
98
|
+
)
|
|
99
|
+
plan.notes = tip
|
|
100
|
+
plan.is_ai_generated = True
|
|
101
|
+
except Exception:
|
|
102
|
+
pass
|
|
103
|
+
return plan
|
prado/ai/ollama.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Local Ollama Integration for PradoOS AI Layer.
|
|
3
|
+
|
|
4
|
+
Connects to local Ollama daemon (default: http://localhost:11434/api/generate)
|
|
5
|
+
with automatic fallback to deterministic provider when daemon is offline.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import datetime
|
|
11
|
+
from typing import List, Optional
|
|
12
|
+
|
|
13
|
+
import requests
|
|
14
|
+
|
|
15
|
+
from prado.ai.base import AIProvider, ForumSummary, StudyPlan
|
|
16
|
+
from prado.ai.deterministic import DeterministicFallbackProvider
|
|
17
|
+
from prado.core.downloader import DeadlineItem, ForumPost
|
|
18
|
+
from prado.exceptions import PradoError
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class OllamaProvider(AIProvider):
|
|
22
|
+
"""Local Ollama client connecting to /api/generate."""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
base_url: str = "http://localhost:11434",
|
|
27
|
+
model: str = "llama3.2",
|
|
28
|
+
timeout_seconds: float = 30.0,
|
|
29
|
+
):
|
|
30
|
+
self.base_url = base_url.rstrip("/")
|
|
31
|
+
self.model = model
|
|
32
|
+
self.timeout_seconds = timeout_seconds
|
|
33
|
+
self._fallback = DeterministicFallbackProvider()
|
|
34
|
+
|
|
35
|
+
def is_available(self) -> bool:
|
|
36
|
+
try:
|
|
37
|
+
resp = requests.get(f"{self.base_url}/api/tags", timeout=2.0)
|
|
38
|
+
return resp.status_code == 200
|
|
39
|
+
except requests.RequestException:
|
|
40
|
+
return False
|
|
41
|
+
|
|
42
|
+
def generate(
|
|
43
|
+
self,
|
|
44
|
+
prompt: str,
|
|
45
|
+
system_prompt: Optional[str] = None,
|
|
46
|
+
max_tokens: int = 1000,
|
|
47
|
+
temperature: float = 0.3,
|
|
48
|
+
) -> str:
|
|
49
|
+
payload = {
|
|
50
|
+
"model": self.model,
|
|
51
|
+
"prompt": prompt,
|
|
52
|
+
"system": system_prompt or "",
|
|
53
|
+
"stream": False,
|
|
54
|
+
"options": {
|
|
55
|
+
"temperature": temperature,
|
|
56
|
+
"num_predict": max_tokens,
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
try:
|
|
60
|
+
resp = requests.post(
|
|
61
|
+
f"{self.base_url}/api/generate",
|
|
62
|
+
json=payload,
|
|
63
|
+
timeout=self.timeout_seconds,
|
|
64
|
+
)
|
|
65
|
+
resp.raise_for_status()
|
|
66
|
+
data = resp.json()
|
|
67
|
+
return data.get("response", "").strip()
|
|
68
|
+
except requests.RequestException as e:
|
|
69
|
+
raise PradoError(f"Ollama generation failed: {e}") from e
|
|
70
|
+
|
|
71
|
+
def summarize_forum_post(self, post: ForumPost) -> ForumSummary:
|
|
72
|
+
if not self.is_available():
|
|
73
|
+
return self._fallback.summarize_forum_post(post)
|
|
74
|
+
|
|
75
|
+
sys_prompt = (
|
|
76
|
+
"You are an academic assistant. Summarize this Moodle forum post in 2 concise sentences, "
|
|
77
|
+
"extract key dates and action items."
|
|
78
|
+
)
|
|
79
|
+
user_prompt = f"Subject: {post.subject}\nAuthor: {post.author}\nContent: {post.content}"
|
|
80
|
+
try:
|
|
81
|
+
summary_text = self.generate(user_prompt, system_prompt=sys_prompt, max_tokens=300)
|
|
82
|
+
fallback_res = self._fallback.summarize_forum_post(post)
|
|
83
|
+
fallback_res.executive_summary = summary_text
|
|
84
|
+
fallback_res.is_ai_generated = True
|
|
85
|
+
return fallback_res
|
|
86
|
+
except Exception:
|
|
87
|
+
return self._fallback.summarize_forum_post(post)
|
|
88
|
+
|
|
89
|
+
def generate_study_plan(
|
|
90
|
+
self,
|
|
91
|
+
deadlines: List[DeadlineItem],
|
|
92
|
+
horizon_days: int = 7,
|
|
93
|
+
start_date: Optional[datetime.date] = None,
|
|
94
|
+
) -> StudyPlan:
|
|
95
|
+
base_plan = self._fallback.generate_study_plan(deadlines, horizon_days, start_date)
|
|
96
|
+
if not self.is_available():
|
|
97
|
+
return base_plan
|
|
98
|
+
|
|
99
|
+
prompt = (
|
|
100
|
+
f"Given these {len(deadlines)} upcoming academic deadlines: "
|
|
101
|
+
f"{[d.title + ' due ' + d.due_date.isoformat() for d in deadlines]}, "
|
|
102
|
+
f"write a 2-sentence encouraging motivational coaching tip."
|
|
103
|
+
)
|
|
104
|
+
try:
|
|
105
|
+
tip = self.generate(prompt, max_tokens=150)
|
|
106
|
+
base_plan.notes = tip
|
|
107
|
+
base_plan.is_ai_generated = True
|
|
108
|
+
except Exception:
|
|
109
|
+
pass
|
|
110
|
+
return base_plan
|
prado/auth/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PradoOS Authentication and Security Subsystem.
|
|
3
|
+
|
|
4
|
+
Provides cross-platform headless Single Sign-On (SSO) for PRADO UGR SimpleSAMLphp,
|
|
5
|
+
native OS credential management (keyring with encrypted vault fallback),
|
|
6
|
+
3-tier Multi-Factor Authentication (MFA), and secure session cookie persistence.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from prado.auth.credentials import CredentialStore
|
|
10
|
+
from prado.auth.mfa import MfaResolver
|
|
11
|
+
from prado.auth.saml import UgrSamlDriver
|
|
12
|
+
from prado.auth.session import MoodleSessionManager
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"CredentialStore",
|
|
16
|
+
"MfaResolver",
|
|
17
|
+
"MoodleSessionManager",
|
|
18
|
+
"UgrSamlDriver",
|
|
19
|
+
]
|