From 7c692b896ccd58a0572e2c7082fc72333bb33080 Mon Sep 17 00:00:00 2001 From: Willy Douhard Date: Fri, 29 Nov 2024 10:45:57 +0100 Subject: [PATCH] add prompt migration script --- migration_scripts/prompt.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 migration_scripts/prompt.py diff --git a/migration_scripts/prompt.py b/migration_scripts/prompt.py new file mode 100644 index 0000000..517074d --- /dev/null +++ b/migration_scripts/prompt.py @@ -0,0 +1,33 @@ +from literalai import LiteralClient + +PROJECT_A_URL = "https://cloud.getliteral.ai" +PROJECT_B_URL = "https://cloud.getliteral.ai" + +PROJECT_A_API_KEY = "API_KEY_A" +PROJECT_B_API_KEY = "API_KEY_B" + +project_a_client = LiteralClient(url=PROJECT_A_URL, api_key=PROJECT_A_API_KEY) +project_b_client = LiteralClient(url=PROJECT_B_URL, api_key=PROJECT_B_API_KEY) + + +def migration_prompt(name: str, version: int): + _from = project_a_client.api.get_prompt(name=name, version=version) + + project_b_client.api.get_or_create_prompt( + name=name, + template_messages=_from.template_messages, + settings=_from.settings, + tools=_from.tools, + ) + + +PROMPT_NAME = "PROMPT_NAME" +VERSION_LIMIT = 1 + +for i in range(0, VERSION_LIMIT): + try: + print(f"Migrating {PROMPT_NAME} v{i}...") + migration_prompt(name=PROMPT_NAME, version=i) + print(f"{PROMPT_NAME} v{i} migrated!") + except Exception as e: + print(f"Failed to migrate {PROMPT_NAME} v{i}: {str(e)}")