mirror of
https://github.com/hoshikawa2/compass_backoffice.git
synced 2026-07-09 13:54:20 +00:00
first commit
This commit is contained in:
1
scripts_original_develop/.gitkeep
Normal file
1
scripts_original_develop/.gitkeep
Normal file
@@ -0,0 +1 @@
|
||||
# Utility scripts will be added here
|
||||
72
scripts_original_develop/get_prompt_from_langfuse.py
Normal file
72
scripts_original_develop/get_prompt_from_langfuse.py
Normal file
@@ -0,0 +1,72 @@
|
||||
"""
|
||||
Simple script to test Langfuse connection and retrieve a prompt.
|
||||
|
||||
Usage:
|
||||
uv run python scripts/get_prompt_from_langfuse.py
|
||||
"""
|
||||
|
||||
# Import settings and setup Langfuse environment variables
|
||||
from src.core.config import settings
|
||||
settings.setup_langfuse()
|
||||
|
||||
from langfuse import Langfuse
|
||||
from src.core.logging import setup_logging
|
||||
|
||||
# Setup logging to see what's happening
|
||||
logger = setup_logging(log_level=settings.LOG_LEVEL, log_format=settings.LOG_FORMAT)
|
||||
|
||||
def main():
|
||||
try:
|
||||
logger.info(f"Connecting to Langfuse at: {settings.LANGFUSE_BASE_URL}")
|
||||
|
||||
# Initialize Langfuse client
|
||||
# The client will use the environment variables exported by settings.setup_langfuse()
|
||||
# or we can pass them explicitly as in the upload script.
|
||||
client = Langfuse(
|
||||
public_key=settings.LANGFUSE_PUBLIC_KEY,
|
||||
secret_key=settings.LANGFUSE_SECRET_KEY,
|
||||
host=settings.LANGFUSE_BASE_URL,
|
||||
)
|
||||
|
||||
# List of prompts we know should exist (from upload_prompts_to_langfuse.py)
|
||||
prompt_name = "ticket_reclassification_pt"
|
||||
|
||||
logger.info(f"Attempting to retrieve prompt: '{prompt_name}'")
|
||||
|
||||
|
||||
prompt = client.get_prompt(prompt_name, max_retries=2)
|
||||
|
||||
logger.info(
|
||||
"Prompt retrieved successfully",
|
||||
extra={
|
||||
"prompt_name": prompt_name,
|
||||
"version": prompt.version,
|
||||
"labels": getattr(prompt, "labels", None),
|
||||
},
|
||||
)
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print(f"PROMPT: {prompt_name} | version={prompt.version} | labels={getattr(prompt, 'labels', 'N/A')}")
|
||||
print("=" * 50)
|
||||
print(prompt.prompt)
|
||||
print("=" * 50 + "\n")
|
||||
|
||||
except Exception as error:
|
||||
error_type = type(error).__name__
|
||||
error_detail = str(error) if str(error) else "(no message)"
|
||||
|
||||
logger.error(
|
||||
"Failed to retrieve prompt",
|
||||
extra={
|
||||
"prompt_name": prompt_name,
|
||||
"error_type": error_type,
|
||||
"error_detail": error_detail,
|
||||
},
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
finally:
|
||||
client.flush()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
85
scripts_original_develop/upload_prompts_to_langfuse.py
Normal file
85
scripts_original_develop/upload_prompts_to_langfuse.py
Normal file
@@ -0,0 +1,85 @@
|
||||
"""
|
||||
Script to upload local prompts to Langfuse.
|
||||
|
||||
Uploads the project prompts with the agreed names so that
|
||||
prompt_manager can retrieve them via get_prompt_from_langfuse().
|
||||
|
||||
Usage:
|
||||
uv run python scripts/upload_prompts_to_langfuse.py
|
||||
"""
|
||||
|
||||
# Import settings BEFORE the Langfuse SDK to ensure env vars are set
|
||||
from src.core.config import settings
|
||||
settings.setup_langfuse()
|
||||
|
||||
from langfuse import Langfuse
|
||||
from src.core.logging import setup_logging
|
||||
|
||||
logger = setup_logging(log_level=settings.LOG_LEVEL, log_format=settings.LOG_FORMAT)
|
||||
|
||||
# Mapping: Langfuse prompt name → local prompt variable
|
||||
from src.agent.local_prompts.canceling_analysis import canceling_analysis_pt
|
||||
from src.agent.local_prompts.ticket_reclassification import ticket_reclassification_pt
|
||||
from src.agent.local_prompts.tim_complaint_analysis import tim_complaint_analysis_pt
|
||||
from src.agent.local_prompts.emulator.response_emulator_generation import response_emulator_generation_pt
|
||||
|
||||
PROMPTS_TO_UPLOAD = [
|
||||
{
|
||||
"name": "ticket_reclassification_pt",
|
||||
"prompt": ticket_reclassification_pt,
|
||||
"description": "Unified reclassification prompt that recieves motives AND decides between (tratamento / reclassificar).",
|
||||
},
|
||||
{
|
||||
"name": "ticket_canceling_analysis_pt",
|
||||
"prompt": canceling_analysis_pt,
|
||||
"description": "Policy violation cancellation check prompt (alternative flow).",
|
||||
},
|
||||
{
|
||||
"name": "tim_complaint_analysis_pt",
|
||||
"prompt": tim_complaint_analysis_pt,
|
||||
"description": "TIM-specific complaint analysis prompt to determine if the complaint is about TIM, a different operator, or is undefined.",
|
||||
},
|
||||
{
|
||||
"name": "response_emulator_generation_pt",
|
||||
"prompt": response_emulator_generation_pt,
|
||||
"description": "Anatel response generation prompt for the emulator (opening/body/ombudsman structure).",
|
||||
# Tunable history window read by generate_response_node via config.
|
||||
"config": {"max_regeneration_history": 4},
|
||||
},
|
||||
]
|
||||
|
||||
# Upload
|
||||
def main():
|
||||
logger.info(f"Connecting to Langfuse at: {settings.LANGFUSE_BASE_URL}")
|
||||
client = Langfuse(
|
||||
public_key=settings.LANGFUSE_PUBLIC_KEY,
|
||||
secret_key=settings.LANGFUSE_SECRET_KEY,
|
||||
host=settings.LANGFUSE_BASE_URL,
|
||||
)
|
||||
|
||||
for item in PROMPTS_TO_UPLOAD:
|
||||
name = item["name"]
|
||||
prompt_text = item["prompt"].strip()
|
||||
description = item["description"]
|
||||
config = {"description": description, **item.get("config", {})}
|
||||
|
||||
logger.info(f"Uploading prompt '{name}'...")
|
||||
try:
|
||||
result = client.create_prompt(
|
||||
name=name,
|
||||
prompt=prompt_text,
|
||||
labels=["production"],
|
||||
config=config,
|
||||
type="text",
|
||||
)
|
||||
logger.info(f"Prompt '{name}' created/updated (version={result.version})")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to upload prompt '{name}': {e}")
|
||||
|
||||
logger.info("Upload complete. Check the Langfuse dashboard to verify the prompts.")
|
||||
client.flush()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user