> ## Documentation Index
> Fetch the complete documentation index at: https://docs.autoblocks.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK Reference

> Reference documentation for the Autoblocks Python Prompt SDK, including the AutoblocksPromptManager and PromptExecutionContext classes.

# Python Prompt SDK Reference

## `AutoblocksPromptManager`

This is the base class the autogenerated prompt manager classes inherit from.
Below are the arguments that can be passed when initializing a prompt manager:

| name               | required | default                                      | description                                                                                                                                                                                                                              |
| ------------------ | -------- | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `major_version`    | true     |                                              | The major version of the prompt to use. Can be a specific version number or "undeployed" for local development.                                                                                                                          |
| `minor_version`    | true     |                                              | Can be one of: a specific minor version or "latest"                                                                                                                                                                                      |
| `api_key`          | false    | `AUTOBLOCKS_V2_API_KEY` environment variable | Your Autoblocks API key.                                                                                                                                                                                                                 |
| `refresh_interval` | false    | `timedelta(seconds=10)`                      | How often to refresh the latest prompt. Only relevant if the minor version is set to `"latest"` or `"latest"` is used in the weighted list.                                                                                              |
| `refresh_timeout`  | false    | `timedelta(seconds=30)`                      | How long to wait for the latest prompt to refresh before timing out. A refresh timeout will not raise an uncaught exception. An error will be logged and the background refresh process will continue to run at its configured interval. |
| `init_timeout`     | false    | `timedelta(seconds=30)`                      | How long to wait for the prompt manager to be ready before timing out.                                                                                                                                                                   |

<CodeGroup>
  ```python specific minor version
  from my_project.autoblocks_prompts import my_app

  mgr = my_app.text_summarization_prompt_manager(
    major_version="1",
    minor_version="0",
  )
  ```

  ```python latest minor version
  from my_project.autoblocks_prompts import my_app

  mgr = my_app.text_summarization_prompt_manager(
    major_version="1",
    minor_version="latest",
  )
  ```
</CodeGroup>

### `exec`

A [context manager](https://docs.python.org/3/reference/datamodel.html#context-managers) that starts a prompt execution context by creating a new
[`PromptExecutionContext`](#prompt-execution-context) instance.

```python
with mgr.exec() as prompt:
    ...
```

## `PromptExecutionContext`

An instance of this class is created every time a new execution context is started with the `exec` context manager.
It contains a frozen copy of the prompt manager's in-memory prompt at the time `exec` was called.
This ensures the prompt is stable for the duration of an execution, even if the in-memory prompt on the manager
instance is refreshed mid-execution.

### `params`

A `pydantic` model instance with the prompt's parameters.

```python
with mgr.exec() as prompt:
    params = dict(
        model=prompt.params.model,
        temperature=prompt.params.temperature,
        ...
    )
```

### `render_template`

The `render_template` attribute contains an instance of a class that has methods for rendering each of the prompt's templates.
The template IDs and template parameters are all converted to snake case so that the method and argument names follow
Python naming conventions.

For example, the prompt in the [quick start](./quick-start) guide contains the below templates:

#### `system`

```
Objective: You are provided with a document...

{{ languageRequirement }}
{{ toneRequirement }}
```

#### `user`

```
Document:

'''
{{ document }}
'''

Summary:
```

#### `util/language`

```
Always respond in {{ language }}.
```

#### `util/tone`

```
Always respond in a {{ tone }} tone.
```

From this, the CLI autogenerates a class with the following methods:

```python
def system(
    self,
    *,
    language_requirement: str,
    tone_requirement: str,
) -> str:
    ...

def user(self, *, document: str) -> str:
    ...

def util_language(self, *, language: str) -> str:
    ...

def util_tone(self, *, tone: str) -> str:
    ...
```

As a result, you are able to render your templates with functions that are aware of the required parameters for each template:

```python
with mgr.exec() as prompt:
    params = dict(
        model=prompt.params.model,
        temperature=prompt.params.temperature,
        max_tokens=prompt.params.max_tokens,
        messages=[
            dict(
                role="system",
                content=prompt.render_template.system(
                    language_requirement=prompt.render_template.util_language(
                        language="Spanish",
                    ),
                    tone_requirement=prompt.render_template.util_tone(
                        tone="formal",
                    ),
                ),
            ),
            dict(
                role="user",
                content=prompt.render_template.user(
                  document="mock document",
                ),
            ),
        ],
    )
```

### `render_tool`

The `render_tool` attribute contains an instance of a class that has methods for rendering each of the prompt's tools.
The tool names and tool parameters are all converted to snake case so that the method and argument names follow
Python naming conventions. The tool will be in the JSON schema format that OpenAI expects.

```python
with mgr.exec() as prompt:
    params = dict(
        model=prompt.params.model,
        temperature=prompt.params.temperature,
        max_tokens=prompt.params.max_tokens,
        tools=[
            prompt.render_tool.my_tool(
                description="My description"
            ),
        ]
       # rest of params...
    )
```
