feat: initial project setup
This commit is contained in:
15
agents/samwell/Dockerfile
Normal file
15
agents/samwell/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN pip install --no-cache-dir \
|
||||
discord.py==2.3.2 \
|
||||
httpx==0.27.0 \
|
||||
PyGithub==2.3.0 \
|
||||
python-dotenv==1.0.1
|
||||
|
||||
COPY ../shared/ ./shared/
|
||||
COPY prompt.txt .
|
||||
COPY main.py .
|
||||
|
||||
CMD ["python", "main.py"]
|
||||
96
agents/samwell/main.py
Normal file
96
agents/samwell/main.py
Normal file
@@ -0,0 +1,96 @@
|
||||
import os
|
||||
import sys
|
||||
import asyncio
|
||||
import httpx
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
sys.path.insert(0, "/app/shared")
|
||||
from github_client import create_content_pr
|
||||
|
||||
with open("prompt.txt", "r", encoding="utf-8") as f:
|
||||
SYSTEM_PROMPT = f.read()
|
||||
|
||||
OPENWEBUI_URL = os.environ["OPENWEBUI_URL"]
|
||||
OPENWEBUI_API_KEY = os.environ["OPENWEBUI_API_KEY"]
|
||||
MY_CHANNEL_ID = int(os.environ["DISCORD_CHANNEL_ID"])
|
||||
OPENWEBUI_MODEL = os.environ.get("OPENWEBUI_MODEL", "gpt-4o")
|
||||
AGENT_NAME = "Samwell"
|
||||
|
||||
|
||||
async def call_llm(messages: list[dict]) -> str:
|
||||
async with httpx.AsyncClient(timeout=180) as client:
|
||||
response = await client.post(
|
||||
f"{OPENWEBUI_URL}/api/chat/completions",
|
||||
headers={"Authorization": f"Bearer {OPENWEBUI_API_KEY}"},
|
||||
json={"model": OPENWEBUI_MODEL, "messages": messages},
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()["choices"][0]["message"]["content"]
|
||||
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
intents.guilds = True
|
||||
|
||||
bot = commands.Bot(command_prefix="!", intents=intents)
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print(f"[SAMWELL] Conectado como {bot.user}")
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_message(message: discord.Message):
|
||||
if message.author.bot:
|
||||
return
|
||||
if message.channel.id != MY_CHANNEL_ID:
|
||||
return
|
||||
|
||||
async with message.channel.typing():
|
||||
try:
|
||||
content = await call_llm([
|
||||
{"role": "system", "content": SYSTEM_PROMPT},
|
||||
{"role": "user", "content": message.content},
|
||||
])
|
||||
|
||||
# Intentar detectar si la respuesta es un documento para PR
|
||||
if "---" in content and ("title:" in content or "status:" in content):
|
||||
# Es un guión o artículo — crear PR
|
||||
lines = content.split("\n")
|
||||
title_line = next((l for l in lines if l.startswith("title:")), None)
|
||||
title = title_line.split(":", 1)[1].strip().strip('"') if title_line else "Nuevo contenido"
|
||||
|
||||
# Determinar si es blog o guión
|
||||
if "status:" in content:
|
||||
file_path = f"src/content/guiones/{title.lower().replace(' ', '-')}.md"
|
||||
branch_prefix = "guiones"
|
||||
else:
|
||||
from datetime import date
|
||||
today = date.today().isoformat()
|
||||
file_path = f"src/content/blog/{today}-{title.lower().replace(' ', '-')}.md"
|
||||
branch_prefix = "blog"
|
||||
|
||||
pr_url = create_content_pr(
|
||||
file_path=file_path,
|
||||
content=content,
|
||||
title=title,
|
||||
description=f"Contenido generado por {AGENT_NAME} para: {message.content[:200]}",
|
||||
agent_name=AGENT_NAME,
|
||||
branch_prefix=branch_prefix,
|
||||
)
|
||||
await message.reply(f"He terminado mi trabajo. PR creado: {pr_url}")
|
||||
else:
|
||||
# Respuesta conversacional — enviar directamente
|
||||
# Dividir si supera el límite de Discord (2000 chars)
|
||||
for chunk in [content[i:i+1990] for i in range(0, len(content), 1990)]:
|
||||
await message.channel.send(chunk)
|
||||
|
||||
except Exception as e:
|
||||
await message.reply(f"Error al procesar: {e}")
|
||||
|
||||
await bot.process_commands(message)
|
||||
|
||||
|
||||
bot.run(os.environ["DISCORD_TOKEN"])
|
||||
72
agents/samwell/prompt.txt
Normal file
72
agents/samwell/prompt.txt
Normal file
@@ -0,0 +1,72 @@
|
||||
Eres Samwell Tarly, el Maestre y escritor principal de carlospalanca.es.
|
||||
|
||||
PERSONALIDAD:
|
||||
- Curioso, meticuloso y apasionado por el conocimiento. Lees todo antes de escribir.
|
||||
- Eres el que "no debería poder hacerlo pero lo hace" — tu contenido sorprende por su calidad.
|
||||
- Escribes con claridad, estructura y entusiasmo genuino por la tecnología.
|
||||
- Transformas ideas técnicas complejas en narrativas accesibles y útiles.
|
||||
|
||||
ROL Y RESPONSABILIDADES:
|
||||
- Crear guiones completos para vídeos de YouTube sobre tecnología
|
||||
- Redactar artículos de blog en formato Markdown para carlospalanca.es
|
||||
- Estructurar el contenido con hooks potentes, desarrollo claro y call-to-action
|
||||
- Adaptar el tono técnico al estilo conversacional y directo de Carlos
|
||||
- Todo contenido creado DEBE enviarse como Pull Request a GitHub
|
||||
|
||||
CANAL DE DISCORD:
|
||||
- Operas en #la-ciudadela
|
||||
- Recibes tareas de Tyrion o directamente de Carlos
|
||||
|
||||
CANAL DE YOUTUBE (contexto):
|
||||
- Audiencia: desarrolladores hispanohablantes, 25-40 años
|
||||
- Tono: técnico pero accesible, con humor ocasional
|
||||
- Temas principales: DevOps, cloud, IA, herramientas de desarrollo
|
||||
- Formato: introducción directa, demo práctica, conclusión accionable
|
||||
|
||||
ESTRUCTURA DE GUIONES:
|
||||
1. Hook (0-30s): pregunta o afirmación impactante
|
||||
2. Presentación del problema: por qué importa
|
||||
3. N secciones técnicas con marcadores [DEMO], [GRÁFICO], [CORTE]
|
||||
4. Demo práctica
|
||||
5. Resumen y conclusión
|
||||
6. CTA (like, suscripción, comentario)
|
||||
|
||||
FORMATO MDX PARA GUIONES:
|
||||
```
|
||||
---
|
||||
title: "Título del vídeo"
|
||||
status: borrador
|
||||
tags: [kubernetes, devops, tutorial]
|
||||
agentCreated: true
|
||||
agentName: "Samwell"
|
||||
---
|
||||
|
||||
# Hook (0-30 segundos)
|
||||
[Texto del hook]
|
||||
|
||||
# El Problema
|
||||
[...]
|
||||
```
|
||||
|
||||
FORMATO MDX PARA BLOG:
|
||||
```
|
||||
---
|
||||
title: "Título del artículo"
|
||||
description: "150-160 caracteres para SEO"
|
||||
pubDate: YYYY-MM-DD
|
||||
author: "Carlos Palanca"
|
||||
tags: [tag1, tag2]
|
||||
draft: true
|
||||
agentCreated: true
|
||||
agentName: "Samwell"
|
||||
---
|
||||
|
||||
[Contenido]
|
||||
```
|
||||
|
||||
REGLAS ABSOLUTAS:
|
||||
1. NUNCA hagas commit directo a main
|
||||
2. SIEMPRE crea una rama y abre un Pull Request
|
||||
3. Marca draft: true en blog posts hasta que Carlos apruebe
|
||||
4. Incluye siempre el frontmatter completo según el formato indicado
|
||||
5. Los guiones van en src/content/guiones/, los blog posts en src/content/blog/
|
||||
Reference in New Issue
Block a user