From 585e0aa5322ec962a64d80a2bb0ccdc2fdc565e2 Mon Sep 17 00:00:00 2001 From: Mahmoud Mabrouk Date: Wed, 23 Oct 2024 14:32:48 +0200 Subject: [PATCH 01/16] docs(app): AGE-1151 restructuring tutorials --- .../a-more-complicated-tutorial-draft.mdx | 0 .../build-rag-application.mdx | 0 .../custom-workflows}/deploy-mistral-model.mdx | 0 .../extract_job_information.mdx | 0 .../first-app-with-langchain.mdx | 0 .../custom-workflows}/list_templates.mdx | 0 .../sdk/evaluate-with-SDK.mdx} | 2 +- docs/sidebars.ts | 18 +++++++++++------- 8 files changed, 12 insertions(+), 8 deletions(-) rename docs/docs/{guides/tutorials => tutorials/custom-workflows}/a-more-complicated-tutorial-draft.mdx (100%) rename docs/docs/{guides/tutorials => tutorials/custom-workflows}/build-rag-application.mdx (100%) rename docs/docs/{guides/tutorials => tutorials/custom-workflows}/deploy-mistral-model.mdx (100%) rename docs/docs/{guides/tutorials => tutorials/custom-workflows}/extract_job_information.mdx (100%) rename docs/docs/{guides/tutorials => tutorials/custom-workflows}/first-app-with-langchain.mdx (100%) rename docs/docs/{guides/tutorials => tutorials/custom-workflows}/list_templates.mdx (100%) rename docs/docs/{guides/cookbooks/evaluations_with_sdk.mdx => tutorials/sdk/evaluate-with-SDK.mdx} (99%) diff --git a/docs/docs/guides/tutorials/a-more-complicated-tutorial-draft.mdx b/docs/docs/tutorials/custom-workflows/a-more-complicated-tutorial-draft.mdx similarity index 100% rename from docs/docs/guides/tutorials/a-more-complicated-tutorial-draft.mdx rename to docs/docs/tutorials/custom-workflows/a-more-complicated-tutorial-draft.mdx diff --git a/docs/docs/guides/tutorials/build-rag-application.mdx b/docs/docs/tutorials/custom-workflows/build-rag-application.mdx similarity index 100% rename from docs/docs/guides/tutorials/build-rag-application.mdx rename to docs/docs/tutorials/custom-workflows/build-rag-application.mdx diff --git a/docs/docs/guides/tutorials/deploy-mistral-model.mdx b/docs/docs/tutorials/custom-workflows/deploy-mistral-model.mdx similarity index 100% rename from docs/docs/guides/tutorials/deploy-mistral-model.mdx rename to docs/docs/tutorials/custom-workflows/deploy-mistral-model.mdx diff --git a/docs/docs/guides/tutorials/extract_job_information.mdx b/docs/docs/tutorials/custom-workflows/extract_job_information.mdx similarity index 100% rename from docs/docs/guides/tutorials/extract_job_information.mdx rename to docs/docs/tutorials/custom-workflows/extract_job_information.mdx diff --git a/docs/docs/guides/tutorials/first-app-with-langchain.mdx b/docs/docs/tutorials/custom-workflows/first-app-with-langchain.mdx similarity index 100% rename from docs/docs/guides/tutorials/first-app-with-langchain.mdx rename to docs/docs/tutorials/custom-workflows/first-app-with-langchain.mdx diff --git a/docs/docs/guides/tutorials/list_templates.mdx b/docs/docs/tutorials/custom-workflows/list_templates.mdx similarity index 100% rename from docs/docs/guides/tutorials/list_templates.mdx rename to docs/docs/tutorials/custom-workflows/list_templates.mdx diff --git a/docs/docs/guides/cookbooks/evaluations_with_sdk.mdx b/docs/docs/tutorials/sdk/evaluate-with-SDK.mdx similarity index 99% rename from docs/docs/guides/cookbooks/evaluations_with_sdk.mdx rename to docs/docs/tutorials/sdk/evaluate-with-SDK.mdx index 1b3a739a67..a5827f3773 100644 --- a/docs/docs/guides/cookbooks/evaluations_with_sdk.mdx +++ b/docs/docs/tutorials/sdk/evaluate-with-SDK.mdx @@ -1,5 +1,5 @@ --- -title: "Evaluations with SDK" +title: "Evaluate with SDK" --- :::note diff --git a/docs/sidebars.ts b/docs/sidebars.ts index 57732e24f1..3abdeaf308 100644 --- a/docs/sidebars.ts +++ b/docs/sidebars.ts @@ -18,8 +18,12 @@ const sidebars: SidebarsConfig = { { label: "Prompt Management", ...CATEGORY_UTILITIES, - items: [{ type: "autogenerated", dirName: "prompt-management" } - ], + items: [{ type: "autogenerated", dirName: "prompt-management" }, + {type: "category", + collapsed: true, + collapsible: true, + label: "Tutorials", + items: [ "tutorials/sdk/manage-prompts-with-SDK"]}], }, { label: "Evaluation", @@ -29,7 +33,7 @@ const sidebars: SidebarsConfig = { collapsed: true, collapsible: true, label: "Tutorials", - items: [ "guides/cookbooks/evaluations_with_sdk"]}], + items: [ "tutorials/sdk/evaluate-with-SDK"]}], }, { label: "Observability", @@ -55,14 +59,14 @@ const sidebars: SidebarsConfig = { ], guidesSidebar: [ { - label: "Tutorials", + label: "Custom Workflows", ...CATEGORY_UTILITIES, - items: [{ type: "autogenerated", dirName: "guides/tutorials" }], + items: [{ type: "autogenerated", dirName: "tutorials/custom-workflows" }], }, { - label: "Cookbooks", + label: "SDK", ...CATEGORY_UTILITIES, - items: [{ type: "autogenerated", dirName: "guides/cookbooks" }], + items: [{ type: "autogenerated", dirName: "tutorials/sdk" }], }, ], refrenceSidebar: [ From c18402da03abc413b7a5e39660c4638507f3fd18 Mon Sep 17 00:00:00 2001 From: Mahmoud Mabrouk Date: Wed, 23 Oct 2024 14:34:44 +0200 Subject: [PATCH 02/16] docs(app): AGE-1151 updated quick start with new SDK --- .../docs/prompt-management/02-quick-start.mdx | 142 +++++++++++++----- 1 file changed, 105 insertions(+), 37 deletions(-) diff --git a/docs/docs/prompt-management/02-quick-start.mdx b/docs/docs/prompt-management/02-quick-start.mdx index f511100a27..bda5a2c186 100644 --- a/docs/docs/prompt-management/02-quick-start.mdx +++ b/docs/docs/prompt-management/02-quick-start.mdx @@ -6,18 +6,18 @@ import Image from "@theme/IdealImage"; ## Introduction -In this tutorial, we will **create a prompt** in the web UI, **publish** it to a deployment, **integrate** it with our code base. +In this tutorial, we will **create a prompt** in the web UI, **publish** it to a deployment, and **integrate** it with our codebase using the Agenta SDK. :::note -If you want to do this whole process programatically, jump to [this guide](/prompt-management/integration/how-to-integrate-with-agenta) +If you want to do this whole process programmatically, jump to [this guide](/prompt-management/integration/how-to-integrate-with-agenta). ::: -## 1. Create a prompt +## 1. Create a Prompt -We will create a prompt from the web UI. This can be done simply by going to the app overview, clicking on create a prompt. You have here the choice between using a chat prompt or a text prompt: +We will create a prompt from the web UI. This can be done by going to the app overview and clicking on **Create a Prompt**. You have the choice between using a chat prompt or a text prompt: -- A text prompt is useful for single turn LLM applications such as question answering, text generation, entity extraction, and classification, etc. -- A chat application is designed for multi-turn applications like chatbots. +- **Text Prompt**: Useful for single-turn LLM applications such as question answering, text generation, entity extraction, classification, etc. +- **Chat Application**: Designed for multi-turn applications like chatbots.
-## 2. Publish a variant +## 2. Publish a Variant -You can create in each LLM application multiple variants. You can think of variants as git branches. Each variant is versioned with each variant version having it's own commit number and being immutable. +Within each LLM application, you can create multiple variants. Variants are like Git branches, allowing you to experiment with different configurations. Each variant is versioned, and each version has its own commit number and is immutable. -When you are satified with a commit (after evaluating it for instance) you can publish it to a deployment. The deployment is tagged with an environment (`production`, `development` or `staging`) and provides you access to endpoint for both the published configuration and to a proxy for the calls. +When you are satisfied with a variant's version (after evaluating it, for instance), you can publish it to a deployment. A deployment is tagged with an environment (`production`, `development`, or `staging`) and provides you with access to endpoints for both the published configuration and proxying the calls. -To publish a variant, go to overview, click on the three dots on the **variant** that you want to publish and select Deploy (see screenshto) +To publish a variant, go to the overview, click on the three dots on the **variant** that you want to publish, and select **Deploy** (see screenshot):
-You can select now which deployments you want to publish the variant to + +You can now select which environments you want to publish the variant to: -
+ :::caution -New change -to the **variant** will not be automaticly published to the **deployment** unless -we explicitly **publish it**. +New changes to the **variant** will not be automatically published to the **deployment** unless you explicitly **publish it** again. -The reason is that we have published the last **version**/**commit** of the **variant** to -that deployment and not the **variant** itself! +The reason is that we have published a specific **version**/**commit** of the **variant** to that deployment, not the **variant** itself! ::: -## 3. Integrate with your code +## 3. Integrate with Your Code + +To use the prompt in your code, you can utilize the Agenta SDK to fetch the configuration. Here's how you can do it in Python: + +### a. Initialize the SDK + +First, import the `agenta` module and initialize the SDK using `ag.init()`. Make sure you have your API key set in your environment variables or configuration file. + +```python +import agenta as ag + +# Initialize the SDK (API key can be set in environment variables or passed directly) +ag.init(api_key="your_api_key") # Replace with your actual API key or omit if set elsewhere +``` + +### b. Fetch the Configuration -To see the code snippet needed to use the prompt, click on the name of the deployment and you will see a drawer with the integration code. For example for python +To fetch the configuration from the production environment, use the `ConfigManager.get_from_registry` method: ```python -from agenta import Agenta -agenta = Agenta() -config = agenta.get_config(base_id="xxxxx", environment="production", cache_timeout=200) # Fetches the configuration with caching +# Fetch configuration from the production environment +config = ag.ConfigManager.get_from_registry( + app_slug="your-app-slug" +) ``` -The prompt object will be like this: +- **Note**: If you do not provide a `variant_ref` or `environment_ref`, the SDK defaults to fetching the latest configuration deployed to the `production` environment. + +### c. Use the Configuration + +The `config` object will be a dictionary containing your prompt configuration. You can use it directly in your application: ```python -{'temperature': 1.0, -'model': 'gpt-3.5-turbo', -'max_tokens': -1, -'prompt_system': 'You are an expert in geography.', -'prompt_user': 'What is the capital of {country}?', -'top_p': 1.0, -'frequence_penalty': 0.0, -'presence_penalty': 0.0, -'force_json': 0} +# Use the configuration +print(config) +``` +**Example Output:** + +```python +{ + 'temperature': 1.0, + 'model': 'gpt-3.5-turbo', + 'max_tokens': -1, + 'prompt_system': 'You are an expert in geography.', + 'prompt_user': 'What is the capital of {country}?', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0, + 'force_json': 0 +} +``` + +### d. (Optional) Schema Validation with Pydantic + +If you have a predefined schema for your configuration, you can use Pydantic to validate it: + +```python +from pydantic import BaseModel + +# Define your configuration schema +class ConfigSchema(BaseModel): + temperature: float + model: str + max_tokens: int + prompt_system: str + prompt_user: str + top_p: float + frequency_penalty: float + presence_penalty: float + force_json: int + +# Fetch configuration with schema validation +config = ag.ConfigManager.get_from_registry( + app_slug="your-app-slug", + schema=ConfigSchema +) + +# Use the configuration +print(config) +``` + +- The `config` object will now be an instance of `ConfigSchema`, allowing you to access its fields directly with type checking. + +### e. Asynchronous Fetching (Optional) + +If your application is asynchronous, you can use the async version of the method: + +```python +# Asynchronous fetching of configuration +config = await ag.ConfigManager.async_get_from_registry( + app_slug="your-app-slug" +) ``` -## 4. Revert to previous deployment (optional) +## 4. Revert to Previous Deployment (Optional) :::note -This feature is only available in cloud and enterprise version +This feature is only available in the cloud and enterprise versions. ::: -Optionally you would like to revert to a previously published commit. For this click on the deployment in the overview view, then click on **history**, you will see all the previous published version. You can revert to a previous version by clicking on revert. +If you need to revert to a previously published commit, click on the deployment in the overview view, then click on **History**. You will see all the previously published versions. You can revert to a previous version by clicking on **Revert**. -## Next steps +## Next Steps -Now that you've created and published your first prompt, you can learn how to do [prompt engineering in the playground](/prompt-management/using-the-playground) or dive deeper into [the capabilities of the prompt management SDK](/prompt-management/creating-a-custom-template) +Now that you've created and published your first prompt, you can learn how to do [prompt engineering in the playground](/prompt-management/using-the-playground) or dive deeper into [the capabilities of the prompt management SDK](/prompt-management/creating-a-custom-template). From c873887d450858c42a37baafb3b0bc57eb7525b9 Mon Sep 17 00:00:00 2001 From: Mahmoud Mabrouk Date: Wed, 23 Oct 2024 14:35:04 +0200 Subject: [PATCH 03/16] docs(app): AGE-1151 prompt management tutorial --- .../tutorials/sdk/manage-prompts-with-SDK.mdx | 240 ++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx diff --git a/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx b/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx new file mode 100644 index 0000000000..49069e65d3 --- /dev/null +++ b/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx @@ -0,0 +1,240 @@ +--- +title: "Manage Prompts with SDK" +--- + +import Image from "@theme/IdealImage"; + +In Agenta, the whole prompt management workflows happens seamlessly in the web UI. However sometimes, you would like to do things programatically without having to go throught the UI. + +In this tutorial we will use the Agenta SDK to create a new prompt, commit changes, deploy them to production then fetch their configuration and use it to call the LLM. + +## Agenda + +Before starting, let's quickly review how Agenta version prompts: + +Agenta follows a structure similar to git for prompt versioning. Instead of having one commit history where you commit changes. It follows a multiple branches (called variants) where changes can be committed, and environement where these changes can be deployed (and used in your application) ([todo: add as pop over] you can see why we chose this here). + +You can find more about how prompt versioning works in the [concepts page](/concepts/concepts). + +The workflow of deploying a change to production we will follow in this tutorial is the following: + +1. Create a new variant (branch) +2. Commit a change to that variant +3. Deploy that commit (variant/version) to the production environment +4. Commit a new change to that variant +5. Fetch the config from that environment + +## Setup + +Before using the SDK, we need to initialize it using the `ag.init()` method which takes the host (default cloud.agenta.ai) and the api key (not required for community editions) + +```python +import agenta as ag + +# Initialize the SDK with your API key +os.environment["AGENTA_API_KEY"] = "xxx" # Only needs setting in oss +os.environment["AGENTA_HOST"] = "https://cloud.agenta.ai" # default value no need setting explicitly +ag.init() +``` + +## Creating a new prompt + +Each prompt in agenta is a unique application. Currently creating a prompt is only available in the web UI. To create a new prompt, just click on create a new prompt and select whether it's a chat or completion propmt in the web UI. The name of the prompt is the slug that we will use for all the operations below. + +Here we are going to create a new completion prompt we will call `topic-explainer`. Here is how our structure would look like after. + +[Todo: Image] + +## Creating a New Variant + +[Todo: Image showing before and after. The new elements are added in a different colors] +Variants are similar to branches in git. Any change to the prompt has to be first committed into a variant. Here we are going to create a new variant and make our first commit to it. For this we use the `VariantManager.create_variant` method: + +```python + +from agenta import Prompt + +# Prompt is a pydantic BaseModel, for additional validation +my_prompt = Prompt(temperature=0.6, + model="gpt-3.5-turbo", + max_tokens=150, + prompt=[{"role": "system", "content": "You are an assistant that provides concise answers"}, + {"role": "user", "content": "Explain {topic} in simple terms"}], + top_p=1.0, + frequency_penalty=0.0, + presence_penalty=0.0 ) + +# Create a new variant +variant = ag.VariantManager.create_variant( + app_slug="topic-explainer", + variant_slug="new-variant", + config_parameters=my_prompt.dict() +) + +print("Created variant:") +print(variant) +``` + +This command will create a new variant and initialize it with the first commit containing the parameters provided + +- **Parameters:** + - `app_slug`: The unique slug of your application. + - `variant_slug`: The unique slug of the new variant . + - `config_parameters`: A dictionary containing the initial configuration parameters. + +**Sample Output:** + +```python +Created variant: +{ + 'app_slug': 'topic-explainer', + 'variant_slug': 'new-variant', + 'variant_version': 1, + 'config': { + 'parameters': { + 'temperature': 0.7, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'metadata': { + 'created_at': '2023-10-01T12:00:00Z', + 'created_by': 'user@example.com' + } + } +} +``` + +## 5. Deploying out changes to the production environment + +[Todo: Image showing before and after. The new elements are added in a different colors] + +To deploy our commit to an environment, use the `DeploymentManager.deploy_variant` method. + +```python +# Deploy the variant to the staging environment +deployment = ag.DeploymentManager.deploy_variant( + app_slug="topic-explainer", + variant_slug="new-variant", + environment_slug="production", +) + +print("Deployed variant to environment:") +print(deployment) +``` + +- **Parameters:** + + - `environment_slug`: The slug of the environment (`development`, `staging`, or `production`). + +- **Notes:** + - Deploying a variant without specifying a `variant_version` deploys the latest version. + +**Sample Output:** + +```python +Deployed variant to environment: +{ + 'app_slug': 'topic-explainer', + 'variant_slug': 'new-variant', + 'variant_version': 2, + 'environment_slug': 'production', + 'deployment_info': { + 'deployed_at': '2023-10-02T12:30:00Z', + 'deployed_by': 'user@example.com' + } +} +``` + +## Committing a change to variant + +[ Image showing changes] + +We are now going to commit changes to our variant. Note here that this will not modify the version in deployment! + +To save changes to a variant (creating a new version), we are goin to use the `VariantManager.commit_variant` method with explicit parameters. + +```python +my_prompt2 = Prompt(temperature=0.6, + model="gpt-3.5-turbo", + max_tokens=150, + prompt=[{"role": "system", "content": "You are an assistant that provides concise answers"}, + {"role": "user", "content": "Use Paul Graham style to explain {topic} in simple terms."}], + top_p=1.0, + frequency_penalty=0.0, + presence_penalty=0.0 ) + + +# Commit the new version +variant = ag.VariantManager.commit_variant( + app_slug="topic-explainer", + variant_slug="new-variant", + config_parameters=my_prompt2.dict() +) + +print("Committed new version of variant:") +print(variant) +``` + +- **Immutability:** Each commit creates a new version of the variant. Versions are immutable once created. + +**Sample Output:** + +```python +Committed new version of variant: +{ + 'app_slug': 'topic-explainer', + 'variant_slug': 'new-variant', + 'variant_version': 2, + 'config': { + 'parameters': { + 'temperature': 0.9, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Use Paul Graham style to explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'metadata': { + 'created_at': '2023-10-02T12:00:00Z', + 'created_by': 'user@example.com' + } + } +} +``` + +## Fetching the prompt in production + +Finally we are going to fetch and use the prompt that in production. Note that the production environment is still referencing the first version of our variant. If we want it to reference the change, we need to deploy it again. + +```python +# Fetch configuration from the staging environment +config = ag.ConfigManager.get_from_registry( + app_slug="topic-explainer", + environment_slug="production" +) +myprompt = Prompt(config.parameters) +print("Fetched configuration from production:") +print(config) + +client.completion( + model=myprompt.model, + messages=format_prompt(myprompt.prompt, topic), + temperature=myprompt.temperature, + max_tokens=myprompt.max_tokens, + ) +``` + +## Next Steps + +Now that you've learned how to manage configurations using the SDK, you can: + +- Read the guide to explore more advanced features of the SDK. +- Read how to reference prompts in your traces. +- Read how to manage configuration for your workflows (chain of prompts, RAG..). From a09a7d119c883630a9d05c627ab0504f7079873b Mon Sep 17 00:00:00 2001 From: Mahmoud Mabrouk Date: Wed, 23 Oct 2024 20:12:31 +0200 Subject: [PATCH 04/16] docs(app): AGE-1151 updated tutorial prompt mangement sdj --- .../tutorials/sdk/manage-prompts-with-SDK.mdx | 72 +++++++++---------- 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx b/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx index 49069e65d3..c009202c77 100644 --- a/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx +++ b/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx @@ -4,21 +4,20 @@ title: "Manage Prompts with SDK" import Image from "@theme/IdealImage"; -In Agenta, the whole prompt management workflows happens seamlessly in the web UI. However sometimes, you would like to do things programatically without having to go throught the UI. +You can manage prompts easily through Agenta's web UI. But sometimes you might want to do things programmatically instead of using the interface. -In this tutorial we will use the Agenta SDK to create a new prompt, commit changes, deploy them to production then fetch their configuration and use it to call the LLM. +In this tutorial, we'll use the Agenta SDK to create a new prompt, commit changes, deploy them to production, then fetch their configuration and use it to call the LLM. -## Agenda +## Tutorial Overview -Before starting, let's quickly review how Agenta version prompts: - -Agenta follows a structure similar to git for prompt versioning. Instead of having one commit history where you commit changes. It follows a multiple branches (called variants) where changes can be committed, and environement where these changes can be deployed (and used in your application) ([todo: add as pop over] you can see why we chose this here). +Before we begin, let's quickly review how Agenta versions prompts: +Agenta follows a structure similar to **git** for prompt versioning. Instead of having one commit history, it uses **multiple branches (called variants)** where changes can be committed, and **environments** where these changes can be deployed (and used in your application). (You can read more about why we chose this approach [here](/concepts/concepts#motivation)). You can find more about how prompt versioning works in the [concepts page](/concepts/concepts). -The workflow of deploying a change to production we will follow in this tutorial is the following: +The workflow for deploying a change to production that we'll follow in this tutorial is: -1. Create a new variant (branch) +1. Create a new variant 2. Commit a change to that variant 3. Deploy that commit (variant/version) to the production environment 4. Commit a new change to that variant @@ -26,29 +25,28 @@ The workflow of deploying a change to production we will follow in this tutorial ## Setup -Before using the SDK, we need to initialize it using the `ag.init()` method which takes the host (default cloud.agenta.ai) and the api key (not required for community editions) +Before using the SDK, we need to initialize it using the `ag.init()` method, which takes the host (default `cloud.agenta.ai`) and the API key (not required for community editions): ```python import agenta as ag # Initialize the SDK with your API key -os.environment["AGENTA_API_KEY"] = "xxx" # Only needs setting in oss -os.environment["AGENTA_HOST"] = "https://cloud.agenta.ai" # default value no need setting explicitly +os.environ["AGENTA_API_KEY"] = "xxx" # Only needs setting in OSS +os.environ["AGENTA_HOST"] = "https://cloud.agenta.ai" # Default value, no need to set explicitly ag.init() ``` ## Creating a new prompt -Each prompt in agenta is a unique application. Currently creating a prompt is only available in the web UI. To create a new prompt, just click on create a new prompt and select whether it's a chat or completion propmt in the web UI. The name of the prompt is the slug that we will use for all the operations below. +Each prompt in Agenta is a unique application. Currently, creating a prompt is only available in the web UI. To create a new prompt, click on "Create a new prompt" and select whether it's a chat or completion prompt. The name of the prompt is the slug we'll use for all operations below. -Here we are going to create a new completion prompt we will call `topic-explainer`. Here is how our structure would look like after. +We're going to create a new completion prompt called `topic-explainer`. -[Todo: Image] +## Creating a new variant -## Creating a New Variant +[Todo: Image showing before and after. The new elements are added in different colors] -[Todo: Image showing before and after. The new elements are added in a different colors] -Variants are similar to branches in git. Any change to the prompt has to be first committed into a variant. Here we are going to create a new variant and make our first commit to it. For this we use the `VariantManager.create_variant` method: +Variants are similar to branches in **git**. Any change to the prompt must first be committed to a variant. Here, we'll create a new variant and make our first commit to it using the `VariantManager.create_variant` method: ```python @@ -75,11 +73,11 @@ print("Created variant:") print(variant) ``` -This command will create a new variant and initialize it with the first commit containing the parameters provided +This command will create a new variant and initialize it with the first commit containing the provided parameters. - **Parameters:** - `app_slug`: The unique slug of your application. - - `variant_slug`: The unique slug of the new variant . + - `variant_slug`: The unique slug of the new variant. - `config_parameters`: A dictionary containing the initial configuration parameters. **Sample Output:** @@ -101,22 +99,18 @@ Created variant: 'frequency_penalty': 0.0, 'presence_penalty': 0.0 }, - 'metadata': { - 'created_at': '2023-10-01T12:00:00Z', - 'created_by': 'user@example.com' - } } } ``` -## 5. Deploying out changes to the production environment +## Deploying changes to the production environment [Todo: Image showing before and after. The new elements are added in a different colors] To deploy our commit to an environment, use the `DeploymentManager.deploy_variant` method. ```python -# Deploy the variant to the staging environment +# Deploy the variant to the production environment deployment = ag.DeploymentManager.deploy_variant( app_slug="topic-explainer", variant_slug="new-variant", @@ -141,12 +135,9 @@ Deployed variant to environment: { 'app_slug': 'topic-explainer', 'variant_slug': 'new-variant', - 'variant_version': 2, + 'variant_version': 1 'environment_slug': 'production', - 'deployment_info': { - 'deployed_at': '2023-10-02T12:30:00Z', - 'deployed_by': 'user@example.com' - } + 'environment_version': 1 } ``` @@ -154,7 +145,7 @@ Deployed variant to environment: [ Image showing changes] -We are now going to commit changes to our variant. Note here that this will not modify the version in deployment! +We're now going to commit changes to our variant. Note that this will not modify the version in deployment! To save changes to a variant (creating a new version), we are goin to use the `VariantManager.commit_variant` method with explicit parameters. @@ -180,7 +171,9 @@ print("Committed new version of variant:") print(variant) ``` -- **Immutability:** Each commit creates a new version of the variant. Versions are immutable once created. +:::info Immutability +Each commit creates a new version of the variant. Versions are immutable once created. +::: **Sample Output:** @@ -200,10 +193,6 @@ Committed new version of variant: 'top_p': 1.0, 'frequency_penalty': 0.0, 'presence_penalty': 0.0 - }, - 'metadata': { - 'created_at': '2023-10-02T12:00:00Z', - 'created_by': 'user@example.com' } } } @@ -211,7 +200,7 @@ Committed new version of variant: ## Fetching the prompt in production -Finally we are going to fetch and use the prompt that in production. Note that the production environment is still referencing the first version of our variant. If we want it to reference the change, we need to deploy it again. +Now we'll fetch and use the prompt that's in production. Keep in mind that the production environment still references the first version of our variant. If we want it to reflect the latest changes, we'll need to deploy it again. ```python # Fetch configuration from the staging environment @@ -228,6 +217,9 @@ client.completion( messages=format_prompt(myprompt.prompt, topic), temperature=myprompt.temperature, max_tokens=myprompt.max_tokens, + top_p=myprompt.top_p, + frequency_penalty=myprompt.frequency_penalty, + presence_penalty=myprompt.presence_penalty, ) ``` @@ -235,6 +227,6 @@ client.completion( Now that you've learned how to manage configurations using the SDK, you can: -- Read the guide to explore more advanced features of the SDK. -- Read how to reference prompts in your traces. -- Read how to manage configuration for your workflows (chain of prompts, RAG..). +- Read the guide to explore more advanced features of the SDK. [add link] +- Read how to reference prompts in your traces. [add link] +- Read how to manage configuration for your workflows (chain of prompts, RAG..). [add link] From 799f9e7d507a820528b477053463195f66c4de58 Mon Sep 17 00:00:00 2001 From: Mahmoud Mabrouk Date: Wed, 23 Oct 2024 20:41:20 +0200 Subject: [PATCH 05/16] docs(app): AGE-1151 concept-motivation+link-fixes --- docs/blog/main.mdx | 2 +- docs/docs/concepts/01-concepts.mdx | 16 +- .../03-creating-a-custom-template.mdx | 2 +- .../03-prompt-management-sdk.mdx | 447 ++++++++++++++++++ .../custom-workflows/list_templates.mdx | 8 +- 5 files changed, 468 insertions(+), 7 deletions(-) create mode 100644 docs/docs/prompt-management/03-prompt-management-sdk.mdx diff --git a/docs/blog/main.mdx b/docs/blog/main.mdx index 3c6b24de40..19fd769ffb 100644 --- a/docs/blog/main.mdx +++ b/docs/blog/main.mdx @@ -196,7 +196,7 @@ We have worked extensively on improving the **reliability of evaluations**. Spec - We fixed small UI issues with large output in human evaluations. - We have added a new export button in the evaluation view to export the results as a CSV file. -Additionally, we have added a new [Cookbook for run evaluation using the SDK](/guides/cookbooks/evaluations_with_sdk). +Additionally, we have added a new [Cookbook for run evaluation using the SDK](/tutorials/sdk/evaluate-with-SDK). In **observability**: diff --git a/docs/docs/concepts/01-concepts.mdx b/docs/docs/concepts/01-concepts.mdx index d26f354f70..581dfd704f 100644 --- a/docs/docs/concepts/01-concepts.mdx +++ b/docs/docs/concepts/01-concepts.mdx @@ -4,10 +4,24 @@ title: "Core Concepts" import Image from "@theme/IdealImage"; +## Motivation + +Building reliable LLM applications goes beyond crafting a single prompt or selecting a model. It's about experimentation—trying various prompts, models, configurations, and AI workflows to determine what works best. Without a robust system, managing these experiments can quickly become chaotic. + +Agenta addresses this challenge by structuring experimentation in a manner similar to **git**'s code management. Rather than maintaining a single, linear history of changes, you can create multiple branches—called **variants** in Agenta. Each **variant** represents a distinct approach or solution you're exploring. + +Within each **variant**, you can make changes that are saved as immutable **versions**. This means every change is recorded and you can always go back to a previous version if needed. + +To move from experimentation to deployment, Agenta uses **environments** like development, staging, and production. You can deploy specific versions of your variants to these environments, controlling what gets tested and what goes live. + +In each of your experiments pre-production or in the environment post-production, all the data that you generate is stored and linked to the **variant** and **version** that you used to generate it. This allows you to always go back to the **variant** and **version** that generated a particular data point and see which **variant** and **version** performed best on it. + +## Concepts + Below are the description to the main terms and concepts used in Agenta. Taxonomy of concepts in Agenta +**Summary concepts prompt management** + Taxonomy of concepts in Agenta + +Each prompt in agenta is connsidered as an app that is referenced by it's slug. +Each app has three environments where you can deploy and fetch changes (production, staging, and development). + +Each app addtionally has variants (which are similar to branches), changes are committed to these variants. + +The workflow of deploying something to production is follows: + +1. (optionally) Create a new variant (branch) +2. Commit a change to that variant +3. Deploy that commit (variant/version) to an environment + + + +## Setup + +Before using the SDK, you need to initialize it using the `ag.init()` method. + +```python +import agenta as ag + +# Initialize the SDK with your API key +os.environment["AGENTA_API_KEY"] = "xxx" # Only needs setting in oss +os.environment["AGENTA_HOST"] = "https://cloud.agenta.ai" # default value no need setting explicitly +ag.init() +``` + +## Creating a new prompt + +Each prompt in agenta is a unique application. Currently creating a prompt is only available in the web UI. To create a new prompt, just click on create a new prompt and select whether it's a chat or completion propmt in the web UI. + +## Deploying a change to production + +We describe here how to create a first variant in Agenta, and deploy it to production + +### 1. Creating a New Variant + +To create a new variant, use the `VariantManager.create_variant` method with explicit parameters. + +```python + +from agenta import Prompt + +# Prompt is a pydantic BaseModel, for additional validation +my_prompt = Prompt(temperature=0.6, + model="gpt-3.5-turbo", + max_tokens=150, + prompt=[{"role": "system", "content": "You are an assistant that provides concise answers"}, + {"role": "user", "content": "Explain {topic} in simple terms"}], + top_p=1.0, + frequency_penalty=0.0, + presence_penalty=0.0 ) + +# Create a new variant +variant = ag.VariantManager.create_variant( + app_slug="my-app", + variant_slug="new-variant", + config_parameters=my_prompt.dict() +) + +print("Created variant:") +print(variant) +``` + +This command will create a new variant and initialize it with the first commit containing the parameters provided + +- **Parameters:** + - `app_slug`: The slug of your application. + - `variant_slug`: The slug of the new variant. + - `config_parameters`: A dictionary containing the initial configuration parameters. + +**Note:** If a variant with the same `slug` and `version` already exists, the SDK will raise an exception. + +**Sample Output:** + +```python +Created variant: +{ + 'app_slug': 'my-app', + 'variant_slug': 'new-variant', + 'variant_version': 1, + 'config': { + 'parameters': { + 'temperature': 0.7, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'metadata': { + 'created_at': '2023-10-01T12:00:00Z', + 'created_by': 'user@example.com' + } + } +} +``` + +## 5. Deploying a Variant to an Environment + +To deploy a variant to an environment, use the `DeploymentManager.deploy_variant` method with explicit parameters. + +```python +# Deploy the variant to the staging environment +deployment = ag.DeploymentManager.deploy_variant( + app_slug="my-app", + variant_slug="new-variant", + variant_version=None, # Optional: If not provided, deploys the latest version + environment_slug="staging", + environment_version=None, # Optional +) + +print("Deployed variant to environment:") +print(deployment) +``` + +- **Parameters:** + + - `environment_slug`: The slug of the environment (`development`, `staging`, or `production`). + - Other parameters as before. + +- **Notes:** + - Deploying a variant without specifying a `variant_version` deploys the latest version. + - Only predefined environments are currently supported. + +**Sample Output:** + +```python +Deployed variant to environment: +{ + 'app_slug': 'my-app', + 'variant_slug': 'new-variant', + 'variant_version': 2, + 'environment_slug': 'staging', + 'deployment_info': { + 'deployed_at': '2023-10-02T12:30:00Z', + 'deployed_by': 'user@example.com' + } +} +``` + +## Committing a Variant Version + +To save changes to a variant (creating a new version), use the `VariantManager.commit_variant` method with explicit parameters. + +```python +# Update the configuration parameters +updated_parameters = { + **initial_parameters, + 'temperature': 0.9 # Adjust the temperature +} + +# Commit the new version +variant = ag.VariantManager.commit_variant( + app_slug="my-app", + variant_slug="new-variant", + variant_version=None, # Optional: Will create a new version + config_parameters=updated_parameters +) + +print("Committed new version of variant:") +print(variant) +``` + +- **Immutability:** Each commit creates a new version of the variant. Versions are immutable once created. + +**Sample Output:** + +```python +Committed new version of variant: +{ + 'app_slug': 'my-app', + 'variant_slug': 'new-variant', + 'variant_version': 2, + 'config': { + 'parameters': { + 'temperature': 0.9, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'metadata': { + 'created_at': '2023-10-02T12:00:00Z', + 'created_by': 'user@example.com' + } + } +} +``` + +## 6. Fetching Configurations + +You can fetch configurations by providing explicit parameters. + +### a. Fetching by Variant Reference + +```python +# Fetch configuration by variant +config = ag.ConfigManager.get_from_registry( + app_slug="my-app", + variant_slug="new-variant", + variant_version=2 +) + +print("Fetched configuration:") +print(config) +``` + +**Sample Output:** + +```python +Fetched configuration: +{ + 'app_slug': 'my-app', + 'variant_slug': 'new-variant', + 'variant_version': 2, + 'config': { + 'parameters': { + 'temperature': 0.9, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'metadata': { + 'created_at': '2023-10-02T12:00:00Z', + 'created_by': 'user@example.com' + } + } +} +``` + +### b. Fetching by Environment Reference + +```python +# Fetch configuration from the staging environment +config = ag.ConfigManager.get_from_registry( + app_slug="my-app", + environment_slug="staging" +) + +print("Fetched configuration from staging:") +print(config) +``` + +**Sample Output:** + +```python +Fetched configuration from staging: +{ + 'app_slug': 'my-app', + 'variant_slug': 'new-variant', + 'variant_version': 2, + 'environment_slug': 'staging', + 'config': { + 'parameters': { + 'temperature': 0.9, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'metadata': { + 'deployed_at': '2023-10-02T12:30:00Z', + 'deployed_by': 'user@example.com' + } + } +} +``` + +### c. Default Behavior + +If you don't provide either `variant` or `environment` identifiers, the SDK fetches the latest configuration deployed to the `production` environment. + +```python +# Fetch configuration from production (default) +config = ag.ConfigManager.get_from_registry( + app_slug="my-app" +) + +print("Fetched configuration from production:") +print(config) +``` + +### d. Schema Validation with Pydantic + +If you have a predefined schema for your configuration, you can use Pydantic to validate it. The configuration parameters will be under `config['parameters']`. + +```python +from pydantic import BaseModel + +# Define your configuration schema +class MyConfigSchema(BaseModel): + temperature: float + model: str + max_tokens: int + prompt_system: str + prompt_user: str + top_p: float + frequency_penalty: float + presence_penalty: float + +# Fetch and validate configuration +config_dict = ag.ConfigManager.get_from_registry( + app_slug="my-app", + variant_slug="new-variant", + variant_version=2 +) + +# Validate the parameters +config_parameters = config_dict['config']['parameters'] +config = MyConfigSchema(**config_parameters) + +print("Validated configuration:") +print(config) +``` + +- **Note:** The `config` object will now be an instance of `MyConfigSchema`. + +## 7. Deleting a Variant + +To delete a variant, use the `VariantManager.delete_variant` method with explicit parameters. + +```python +# Delete a variant +ag.VariantManager.delete_variant( + app_slug="my-app", + variant_slug="obsolete-variant" +) + +print("Variant deleted successfully.") +``` + +- **Warning:** Deleting a variant removes all versions of the variant. This action is irreversible. + +## 8. Listing All Variants + +To list all variants of an application, use the `VariantManager.list_variants` method. + +```python +# List all variants +variants = ag.VariantManager.list_variants(app_slug="my-app") + +print("List of variants:") +for variant in variants: + print(variant) +``` + +**Sample Output:** + +```python +List of variants: +{ + 'variant_slug': 'new-variant', + 'versions': [1, 2], + 'latest_version': 2 +} +{ + 'variant_slug': 'another-variant', + 'versions': [1], + 'latest_version': 1 +} +``` + +- **Information Provided:** The list includes all variants with their `variant_slug`, available `versions`, and `latest_version`. + +## 9. Handling Errors + +The SDK raises exceptions for error conditions. It's good practice to handle these exceptions in your code. + +```python +try: + # Attempt to create a variant that already exists + variant = ag.VariantManager.create_variant( + app_slug="my-app", + variant_slug="existing-variant", + config_parameters=initial_parameters + ) +except Exception as e: + print(f"An error occurred: {e}") +``` + +- **Common Exceptions:** + - Providing both variant and environment identifiers when fetching configurations. + - Conflicts when adding or committing configurations with existing `variant_slug` and `variant_version`. + - Attempting to modify an immutable version. + +## 10. Asynchronous Operations + +If your application uses asynchronous programming, you can use the async versions of the methods. + +```python +# Asynchronous fetching of configuration +config = await ag.ConfigManager.async_get_from_registry( + app_slug="my-app", + variant_slug="new-variant", + variant_version=2 +) + +print("Fetched configuration asynchronously:") +print(config) +``` + +- **Note:** Ensure that you're running this code within an asynchronous event loop. + +## 11. Thread Safety + +The SDK is designed to be thread-safe. You can use it in multi-threaded applications without worrying about shared mutable states. + +## Next Steps + +Now that you've learned how to manage configurations using the SDK with explicit parameters, you can: + +- Explore more advanced features of the SDK. +- Integrate the SDK into your application's deployment pipeline. +- Use the SDK to automate configuration management tasks. diff --git a/docs/docs/tutorials/custom-workflows/list_templates.mdx b/docs/docs/tutorials/custom-workflows/list_templates.mdx index 29b6434413..859762b86c 100644 --- a/docs/docs/tutorials/custom-workflows/list_templates.mdx +++ b/docs/docs/tutorials/custom-workflows/list_templates.mdx @@ -8,17 +8,17 @@ sidebar_position: 1 ## 📝 Text Generation -### [Single Prompt Application using OpenAI and Langchain](/guides/tutorials/first-app-with-langchain) +### [Single Prompt Application using OpenAI and Langchain](/tutorials/custom-workflows/first-app-with-langchain) Learn how to use our SDK to deploy an application with agenta. The application we will create uses OpenAI and Langchain. The application generates outreach messages in Linkedin to investors based on a startup name and idea. -### [Use Mistral from Huggingface for a Summarization Task](/guides/tutorials/deploy-mistral-model) +### [Use Mistral from Huggingface for a Summarization Task](/tutorials/custom-workflows/deploy-mistral-model) Learn how to use a custom model with agenta. ## Retrieval Augmented Generation (RAG) -### [RAG Application with LlamaIndex](/guides/tutorials/build-rag-application) +### [RAG Application with LlamaIndex](/tutorials/custom-workflows/build-rag-application) Learn how to create a RAG application with LlamaIndex and use it in agenta. You will create a playground in agenta where you can experiment with the parameters of the RAG application, test it and compare different versions. @@ -28,6 +28,6 @@ Learn how to create a RAG application with LlamaIndex and use it in agenta. You These templates extract data in a structured format from an unstructured source. -### [Extraction using OpenAI Functions and Langchain](/guides/tutorials/extract_job_information) +### [Extraction using OpenAI Functions and Langchain](/tutorials/custom-workflows/extract_job_information) Extracts job information (company name, job title, salary range) from a job description. Uses OpenAI Functions and Langchain. From de3fedd24aefea70939a529c249f2c5ec42555c0 Mon Sep 17 00:00:00 2001 From: Mahmoud Mabrouk Date: Fri, 25 Oct 2024 08:14:32 +0200 Subject: [PATCH 06/16] docs(app): AGE-1151 update prompt management sdk howto --- .../03-prompt-management-sdk.mdx | 290 +++++++----------- 1 file changed, 103 insertions(+), 187 deletions(-) diff --git a/docs/docs/prompt-management/03-prompt-management-sdk.mdx b/docs/docs/prompt-management/03-prompt-management-sdk.mdx index 2d656f1b1a..a36934c6e3 100644 --- a/docs/docs/prompt-management/03-prompt-management-sdk.mdx +++ b/docs/docs/prompt-management/03-prompt-management-sdk.mdx @@ -4,33 +4,35 @@ title: "Manage Prompt with the SDK" import Image from "@theme/IdealImage"; -In this guide we go through all actions done through the SDK (creating a variant, committing changes, deploying changes, fetching configurations). If you would like a more simple introduction, please read the prompt mangement tutorial here [todo add link] +In this guide, we'll explore all actions performed through the SDK: creating variants, committing changes, deploying changes, and fetching configurations. For a simpler introduction, please refer to the [prompt mangement tutorial](/tutorials/sdk/manage-prompts-with-SDK). -Agenta follows a structure similar to git for prompt versioning. Instead of having one commit history where you commit changes. It follows a multiple branches (called variants) where changes can be committed, and environement where these changes can be deployed (and used in your application) ([todo: add as pop over] you can see why we chose this here). +Before starting, we recommend to get acquainted with how versioning works in Agenta. You can find more details on the [concepts page](/concepts/concepts), or read the quick summary below. -Below is a short summary of how versioning works in Agenta, you can find more in the [concepts page](/concepts/concepts). +:::info Versioning in Agenta -
-**Summary concepts prompt management** - Taxonomy of concepts in Agenta +{" "} -Each prompt in agenta is connsidered as an app that is referenced by it's slug. -Each app has three environments where you can deploy and fetch changes (production, staging, and development). +Taxonomy of concepts in Agenta +Agenta follows a structure similar to **git** for prompt versioning. Instead of a +single commit history, you can create multiple branches—called **variants**. Each +variant represents a distinct approach or solution you're exploring. -Each app addtionally has variants (which are similar to branches), changes are committed to these variants. +To move from experimentation to deployment, Agenta uses **environments** like +**development**, **staging**, and **production**. You can deploy specific versions of your **variants** +to these **environments**, controlling what gets tested and what goes live. -The workflow of deploying something to production is follows: +The workflow of deploying something to production is therefore as follows: -1. (optionally) Create a new variant (branch) -2. Commit a change to that variant -3. Deploy that commit (variant/version) to an environment +1. (optionally) Create a new **variant** (branch) +2. Commit a change to that **variant** +3. Deploy that **commit** (**variant**/**version**) to an **environment** -
+::: ## Setup @@ -47,15 +49,13 @@ ag.init() ## Creating a new prompt -Each prompt in agenta is a unique application. Currently creating a prompt is only available in the web UI. To create a new prompt, just click on create a new prompt and select whether it's a chat or completion propmt in the web UI. +Each prompt in agenta is a unique application. Currently creating a prompt is only available in the web UI. To create a new prompt, just click on create a new prompt and select whether it's a chat or completion prompt in the web UI. -## Deploying a change to production +## Committing changes -We describe here how to create a first variant in Agenta, and deploy it to production +### Creating a New Variant -### 1. Creating a New Variant - -To create a new variant, use the `VariantManager.create_variant` method with explicit parameters. +To create a new variant, use the `VariantManager.create_variant` method. ```python @@ -109,122 +109,128 @@ Created variant: 'top_p': 1.0, 'frequency_penalty': 0.0, 'presence_penalty': 0.0 - }, - 'metadata': { - 'created_at': '2023-10-01T12:00:00Z', - 'created_by': 'user@example.com' } } } ``` -## 5. Deploying a Variant to an Environment +### Committing Changes to a Variant -To deploy a variant to an environment, use the `DeploymentManager.deploy_variant` method with explicit parameters. +To save changes to a variant (creating a new version), use the `VariantManager.commit_variant` method with explicit parameters. ```python -# Deploy the variant to the staging environment -deployment = ag.DeploymentManager.deploy_variant( +my_prompt2 = Prompt(temperature=1.0, + model="gpt-4", + max_tokens=150, + prompt=[{"role": "system", "content": "You are an assistant that provides concise answers"}, + {"role": "user", "content": "Explain {topic} in simple terms"}], + top_p=1.0, + frequency_penalty=0.0, + presence_penalty=0.0 ) + +# Commit the new version +variant = ag.VariantManager.commit_variant( app_slug="my-app", variant_slug="new-variant", - variant_version=None, # Optional: If not provided, deploys the latest version - environment_slug="staging", - environment_version=None, # Optional + config_parameters=my_prompt2.dict() ) -print("Deployed variant to environment:") -print(deployment) +print("Committed new version of variant:") +print(variant) ``` -- **Parameters:** - - - `environment_slug`: The slug of the environment (`development`, `staging`, or `production`). - - Other parameters as before. - -- **Notes:** - - Deploying a variant without specifying a `variant_version` deploys the latest version. - - Only predefined environments are currently supported. +:::info Immutability +Each commit creates a new version of the variant. Versions are immutable once created. +::: **Sample Output:** ```python -Deployed variant to environment: +Committed new version of variant: { 'app_slug': 'my-app', 'variant_slug': 'new-variant', 'variant_version': 2, - 'environment_slug': 'staging', - 'deployment_info': { - 'deployed_at': '2023-10-02T12:30:00Z', - 'deployed_by': 'user@example.com' + 'config': { + 'parameters': { + 'temperature': 0.9, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + } } } ``` -## Committing a Variant Version +## Deploying to an Environment -To save changes to a variant (creating a new version), use the `VariantManager.commit_variant` method with explicit parameters. +To deploy a variant to an environment, use the `DeploymentManager.deploy_variant` method with the variant reference and `environment_slug`: The slug of the environment (`development`, `staging`, or `production`). ```python -# Update the configuration parameters -updated_parameters = { - **initial_parameters, - 'temperature': 0.9 # Adjust the temperature -} - -# Commit the new version -variant = ag.VariantManager.commit_variant( +# Deploy the variant to the staging environment +deployment = ag.DeploymentManager.deploy_variant( app_slug="my-app", variant_slug="new-variant", - variant_version=None, # Optional: Will create a new version - config_parameters=updated_parameters + variant_version=None, # Optional: If not provided, deploys the latest version + environment_slug="staging" ) -print("Committed new version of variant:") -print(variant) +print("Deployed variant to environment:") +print(deployment) ``` -- **Immutability:** Each commit creates a new version of the variant. Versions are immutable once created. +:::warning + +- Deploying a variant without specifying a `variant_version` deploys the latest version. +- Only predefined environments with slugs `development`, `staging`, and `production` are currently supported. + ::: **Sample Output:** ```python -Committed new version of variant: +Deployed variant to environment: { 'app_slug': 'my-app', 'variant_slug': 'new-variant', 'variant_version': 2, - 'config': { - 'parameters': { - 'temperature': 0.9, - 'model': 'gpt-3.5-turbo', - 'max_tokens': 150, - 'prompt_system': 'You are an assistant that provides concise answers.', - 'prompt_user': 'Explain {topic} in simple terms.', - 'top_p': 1.0, - 'frequency_penalty': 0.0, - 'presence_penalty': 0.0 - }, - 'metadata': { - 'created_at': '2023-10-02T12:00:00Z', - 'created_by': 'user@example.com' - } + 'environment_slug': 'staging', + 'deployment_info': { + 'deployed_at': '2023-10-02T12:30:00Z', + 'deployed_by': 'user@example.com' } } ``` -## 6. Fetching Configurations +## Fetching Configurations + +You can fetch the configurations from a variant reference (`app_slug`, `variant_slug`, `variant_version`) or an environment reference (`app_slug`, `environment_slug`). The default behavior when fetching is to fetch the latest configuration from the `production` environment. If you don't provide a `_version` parameter but only a `variant_slug` or an `environment_slug`, the SDK will fetch the latest version of the variant from the specified **environment/variant**. -You can fetch configurations by providing explicit parameters. +### Default Behavior when fetching -### a. Fetching by Variant Reference +If you don't provide either `variant` or `environment` identifiers, the SDK fetches the latest configuration deployed to the `production` environment. + +```python +# Fetch configuration from the latest version in production (default) +config = ag.ConfigManager.get_from_registry( + app_slug="my-app" +) + +print("Fetched configuration from production:") +print(config) +``` + +### Fetching by Variant Reference ```python # Fetch configuration by variant config = ag.ConfigManager.get_from_registry( app_slug="my-app", variant_slug="new-variant", - variant_version=2 + variant_version=2 # Optional: If not provided, fetches the latest version ) print("Fetched configuration:") @@ -249,19 +255,15 @@ Fetched configuration: 'top_p': 1.0, 'frequency_penalty': 0.0, 'presence_penalty': 0.0 - }, - 'metadata': { - 'created_at': '2023-10-02T12:00:00Z', - 'created_by': 'user@example.com' } } } ``` -### b. Fetching by Environment Reference +### Fetching by Environment Reference ```python -# Fetch configuration from the staging environment +# Fetch the latest configuration from the staging environment config = ag.ConfigManager.get_from_registry( app_slug="my-app", environment_slug="staging" @@ -290,67 +292,14 @@ Fetched configuration from staging: 'top_p': 1.0, 'frequency_penalty': 0.0, 'presence_penalty': 0.0 - }, - 'metadata': { - 'deployed_at': '2023-10-02T12:30:00Z', - 'deployed_by': 'user@example.com' } } } ``` -### c. Default Behavior +## Deleting a Variant -If you don't provide either `variant` or `environment` identifiers, the SDK fetches the latest configuration deployed to the `production` environment. - -```python -# Fetch configuration from production (default) -config = ag.ConfigManager.get_from_registry( - app_slug="my-app" -) - -print("Fetched configuration from production:") -print(config) -``` - -### d. Schema Validation with Pydantic - -If you have a predefined schema for your configuration, you can use Pydantic to validate it. The configuration parameters will be under `config['parameters']`. - -```python -from pydantic import BaseModel - -# Define your configuration schema -class MyConfigSchema(BaseModel): - temperature: float - model: str - max_tokens: int - prompt_system: str - prompt_user: str - top_p: float - frequency_penalty: float - presence_penalty: float - -# Fetch and validate configuration -config_dict = ag.ConfigManager.get_from_registry( - app_slug="my-app", - variant_slug="new-variant", - variant_version=2 -) - -# Validate the parameters -config_parameters = config_dict['config']['parameters'] -config = MyConfigSchema(**config_parameters) - -print("Validated configuration:") -print(config) -``` - -- **Note:** The `config` object will now be an instance of `MyConfigSchema`. - -## 7. Deleting a Variant - -To delete a variant, use the `VariantManager.delete_variant` method with explicit parameters. +To delete a variant, use the `VariantManager.delete_variant` method. ```python # Delete a variant @@ -362,9 +311,13 @@ ag.VariantManager.delete_variant( print("Variant deleted successfully.") ``` -- **Warning:** Deleting a variant removes all versions of the variant. This action is irreversible. +:::warning -## 8. Listing All Variants +- Deleting a variant removes all versions of the variant. This action is irreversible. +- Attempting to delete a variant that is deployed to an environment will raise an exception. + ::: + +## Listing All Variants To list all variants of an application, use the `VariantManager.list_variants` method. @@ -393,30 +346,7 @@ List of variants: } ``` -- **Information Provided:** The list includes all variants with their `variant_slug`, available `versions`, and `latest_version`. - -## 9. Handling Errors - -The SDK raises exceptions for error conditions. It's good practice to handle these exceptions in your code. - -```python -try: - # Attempt to create a variant that already exists - variant = ag.VariantManager.create_variant( - app_slug="my-app", - variant_slug="existing-variant", - config_parameters=initial_parameters - ) -except Exception as e: - print(f"An error occurred: {e}") -``` - -- **Common Exceptions:** - - Providing both variant and environment identifiers when fetching configurations. - - Conflicts when adding or committing configurations with existing `variant_slug` and `variant_version`. - - Attempting to modify an immutable version. - -## 10. Asynchronous Operations +## Asynchronous Operations If your application uses asynchronous programming, you can use the async versions of the methods. @@ -431,17 +361,3 @@ config = await ag.ConfigManager.async_get_from_registry( print("Fetched configuration asynchronously:") print(config) ``` - -- **Note:** Ensure that you're running this code within an asynchronous event loop. - -## 11. Thread Safety - -The SDK is designed to be thread-safe. You can use it in multi-threaded applications without worrying about shared mutable states. - -## Next Steps - -Now that you've learned how to manage configurations using the SDK with explicit parameters, you can: - -- Explore more advanced features of the SDK. -- Integrate the SDK into your application's deployment pipeline. -- Use the SDK to automate configuration management tasks. From 95b94efaa72a2652ade4eb4866aab04d9efcbcf6 Mon Sep 17 00:00:00 2001 From: jp-agenta Date: Wed, 6 Nov 2024 17:48:30 +0100 Subject: [PATCH 07/16] Update docs to match implementation, without testing in this case. --- .../03-prompt-management-sdk.mdx | 343 ++++++++++++------ 1 file changed, 240 insertions(+), 103 deletions(-) diff --git a/docs/docs/prompt-management/03-prompt-management-sdk.mdx b/docs/docs/prompt-management/03-prompt-management-sdk.mdx index a36934c6e3..8db7ee0411 100644 --- a/docs/docs/prompt-management/03-prompt-management-sdk.mdx +++ b/docs/docs/prompt-management/03-prompt-management-sdk.mdx @@ -62,20 +62,25 @@ To create a new variant, use the `VariantManager.create_variant` method. from agenta import Prompt # Prompt is a pydantic BaseModel, for additional validation -my_prompt = Prompt(temperature=0.6, - model="gpt-3.5-turbo", - max_tokens=150, - prompt=[{"role": "system", "content": "You are an assistant that provides concise answers"}, - {"role": "user", "content": "Explain {topic} in simple terms"}], - top_p=1.0, - frequency_penalty=0.0, - presence_penalty=0.0 ) +my_prompt = Prompt( + temperature=0.7, + model="gpt-3.5-turbo", + max_tokens=150, + prompt=[ + {"role": "system", "content": "You are an assistant that provides concise answers"}, + {"role": "user", "content": "Explain {topic} in simple terms"} + ], + top_p=1.0, + frequency_penalty=0.0, + presence_penalty=0.0 +) # Create a new variant variant = ag.VariantManager.create_variant( - app_slug="my-app", - variant_slug="new-variant", - config_parameters=my_prompt.dict() + parameters=my_prompt.model_dump(), + app_slug="my-app-slug", + # app_id="my-app-id", # you can also use `app_id` + variant_slug="my-variant-slug", ) print("Created variant:") @@ -87,7 +92,7 @@ This command will create a new variant and initialize it with the first commit c - **Parameters:** - `app_slug`: The slug of your application. - `variant_slug`: The slug of the new variant. - - `config_parameters`: A dictionary containing the initial configuration parameters. + - `parameters`: A dictionary containing the initial configuration parameters. **Note:** If a variant with the same `slug` and `version` already exists, the SDK will raise an exception. @@ -96,21 +101,24 @@ This command will create a new variant and initialize it with the first commit c ```python Created variant: { - 'app_slug': 'my-app', - 'variant_slug': 'new-variant', + 'parameters': { + 'temperature': 0.7, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'app_id': 'my-app-id', + 'app_slug': 'my-app-slug', + 'variant_id': 'new-variant-id', + 'variant_slug': 'my-variant-slug', 'variant_version': 1, - 'config': { - 'parameters': { - 'temperature': 0.7, - 'model': 'gpt-3.5-turbo', - 'max_tokens': 150, - 'prompt_system': 'You are an assistant that provides concise answers.', - 'prompt_user': 'Explain {topic} in simple terms.', - 'top_p': 1.0, - 'frequency_penalty': 0.0, - 'presence_penalty': 0.0 - } - } + 'committed_at': 'current-datetime', + 'committed_by': 'my-email-address', + 'committed_by_id': 'my-user-id', } ``` @@ -119,20 +127,24 @@ Created variant: To save changes to a variant (creating a new version), use the `VariantManager.commit_variant` method with explicit parameters. ```python -my_prompt2 = Prompt(temperature=1.0, - model="gpt-4", - max_tokens=150, - prompt=[{"role": "system", "content": "You are an assistant that provides concise answers"}, - {"role": "user", "content": "Explain {topic} in simple terms"}], - top_p=1.0, - frequency_penalty=0.0, - presence_penalty=0.0 ) +my_prompt2 = Prompt( + temperature=1.0, + model="gpt-4", + max_tokens=150, + prompt=[ + {"role": "system", "content": "You are an assistant that provides concise answers"}, + {"role": "user", "content": "Explain {topic} in simple terms"} + ], + top_p=1.0, + frequency_penalty=0.0, + presence_penalty=0.0 +) # Commit the new version variant = ag.VariantManager.commit_variant( - app_slug="my-app", - variant_slug="new-variant", - config_parameters=my_prompt2.dict() + parameters=my_prompt2.model_dump(), + app_slug="my-app-slug", + variant_slug="my-variant-slug", ) print("Committed new version of variant:") @@ -148,21 +160,24 @@ Each commit creates a new version of the variant. Versions are immutable once cr ```python Committed new version of variant: { - 'app_slug': 'my-app', - 'variant_slug': 'new-variant', - 'variant_version': 2, - 'config': { - 'parameters': { - 'temperature': 0.9, - 'model': 'gpt-3.5-turbo', - 'max_tokens': 150, - 'prompt_system': 'You are an assistant that provides concise answers.', - 'prompt_user': 'Explain {topic} in simple terms.', - 'top_p': 1.0, - 'frequency_penalty': 0.0, - 'presence_penalty': 0.0 - } + 'parameters': { + 'temperature': 1.0, + 'model': 'gpt-4', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 } + 'app_id': 'my-app-id', + 'app_slug': 'my-app-slug', + 'variant_id': 'updated-variant-id', + 'variant_slug': 'my-variant-slug', + 'variant_version': 2, + 'committed_at': 'current-datetime', + 'committed_by': 'my-email-address', + 'committed_by_id': 'my-user-id', } ``` @@ -173,8 +188,9 @@ To deploy a variant to an environment, use the `DeploymentManager.deploy_variant ```python # Deploy the variant to the staging environment deployment = ag.DeploymentManager.deploy_variant( - app_slug="my-app", - variant_slug="new-variant", + app_slug="my-app-slug", + # app_id="my-app-id", # you can also use `app_id` + variant_slug="my-variant-slug", variant_version=None, # Optional: If not provided, deploys the latest version environment_slug="staging" ) @@ -194,14 +210,27 @@ print(deployment) ```python Deployed variant to environment: { - 'app_slug': 'my-app', - 'variant_slug': 'new-variant', - 'variant_version': 2, + 'parameters': { + 'temperature': 0.7, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'app_id': 'my-app-id', + 'app_slug': 'my-app-slug', + 'variant_id': 'new-variant-id', + 'variant_slug': 'my-variant-slug', + 'variant_version': 1, + 'environment_id': 'staging-enviroment-id', 'environment_slug': 'staging', - 'deployment_info': { - 'deployed_at': '2023-10-02T12:30:00Z', - 'deployed_by': 'user@example.com' - } + 'environment_version': 1, + 'deployed_at': 'current-datetime', + 'deployed_by': 'my-email-address', + 'deployed_by_id': 'my-user-id', } ``` @@ -216,7 +245,8 @@ If you don't provide either `variant` or `environment` identifiers, the SDK fetc ```python # Fetch configuration from the latest version in production (default) config = ag.ConfigManager.get_from_registry( - app_slug="my-app" + app_slug="my-app-slug" + # app_id="my-app-id", # you can also use `app_id` ) print("Fetched configuration from production:") @@ -228,8 +258,9 @@ print(config) ```python # Fetch configuration by variant config = ag.ConfigManager.get_from_registry( - app_slug="my-app", - variant_slug="new-variant", + app_slug="my-app-slug", + # app_id="my-app-id", # you can also use `app_id` + variant_slug="my-variant-slug", variant_version=2 # Optional: If not provided, fetches the latest version ) @@ -242,21 +273,24 @@ print(config) ```python Fetched configuration: { - 'app_slug': 'my-app', - 'variant_slug': 'new-variant', - 'variant_version': 2, - 'config': { - 'parameters': { - 'temperature': 0.9, - 'model': 'gpt-3.5-turbo', - 'max_tokens': 150, - 'prompt_system': 'You are an assistant that provides concise answers.', - 'prompt_user': 'Explain {topic} in simple terms.', - 'top_p': 1.0, - 'frequency_penalty': 0.0, - 'presence_penalty': 0.0 - } + 'parameters': { + 'temperature': 1.0, + 'model': 'gpt-4', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 } + 'app_id': 'my-app-id', + 'app_slug': 'my-app-slug', + 'variant_id': 'updated-variant-id', + 'variant_slug': 'my-variant-slug', + 'variant_version': 2, + 'committed_at': 'current-datetime', + 'committed_by': 'my-email-address', + 'committed_by_id': 'my-user-id', } ``` @@ -267,6 +301,7 @@ Fetched configuration: config = ag.ConfigManager.get_from_registry( app_slug="my-app", environment_slug="staging" + environment_version=1 # Optional: If not provided, fetches the latest version ) print("Fetched configuration from staging:") @@ -278,22 +313,27 @@ print(config) ```python Fetched configuration from staging: { - 'app_slug': 'my-app', - 'variant_slug': 'new-variant', - 'variant_version': 2, + 'parameters': { + 'temperature': 0.7, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'app_id': 'my-app-id', + 'app_slug': 'my-app-slug', + 'variant_id': 'new-variant-id', + 'variant_slug': 'my-variant-slug', + 'variant_version': 1, + 'environment_id': 'staging-enviroment-id', 'environment_slug': 'staging', - 'config': { - 'parameters': { - 'temperature': 0.9, - 'model': 'gpt-3.5-turbo', - 'max_tokens': 150, - 'prompt_system': 'You are an assistant that provides concise answers.', - 'prompt_user': 'Explain {topic} in simple terms.', - 'top_p': 1.0, - 'frequency_penalty': 0.0, - 'presence_penalty': 0.0 - } - } + 'environment_version': 1, + 'deployed_at': 'current-datetime', + 'deployed_by': 'my-email-address', + 'deployed_by_id': 'my-user-id', } ``` @@ -305,6 +345,7 @@ To delete a variant, use the `VariantManager.delete_variant` method. # Delete a variant ag.VariantManager.delete_variant( app_slug="my-app", + # app_id="my-app-id", # you can also use `app_id` variant_slug="obsolete-variant" ) @@ -314,7 +355,7 @@ print("Variant deleted successfully.") :::warning - Deleting a variant removes all versions of the variant. This action is irreversible. -- Attempting to delete a variant that is deployed to an environment will raise an exception. +- Attempting to delete a variant that is deployed to an environment will fail. ::: ## Listing All Variants @@ -323,7 +364,72 @@ To list all variants of an application, use the `VariantManager.list_variants` m ```python # List all variants -variants = ag.VariantManager.list_variants(app_slug="my-app") +variants = ag.VariantManager.list_variants( + app_slug="my-app" + # app_id="my-app-id", # you can also use `app_id` +) + +print("List of variants:") +for variant in variants: + print(variant) +``` + +**Sample Output:** + +```python +List of variants: +{ + 'parameters': { + 'temperature': 1.0, + 'model': 'gpt-4', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + } + 'app_id': 'my-app-id', + 'app_slug': 'my-app-slug', + 'variant_id': 'updated-variant-id', + 'variant_slug': 'my-variant-slug', + 'variant_version': 2, + 'committed_at': 'current-datetime', + 'committed_by': 'my-email-address', + 'committed_by_id': 'my-user-id', +} +{ + 'parameters': { + 'temperature': 0.5, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 100, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + } + 'app_id': 'my-app-id', + 'app_slug': 'my-app-slug', + 'variant_id': 'another-variant-id', + 'variant_slug': 'another-variant-slug', + 'variant_version': 1, + 'committed_at': 'another-datetime', + 'committed_by': 'another-email-address', + 'committed_by_id': 'another-user-id', +} +``` + +## Fetching a Variant's history + +To list all versions for a variant of an application, use the `VariantManager.list_variants` method. + +```python +# List all variants +variants = ag.VariantManager.list_variants( + app_slug="my-app" + # app_id="my-app-id", # you can also use `app_id` +) print("List of variants:") for variant in variants: @@ -335,26 +441,57 @@ for variant in variants: ```python List of variants: { - 'variant_slug': 'new-variant', - 'versions': [1, 2], - 'latest_version': 2 + 'parameters': { + 'temperature': 1.0, + 'model': 'gpt-4', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + } + 'app_id': 'my-app-id', + 'app_slug': 'my-app-slug', + 'variant_id': 'updated-variant-id', + 'variant_slug': 'my-variant-slug', + 'variant_version': 2, + 'committed_at': 'current-datetime', + 'committed_by': 'my-email-address', + 'committed_by_id': 'my-user-id', } { - 'variant_slug': 'another-variant', - 'versions': [1], - 'latest_version': 1 + 'parameters': { + 'temperature': 0.5, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 100, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + } + 'app_id': 'my-app-id', + 'app_slug': 'my-app-slug', + 'variant_id': 'another-variant-id', + 'variant_slug': 'another-variant-slug', + 'variant_version': 1, + 'committed_at': 'another-datetime', + 'committed_by': 'another-email-address', + 'committed_by_id': 'another-user-id', } ``` ## Asynchronous Operations -If your application uses asynchronous programming, you can use the async versions of the methods. +If your application uses asynchronous programming, you can use the async versions of the methods (see the `a` prefix in the function name). ```python # Asynchronous fetching of configuration -config = await ag.ConfigManager.async_get_from_registry( +config = await ag.ConfigManager.aget_from_registry( app_slug="my-app", - variant_slug="new-variant", + # app_id="my-app-id", # you can also use `app_id` + variant_slug="my-variant-slug", variant_version=2 ) From a8952ce59d36aa5e85f763f671ad3d9d0bd3effd Mon Sep 17 00:00:00 2001 From: jp-agenta Date: Thu, 7 Nov 2024 13:13:20 +0100 Subject: [PATCH 08/16] fix prompt variables for current state of template --- .../prompt-management/03-prompt-management-sdk.mdx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/docs/prompt-management/03-prompt-management-sdk.mdx b/docs/docs/prompt-management/03-prompt-management-sdk.mdx index 8db7ee0411..3660dd54aa 100644 --- a/docs/docs/prompt-management/03-prompt-management-sdk.mdx +++ b/docs/docs/prompt-management/03-prompt-management-sdk.mdx @@ -66,10 +66,8 @@ my_prompt = Prompt( temperature=0.7, model="gpt-3.5-turbo", max_tokens=150, - prompt=[ - {"role": "system", "content": "You are an assistant that provides concise answers"}, - {"role": "user", "content": "Explain {topic} in simple terms"} - ], + prompt_system="You are an assistant that provides concise answers", + prompt_user="Explain {topic} in simple terms", top_p=1.0, frequency_penalty=0.0, presence_penalty=0.0 @@ -131,10 +129,8 @@ my_prompt2 = Prompt( temperature=1.0, model="gpt-4", max_tokens=150, - prompt=[ - {"role": "system", "content": "You are an assistant that provides concise answers"}, - {"role": "user", "content": "Explain {topic} in simple terms"} - ], + prompt_system="You are an assistant that provides concise answers", + prompt_user="Explain {topic} in simple terms", top_p=1.0, frequency_penalty=0.0, presence_penalty=0.0 From 7c84545c0bf17b9beaf972b9eb70797dd27c46f3 Mon Sep 17 00:00:00 2001 From: Abraham 'Abram' Israel Date: Tue, 12 Nov 2024 09:27:40 +0100 Subject: [PATCH 09/16] refactor (cli): add Prompt sdk type --- agenta-cli/agenta/__init__.py | 1 + agenta-cli/agenta/sdk/__init__.py | 1 + agenta-cli/agenta/sdk/types.py | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/agenta-cli/agenta/__init__.py b/agenta-cli/agenta/__init__.py index 4b713d02a8..3a823a9c22 100644 --- a/agenta-cli/agenta/__init__.py +++ b/agenta-cli/agenta/__init__.py @@ -16,6 +16,7 @@ TextParam, FileInputURL, BinaryParam, + Prompt, ) from .sdk.tracing.logger import llm_logger as logging diff --git a/agenta-cli/agenta/sdk/__init__.py b/agenta-cli/agenta/sdk/__init__.py index f972482a85..435e33b386 100644 --- a/agenta-cli/agenta/sdk/__init__.py +++ b/agenta-cli/agenta/sdk/__init__.py @@ -16,6 +16,7 @@ MessagesInput, FileInputURL, BinaryParam, + Prompt, ) from .tracing.llm_tracing import Tracing diff --git a/agenta-cli/agenta/sdk/types.py b/agenta-cli/agenta/sdk/types.py index b34f380bae..cab9fb4b2c 100644 --- a/agenta-cli/agenta/sdk/types.py +++ b/agenta-cli/agenta/sdk/types.py @@ -222,7 +222,10 @@ class LifecyclesResponse(ReferencesResponse): deployed_by_id: Optional[str] = None def __str__(self): - return str(self.model_dump(exclude_none=True)) + return self.model_dump_json(indent=4) + + def __repr__(self): + return self.__str__() class ConfigurationResponse(LifecyclesResponse): @@ -231,3 +234,14 @@ class ConfigurationResponse(LifecyclesResponse): class DeploymentResponse(LifecyclesResponse): pass + + +class Prompt(BaseModel): + temperature: float + model: str + max_tokens: int + prompt_system: str + prompt_user: str + top_p: float + frequency_penalty: float + presence_penalty: float From 5740b57896af4c53b1630836260052f9e0c96ca6 Mon Sep 17 00:00:00 2001 From: Abraham 'Abram' Israel Date: Tue, 12 Nov 2024 09:28:15 +0100 Subject: [PATCH 10/16] refactor (docs): update prompt management docs based on new development in the sdk & backend --- .../03-prompt-management-sdk.mdx | 169 +++++++++++------- .../tutorials/sdk/manage-prompts-with-SDK.mdx | 127 +++++++------ 2 files changed, 184 insertions(+), 112 deletions(-) diff --git a/docs/docs/prompt-management/03-prompt-management-sdk.mdx b/docs/docs/prompt-management/03-prompt-management-sdk.mdx index 3660dd54aa..0b4c0e0871 100644 --- a/docs/docs/prompt-management/03-prompt-management-sdk.mdx +++ b/docs/docs/prompt-management/03-prompt-management-sdk.mdx @@ -39,11 +39,14 @@ The workflow of deploying something to production is therefore as follows: Before using the SDK, you need to initialize it using the `ag.init()` method. ```python +import os import agenta as ag + # Initialize the SDK with your API key -os.environment["AGENTA_API_KEY"] = "xxx" # Only needs setting in oss -os.environment["AGENTA_HOST"] = "https://cloud.agenta.ai" # default value no need setting explicitly +os.environ["AGENTA_API_KEY"] = "xxx" # Only needs setting in oss +os.environ["AGENTA_HOST"] = "https://cloud.agenta.ai" # default value no need setting explicitly + ag.init() ``` @@ -55,13 +58,14 @@ Each prompt in agenta is a unique application. Currently creating a prompt is on ### Creating a New Variant -To create a new variant, use the `VariantManager.create_variant` method. +To create a new variant, use the `VariantManager.create` method. ```python from agenta import Prompt -# Prompt is a pydantic BaseModel, for additional validation +# Prompt is a pydantic BaseModel we created for common prompt settings. +# To add more fields or validations, create your own custom model. my_prompt = Prompt( temperature=0.7, model="gpt-3.5-turbo", @@ -74,7 +78,7 @@ my_prompt = Prompt( ) # Create a new variant -variant = ag.VariantManager.create_variant( +variant = ag.VariantManager.create( parameters=my_prompt.model_dump(), app_slug="my-app-slug", # app_id="my-app-id", # you can also use `app_id` @@ -83,6 +87,18 @@ variant = ag.VariantManager.create_variant( print("Created variant:") print(variant) + +# Create a new version asynchronously (optional) +# async def create_variant(): +# variant = ag.VariantManager.acreate( +# parameters=my_prompt.model_dump(), +# app_slug="my-app-slug", +# app_id="my-app-id", # you can also use `app_id` +# variant_slug="my-variant-slug", +# ) + +# print("Created variant (async):") +# print(variant) ``` This command will create a new variant and initialize it with the first commit containing the parameters provided @@ -122,7 +138,7 @@ Created variant: ### Committing Changes to a Variant -To save changes to a variant (creating a new version), use the `VariantManager.commit_variant` method with explicit parameters. +To save changes to a variant (creating a new version), use the `VariantManager.commit` method with explicit parameters. ```python my_prompt2 = Prompt( @@ -137,7 +153,7 @@ my_prompt2 = Prompt( ) # Commit the new version -variant = ag.VariantManager.commit_variant( +variant = ag.VariantManager.commit( parameters=my_prompt2.model_dump(), app_slug="my-app-slug", variant_slug="my-variant-slug", @@ -145,6 +161,17 @@ variant = ag.VariantManager.commit_variant( print("Committed new version of variant:") print(variant) + +# Commit the new version asynchronously (optional) +# async def commit_variant(): +# variant = ag.VariantManager.acommit( +# parameters=my_prompt2.model_dump(), +# app_slug="my-app-slug", +# variant_slug="my-variant-slug", +# ) + +# print("Committed new version of variant (async):") +# print(variant) ``` :::info Immutability @@ -179,11 +206,11 @@ Committed new version of variant: ## Deploying to an Environment -To deploy a variant to an environment, use the `DeploymentManager.deploy_variant` method with the variant reference and `environment_slug`: The slug of the environment (`development`, `staging`, or `production`). +To deploy a variant to an environment, use the `DeploymentManager.deploy` method with the variant reference and `environment_slug`: The slug of the environment (`development`, `staging`, or `production`). ```python # Deploy the variant to the staging environment -deployment = ag.DeploymentManager.deploy_variant( +deployment = ag.DeploymentManager.deploy( app_slug="my-app-slug", # app_id="my-app-id", # you can also use `app_id` variant_slug="my-variant-slug", @@ -193,6 +220,19 @@ deployment = ag.DeploymentManager.deploy_variant( print("Deployed variant to environment:") print(deployment) + +# Deploy the variant to the staging environment asynchronously (optional) +# async def deploy_variant(): +# deployment = await ag.DeploymentManager.adeploy( +# app_slug="my-app-slug", +# # app_id="my-app-id", # you can also use `app_id` +# variant_slug="my-variant-slug", +# variant_version=None, # Optional: If not provided, deploys the latest version +# environment_slug="staging" +# ) + +# print("Deployed variant to environment (async):") +# print(deployment) ``` :::warning @@ -269,24 +309,14 @@ print(config) ```python Fetched configuration: { - 'parameters': { - 'temperature': 1.0, - 'model': 'gpt-4', - 'max_tokens': 150, - 'prompt_system': 'You are an assistant that provides concise answers.', - 'prompt_user': 'Explain {topic} in simple terms.', - 'top_p': 1.0, - 'frequency_penalty': 0.0, - 'presence_penalty': 0.0 - } - 'app_id': 'my-app-id', - 'app_slug': 'my-app-slug', - 'variant_id': 'updated-variant-id', - 'variant_slug': 'my-variant-slug', - 'variant_version': 2, - 'committed_at': 'current-datetime', - 'committed_by': 'my-email-address', - 'committed_by_id': 'my-user-id', + 'temperature': 1.0, + 'model': 'gpt-4', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 } ``` @@ -309,42 +339,37 @@ print(config) ```python Fetched configuration from staging: { - 'parameters': { - 'temperature': 0.7, - 'model': 'gpt-3.5-turbo', - 'max_tokens': 150, - 'prompt_system': 'You are an assistant that provides concise answers.', - 'prompt_user': 'Explain {topic} in simple terms.', - 'top_p': 1.0, - 'frequency_penalty': 0.0, - 'presence_penalty': 0.0 - }, - 'app_id': 'my-app-id', - 'app_slug': 'my-app-slug', - 'variant_id': 'new-variant-id', - 'variant_slug': 'my-variant-slug', - 'variant_version': 1, - 'environment_id': 'staging-enviroment-id', - 'environment_slug': 'staging', - 'environment_version': 1, - 'deployed_at': 'current-datetime', - 'deployed_by': 'my-email-address', - 'deployed_by_id': 'my-user-id', + 'temperature': 0.7, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 } ``` ## Deleting a Variant -To delete a variant, use the `VariantManager.delete_variant` method. +To delete a variant, use the `VariantManager.delete` method. ```python # Delete a variant -ag.VariantManager.delete_variant( +ag.VariantManager.delete( app_slug="my-app", # app_id="my-app-id", # you can also use `app_id` variant_slug="obsolete-variant" ) +# Delete a variant asynchronously (optional) +# async def delete_variant(): +# versions = await ag.VariantManager.adelete( +# app_slug="my-app", +# # app_id="my-app-id", # you can also use `app_id` +# variant_slug="obsolete-variant", +# ) + print("Variant deleted successfully.") ``` @@ -356,11 +381,11 @@ print("Variant deleted successfully.") ## Listing All Variants -To list all variants of an application, use the `VariantManager.list_variants` method. +To list all variants of an application, use the `VariantManager.list` method. ```python -# List all variants -variants = ag.VariantManager.list_variants( +# List all variants (syncrhonously) +variants = ag.VariantManager.list( app_slug="my-app" # app_id="my-app-id", # you can also use `app_id` ) @@ -368,6 +393,17 @@ variants = ag.VariantManager.list_variants( print("List of variants:") for variant in variants: print(variant) + +# List all variants asynchronously (optional) +# async def list_variants(): +# variants = await ag.VariantManager.alist( +# app_slug="my-app" +# # app_id="my-app-id", # you can also use `app_id` +# ) + +# print("List of variants (async):") +# for variant in variants: +# print(variant) ``` **Sample Output:** @@ -418,18 +454,31 @@ List of variants: ## Fetching a Variant's history -To list all versions for a variant of an application, use the `VariantManager.list_variants` method. +To list all versions for a variant of an application, use the `VariantManager.list` method. ```python -# List all variants -variants = ag.VariantManager.list_variants( +# List all variant versions/history (synchronously) +versions = ag.VariantManager.history( + variant_slug="variant-slug", app_slug="my-app" # app_id="my-app-id", # you can also use `app_id` ) -print("List of variants:") -for variant in variants: - print(variant) +print("History of variant:") +for version in versions: + print(version) + +# List all variant versions/history asynchronously (optional) +# async def fetch_variant_history(): +# versions = await ag.VariantManager.ahistory( +# variant_slug="variant-slug", +# app_slug="my-app" +# # app_id="my-app-id", # you can also use `app_id` +# ) + +# print("History of variant:") +# for version in versions: +# print(version) ``` **Sample Output:** @@ -484,7 +533,7 @@ If your application uses asynchronous programming, you can use the async version ```python # Asynchronous fetching of configuration -config = await ag.ConfigManager.aget_from_registry( +config = await ag.ConfigManager.async_get_from_registry( app_slug="my-app", # app_id="my-app-id", # you can also use `app_id` variant_slug="my-variant-slug", diff --git a/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx b/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx index c009202c77..c5486eb831 100644 --- a/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx +++ b/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx @@ -46,7 +46,7 @@ We're going to create a new completion prompt called `topic-explainer`. [Todo: Image showing before and after. The new elements are added in different colors] -Variants are similar to branches in **git**. Any change to the prompt must first be committed to a variant. Here, we'll create a new variant and make our first commit to it using the `VariantManager.create_variant` method: +Variants are similar to branches in **git**. Any change to the prompt must first be committed to a variant. Here, we'll create a new variant and make our first commit to it using the `VariantManager.create` method: ```python @@ -56,14 +56,14 @@ from agenta import Prompt my_prompt = Prompt(temperature=0.6, model="gpt-3.5-turbo", max_tokens=150, - prompt=[{"role": "system", "content": "You are an assistant that provides concise answers"}, - {"role": "user", "content": "Explain {topic} in simple terms"}], + prompt_system="You are an assistant that provides concise answers", + prompt_user="Explain {topic} in simple terms", top_p=1.0, frequency_penalty=0.0, presence_penalty=0.0 ) # Create a new variant -variant = ag.VariantManager.create_variant( +variant = ag.VariantManager.create( app_slug="topic-explainer", variant_slug="new-variant", config_parameters=my_prompt.dict() @@ -85,21 +85,24 @@ This command will create a new variant and initialize it with the first commit c ```python Created variant: { - 'app_slug': 'topic-explainer', - 'variant_slug': 'new-variant', + 'parameters': { + 'temperature': 0.6, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'app_id': 'my-app-id', + 'app_slug': 'my-app-slug', + 'variant_id': 'new-variant-id', + 'variant_slug': 'my-variant-slug', 'variant_version': 1, - 'config': { - 'parameters': { - 'temperature': 0.7, - 'model': 'gpt-3.5-turbo', - 'max_tokens': 150, - 'prompt_system': 'You are an assistant that provides concise answers.', - 'prompt_user': 'Explain {topic} in simple terms.', - 'top_p': 1.0, - 'frequency_penalty': 0.0, - 'presence_penalty': 0.0 - }, - } + 'committed_at': 'current-datetime', + 'committed_by': 'my-email-address', + 'committed_by_id': 'my-user-id', } ``` @@ -107,11 +110,11 @@ Created variant: [Todo: Image showing before and after. The new elements are added in a different colors] -To deploy our commit to an environment, use the `DeploymentManager.deploy_variant` method. +To deploy our commit to an environment, use the `DeploymentManager.deploy` method. ```python # Deploy the variant to the production environment -deployment = ag.DeploymentManager.deploy_variant( +deployment = ag.DeploymentManager.deploy( app_slug="topic-explainer", variant_slug="new-variant", environment_slug="production", @@ -133,11 +136,27 @@ print(deployment) ```python Deployed variant to environment: { + 'parameters': { + 'temperature': 0.7, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'app_id': 'my-app-id', 'app_slug': 'topic-explainer', - 'variant_slug': 'new-variant', - 'variant_version': 1 + 'variant_id': 'new-variant-id', + 'variant_slug': 'my-variant-slug', + 'variant_version': 1, + 'environment_id': 'production-enviroment-id', 'environment_slug': 'production', - 'environment_version': 1 + 'environment_version': 1, + 'deployed_at': 'current-datetime', + 'deployed_by': 'my-email-address', + 'deployed_by_id': 'my-user-id', } ``` @@ -150,14 +169,15 @@ We're now going to commit changes to our variant. Note that this will not modify To save changes to a variant (creating a new version), we are goin to use the `VariantManager.commit_variant` method with explicit parameters. ```python -my_prompt2 = Prompt(temperature=0.6, - model="gpt-3.5-turbo", - max_tokens=150, - prompt=[{"role": "system", "content": "You are an assistant that provides concise answers"}, - {"role": "user", "content": "Use Paul Graham style to explain {topic} in simple terms."}], - top_p=1.0, - frequency_penalty=0.0, - presence_penalty=0.0 ) +my_prompt2 = Prompt( + temperature=0.9, + model="gpt-3.5-turbo", + max_tokens=150, + prompt_system="You are an assistant that provides concise answers", + prompt_user="Use Paul Graham style to explain {topic} in simple terms.", + top_p=1.0, + frequency_penalty=0.0, + presence_penalty=0.0 ) # Commit the new version @@ -180,21 +200,24 @@ Each commit creates a new version of the variant. Versions are immutable once cr ```python Committed new version of variant: { + 'parameters': { + 'temperature': 0.9, + 'model': 'gpt-3.5-turbo', + 'max_tokens': 150, + 'prompt_system': 'You are an assistant that provides concise answers.', + 'prompt_user': 'Use Paul Graham style to explain {topic} in simple terms.', + 'top_p': 1.0, + 'frequency_penalty': 0.0, + 'presence_penalty': 0.0 + }, + 'app_id': 'my-app-id', 'app_slug': 'topic-explainer', - 'variant_slug': 'new-variant', + 'variant_id': 'new-variant-id', + 'variant_slug': 'new-variant-slug', 'variant_version': 2, - 'config': { - 'parameters': { - 'temperature': 0.9, - 'model': 'gpt-3.5-turbo', - 'max_tokens': 150, - 'prompt_system': 'You are an assistant that provides concise answers.', - 'prompt_user': 'Use Paul Graham style to explain {topic} in simple terms.', - 'top_p': 1.0, - 'frequency_penalty': 0.0, - 'presence_penalty': 0.0 - } - } + 'committed_at': 'current-datetime', + 'committed_by': 'my-email-address', + 'committed_by_id': 'my-user-id', } ``` @@ -213,14 +236,14 @@ print("Fetched configuration from production:") print(config) client.completion( - model=myprompt.model, - messages=format_prompt(myprompt.prompt, topic), - temperature=myprompt.temperature, - max_tokens=myprompt.max_tokens, - top_p=myprompt.top_p, - frequency_penalty=myprompt.frequency_penalty, - presence_penalty=myprompt.presence_penalty, - ) + model=myprompt.model, + messages=format_prompt(myprompt.prompt, topic), + temperature=myprompt.temperature, + max_tokens=myprompt.max_tokens, + top_p=myprompt.top_p, + frequency_penalty=myprompt.frequency_penalty, + presence_penalty=myprompt.presence_penalty, +) ``` ## Next Steps From 037c9569a9236d1f91a9eec9bb40f6f8a318a22e Mon Sep 17 00:00:00 2001 From: Abraham 'Abram' Israel Date: Tue, 12 Nov 2024 09:38:36 +0100 Subject: [PATCH 11/16] minor refactor (docs): rename 'commit_variant' to 'commit' --- docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx b/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx index c5486eb831..b009dfcd2e 100644 --- a/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx +++ b/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx @@ -166,7 +166,7 @@ Deployed variant to environment: We're now going to commit changes to our variant. Note that this will not modify the version in deployment! -To save changes to a variant (creating a new version), we are goin to use the `VariantManager.commit_variant` method with explicit parameters. +To save changes to a variant (creating a new version), we are goin to use the `VariantManager.commit` method with explicit parameters. ```python my_prompt2 = Prompt( @@ -181,7 +181,7 @@ my_prompt2 = Prompt( # Commit the new version -variant = ag.VariantManager.commit_variant( +variant = ag.VariantManager.commit( app_slug="topic-explainer", variant_slug="new-variant", config_parameters=my_prompt2.dict() From 2477f46a02f3bd64915a3dab1811397f68fdfbd1 Mon Sep 17 00:00:00 2001 From: Abraham 'Abram' Israel Date: Tue, 12 Nov 2024 09:42:45 +0100 Subject: [PATCH 12/16] minor refactor (docs): add 'await' keyword to execute coroutines in VariantManager and DeploymentManager method(s) --- docs/docs/prompt-management/03-prompt-management-sdk.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/prompt-management/03-prompt-management-sdk.mdx b/docs/docs/prompt-management/03-prompt-management-sdk.mdx index 0b4c0e0871..221634ce58 100644 --- a/docs/docs/prompt-management/03-prompt-management-sdk.mdx +++ b/docs/docs/prompt-management/03-prompt-management-sdk.mdx @@ -90,7 +90,7 @@ print(variant) # Create a new version asynchronously (optional) # async def create_variant(): -# variant = ag.VariantManager.acreate( +# variant = await ag.VariantManager.acreate( # parameters=my_prompt.model_dump(), # app_slug="my-app-slug", # app_id="my-app-id", # you can also use `app_id` @@ -164,7 +164,7 @@ print(variant) # Commit the new version asynchronously (optional) # async def commit_variant(): -# variant = ag.VariantManager.acommit( +# variant = await ag.VariantManager.acommit( # parameters=my_prompt2.model_dump(), # app_slug="my-app-slug", # variant_slug="my-variant-slug", From c812422efd7e43b993f5a22952f1e1f80574ab6d Mon Sep 17 00:00:00 2001 From: Abraham 'Abram' Israel Date: Tue, 12 Nov 2024 11:08:50 +0100 Subject: [PATCH 13/16] refactor (docs): update async method naming in config manager for consistency across manager methods --- agenta-cli/agenta/sdk/managers/config_manager.py | 4 ++-- docs/docs/prompt-management/02-quick-start.mdx | 2 +- docs/docs/prompt-management/03-prompt-management-sdk.mdx | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/agenta-cli/agenta/sdk/managers/config_manager.py b/agenta-cli/agenta/sdk/managers/config_manager.py index 8e5e4aadd5..a58ddb94f1 100644 --- a/agenta-cli/agenta/sdk/managers/config_manager.py +++ b/agenta-cli/agenta/sdk/managers/config_manager.py @@ -93,7 +93,7 @@ def get_from_route( return parameters @staticmethod - async def async_get_from_route( + async def aget_from_route( schema: Optional[Type[T]] = None, ) -> Union[Dict[str, Any], T]: """ @@ -214,7 +214,7 @@ def get_from_registry( return config.parameters @staticmethod - async def async_get_from_registry( + async def aget_from_registry( schema: Optional[Type[T]] = None, # app_id: Optional[str] = None, diff --git a/docs/docs/prompt-management/02-quick-start.mdx b/docs/docs/prompt-management/02-quick-start.mdx index bda5a2c186..6e62c3bf1f 100644 --- a/docs/docs/prompt-management/02-quick-start.mdx +++ b/docs/docs/prompt-management/02-quick-start.mdx @@ -145,7 +145,7 @@ If your application is asynchronous, you can use the async version of the method ```python # Asynchronous fetching of configuration -config = await ag.ConfigManager.async_get_from_registry( +config = await ag.ConfigManager.aget_from_registry( app_slug="your-app-slug" ) ``` diff --git a/docs/docs/prompt-management/03-prompt-management-sdk.mdx b/docs/docs/prompt-management/03-prompt-management-sdk.mdx index 221634ce58..e0bbb18565 100644 --- a/docs/docs/prompt-management/03-prompt-management-sdk.mdx +++ b/docs/docs/prompt-management/03-prompt-management-sdk.mdx @@ -484,7 +484,7 @@ for version in versions: **Sample Output:** ```python -List of variants: +History of variants: { 'parameters': { 'temperature': 1.0, @@ -533,7 +533,7 @@ If your application uses asynchronous programming, you can use the async version ```python # Asynchronous fetching of configuration -config = await ag.ConfigManager.async_get_from_registry( +config = await ag.ConfigManager.aget_from_registry( app_slug="my-app", # app_id="my-app-id", # you can also use `app_id` variant_slug="my-variant-slug", From 064aaa5fc7a0e0b190bff87aba3d73f43bbf0e2d Mon Sep 17 00:00:00 2001 From: Abraham 'Abram' Israel Date: Tue, 12 Nov 2024 11:11:09 +0100 Subject: [PATCH 14/16] fix (tests): resolve failing sdk tests --- agenta-cli/agenta/tests/prompt_sdk/test_config_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-cli/agenta/tests/prompt_sdk/test_config_manager.py b/agenta-cli/agenta/tests/prompt_sdk/test_config_manager.py index 778366800b..21febee154 100644 --- a/agenta-cli/agenta/tests/prompt_sdk/test_config_manager.py +++ b/agenta-cli/agenta/tests/prompt_sdk/test_config_manager.py @@ -151,7 +151,7 @@ async def test_afetch_configuration_and_return_dict(mock_aget_config): "max_tokens": 100, } - config = await ConfigManager.async_get_from_registry( + config = await ConfigManager.aget_from_registry( app_slug="my-app", variant_slug="new-variant", variant_version=2 ) @@ -169,7 +169,7 @@ async def test_afetch_configuration_and_return_schema(mock_aget_config): temperature=0.9, model="gpt-3.5-turbo", max_tokens=100 ) - config_as_schema = await ConfigManager.async_get_from_registry( + config_as_schema = await ConfigManager.aget_from_registry( schema=Parameters, app_slug="my-app", variant_slug="new-variant", From a13becca39f43d135ed56bef715aacfc855bd719 Mon Sep 17 00:00:00 2001 From: Abraham 'Abram' Israel Date: Tue, 12 Nov 2024 11:20:16 +0100 Subject: [PATCH 15/16] fix (cli:tests): resolve failing patched ConfigManager method --- agenta-cli/agenta/tests/prompt_sdk/test_config_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agenta-cli/agenta/tests/prompt_sdk/test_config_manager.py b/agenta-cli/agenta/tests/prompt_sdk/test_config_manager.py index 21febee154..ef99baf08d 100644 --- a/agenta-cli/agenta/tests/prompt_sdk/test_config_manager.py +++ b/agenta-cli/agenta/tests/prompt_sdk/test_config_manager.py @@ -141,7 +141,7 @@ def test_fetch_configuration_and_return_schema(mock_get_config): @pytest.mark.asyncio -@patch("agenta.ConfigManager.async_get_from_registry") +@patch("agenta.ConfigManager.aget_from_registry") async def test_afetch_configuration_and_return_dict(mock_aget_config): # Mock the API response for fetching configuration @@ -161,7 +161,7 @@ async def test_afetch_configuration_and_return_dict(mock_aget_config): @pytest.mark.asyncio -@patch("agenta.ConfigManager.async_get_from_registry") +@patch("agenta.ConfigManager.aget_from_registry") async def test_afetch_configuration_and_return_schema(mock_aget_config): # Mock the API response for fetching configuration From f664ae1e6a7e037d721add2513e3ae1fe7528f3e Mon Sep 17 00:00:00 2001 From: Abraham 'Abram' Israel Date: Tue, 12 Nov 2024 14:03:45 +0100 Subject: [PATCH 16/16] minor refactor (docs): update code example in 'fetching the prompt in production' section --- docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx b/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx index b009dfcd2e..7f72e71826 100644 --- a/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx +++ b/docs/docs/tutorials/sdk/manage-prompts-with-SDK.mdx @@ -231,7 +231,7 @@ config = ag.ConfigManager.get_from_registry( app_slug="topic-explainer", environment_slug="production" ) -myprompt = Prompt(config.parameters) +myprompt = Prompt(config) print("Fetched configuration from production:") print(config)