feat: connect desktop sessions and streaming
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Iterator
|
||||
from dataclasses import dataclass
|
||||
from enum import StrEnum
|
||||
|
||||
from javis.memory.usage_store import ProviderEvent, SQLiteUsageStore, UsageStoreError
|
||||
from javis.providers.base import (
|
||||
@@ -18,7 +19,14 @@ from javis.providers.base import (
|
||||
)
|
||||
from javis.security.privacy import CloudPolicy, PrivacyDecision, PrivacyRouter
|
||||
|
||||
ApprovalCallback = Callable[[PrivacyDecision], bool]
|
||||
|
||||
class ApprovalChoice(StrEnum):
|
||||
ALLOW = "allow"
|
||||
LOCAL = "local"
|
||||
CANCEL = "cancel"
|
||||
|
||||
|
||||
ApprovalCallback = Callable[[PrivacyDecision], ApprovalChoice | bool]
|
||||
NoticeCallback = Callable[[str], None]
|
||||
CloudProviderFactory = Callable[[], LocalModelProvider]
|
||||
|
||||
@@ -89,6 +97,14 @@ class HybridProvider:
|
||||
raise ValueError("Provider-Modus muss auto, local oder gemini sein.")
|
||||
self.mode = mode
|
||||
|
||||
def _approval_choice(self, decision: PrivacyDecision) -> ApprovalChoice:
|
||||
result = self._approval_callback(decision)
|
||||
if isinstance(result, bool):
|
||||
return ApprovalChoice.ALLOW if result else ApprovalChoice.LOCAL
|
||||
if isinstance(result, ApprovalChoice):
|
||||
return result
|
||||
raise ValueError("Ungültiges Ergebnis der Cloudfreigabe.")
|
||||
|
||||
def chat(self, messages: list[ChatMessage]) -> str:
|
||||
current_text = messages[-1].content if messages else ""
|
||||
cloud_requested = self.mode == "gemini"
|
||||
@@ -110,8 +126,11 @@ class HybridProvider:
|
||||
|
||||
approved = decision.policy is CloudPolicy.ALLOWED
|
||||
if decision.policy is CloudPolicy.ASK:
|
||||
approved = self._approval_callback(decision)
|
||||
if not approved:
|
||||
choice = self._approval_choice(decision)
|
||||
if choice is ApprovalChoice.CANCEL:
|
||||
raise ResponseAbortedError("Anfrage vor der Cloudfreigabe abgebrochen.")
|
||||
approved = choice is ApprovalChoice.ALLOW
|
||||
if choice is ApprovalChoice.LOCAL:
|
||||
return self._local(messages, decision, "Cloudfreigabe abgelehnt", fallback=True)
|
||||
|
||||
unavailable_reason = self._cloud_unavailable_reason()
|
||||
@@ -194,8 +213,11 @@ class HybridProvider:
|
||||
|
||||
approved = decision.policy is CloudPolicy.ALLOWED
|
||||
if decision.policy is CloudPolicy.ASK:
|
||||
approved = self._approval_callback(decision)
|
||||
if not approved:
|
||||
choice = self._approval_choice(decision)
|
||||
if choice is ApprovalChoice.CANCEL:
|
||||
raise ResponseAbortedError("Anfrage vor der Cloudfreigabe abgebrochen.")
|
||||
approved = choice is ApprovalChoice.ALLOW
|
||||
if choice is ApprovalChoice.LOCAL:
|
||||
yield from self._stream_local(
|
||||
messages,
|
||||
decision,
|
||||
|
||||
Reference in New Issue
Block a user