feat: Implement main application shell with navigation and color scheme toggle

- Added Appshell component with responsive navbar and main content area
- Integrated ColorSchemeToggle for light/dark mode switching
- Created Welcome component with styled title and introductory text
- Developed ChatPage for LLM interaction with WebSocket support
- Implemented Biblioteca for managing notes with rich text editor
- Added LoginPage for user authentication with error handling
- Introduced MessageList and MessageBubble components for chat messages
- Styled components with CSS modules for consistent design
This commit is contained in:
2025-06-21 02:01:21 +02:00
parent 3d5deef0fb
commit aef8791151
101 changed files with 169 additions and 166 deletions
+62
View File
@@ -0,0 +1,62 @@
import requests
from domains.Credenciales.ollama_credencial import OllamaCredencial
class OllamaCliente:
def __init__(self, credencial: OllamaCredencial):
"""
Inicializa el cliente de Ollama con una instancia de OllamaCredencial.
"""
self.credencial = credencial
self.base_url = self.credencial.base_url
# --- Chat Completions ---
def chat_completion(self, model: str, messages: list, stream: bool = False, **kwargs):
url = f"{self.base_url}/api/chat"
payload = {
"model": model,
"messages": messages,
"stream": stream,
**kwargs
}
response = requests.post(url, json=payload, stream=stream)
response.raise_for_status()
return self._handle_stream(response) if stream else response.json()
def _handle_stream(self, response):
for line in response.iter_lines():
if line:
try:
parsed = line.decode("utf-8")
# Extraer contenido si está en JSON como {"message":{"content":"..."},...}
if parsed.startswith("{"):
import json
data = json.loads(parsed)
if "message" in data and "content" in data["message"]:
yield data["message"]["content"]
except Exception:
continue
# --- Text Completion (legacy) ---
def completion(self, model: str, prompt: str, **kwargs):
url = f"{self.base_url}/api/generate"
payload = {
"model": model,
"prompt": prompt,
**kwargs
}
response = requests.post(url, json=payload)
response.raise_for_status()
return response.json()
# --- Embeddings ---
def embedding(self, model: str, input: str | list[str], **kwargs):
url = f"{self.base_url}/api/embeddings"
payload = {
"model": model,
"prompt": input,
**kwargs
}
response = requests.post(url, json=payload)
response.raise_for_status()
return response.json()
+70
View File
@@ -0,0 +1,70 @@
from openai import OpenAI
from domains.ApiKeys.openai_apikey import OpenAICredencial
class OpenAICliente:
def __init__(self, credencial: OpenAICredencial):
"""
Inicializa el cliente de OpenAI con una instancia de OpenAICredencial.
"""
self.credencial = credencial
self.client = OpenAI(api_key=self.credencial.api_key)
if self.credencial.organizacion:
self.client.organization = self.credencial.organizacion
# --- Chat Completions ---
def chat_completion(self, model: str, messages: list, stream: bool = False, **kwargs):
response = self.client.chat.completions.create(
model=model,
messages=messages,
stream=stream, # Parámetro explícito
**kwargs
)
return self._handle_stream(response, stream) if stream else response
def _handle_stream(self, stream, _):
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
yield chunk.choices[0].delta.content
# --- Text Completions (legacy) ---
def completion(self, model: str, prompt: str, **kwargs):
return self.client.completions.create(model=model, prompt=prompt, **kwargs)
# --- Text Edits ---
def edit(self, model: str, input: str, instruction: str, **kwargs):
return self.client.edits.create(model=model, input=input, instruction=instruction, **kwargs)
# --- Embeddings ---
def embedding(self, model: str, input: str | list[str], **kwargs):
return self.client.embeddings.create(model=model, input=input, **kwargs)
# --- Moderation ---
def moderation(self, input: str | list[str], model="text-moderation-latest", **kwargs):
return self.client.moderations.create(input=input, model=model, **kwargs)
# --- Image Generation ---
def image_generate(self, prompt: str, **kwargs):
return self.client.images.generate(prompt=prompt, **kwargs)
# --- Audio Transcription ---
def audio_transcribe(self, model: str, file_path: str, **kwargs):
with open(file_path, "rb") as f:
return self.client.audio.transcriptions.create(model=model, file=f, **kwargs)
# --- Audio Translation ---
def audio_translate(self, model: str, file_path: str, **kwargs):
with open(file_path, "rb") as f:
return self.client.audio.translations.create(model=model, file=f, **kwargs)
# --- File Upload ---
def file_upload(self, file_path: str, purpose="fine-tune", **kwargs):
with open(file_path, "rb") as f:
return self.client.files.create(file=f, purpose=purpose, **kwargs)
# --- File List ---
def file_list(self, **kwargs):
return self.client.files.list(**kwargs)
# --- File Delete ---
def file_delete(self, file_id: str, **kwargs):
return self.client.files.delete(file_id=file_id, **kwargs)
View File