Capítulo 1: Versionado de Prompts
Prompts como Código
# prompts/customer_support/v2.1.0.yaml
name: customer_support_agent
version: 2.1.0
description: "Customer support assistant prompt"
author: ml-team@company.com
created: 2024-01-15
system_prompt: |
You are a helpful customer support agent for TechCorp.
Guidelines:
- Be polite and professional
- Only answer questions about our products
- If unsure, escalate to human support
- Never share confidential information
user_template: |
Customer: {customer_name}
Subscription: {subscription_tier}
Query: {query}
Previous context: {context}
parameters:
temperature: 0.7
max_tokens: 500
model: gpt-4
evaluation:
golden_dataset: tests/customer_support_golden.json
metrics:
- helpfulness > 4.0
- accuracy > 0.9
Registro de Prompts
class PromptRegistry:
def __init__(self, storage_path: str):
self.storage_path = storage_path
self.prompts = {}
def register(self, prompt: Prompt) -> str:
"""Register a new prompt version."""
key = f"{prompt.name}/{prompt.version}"
self.prompts[key] = prompt
self._save_to_storage(prompt)
return key
def get(self, name: str, version: str = "latest") -> Prompt:
"""Get a prompt by name and version."""
if version == "latest":
version = self._get_latest_version(name)
return self.prompts.get(f"{name}/{version}")
def get_production(self, name: str) -> Prompt:
"""Get the production version of a prompt."""
metadata = self._get_metadata(name)
return self.get(name, metadata.get("production_version"))
Siguiente: Capítulo 2: Pruebas A/B de Prompts