Skip to main content

A Python SDK for interacting with PromptGround API.

Project description

PromptGround SDK

A simple Python SDK for interacting with the PromptGround API.

Installation

Install the SDK using pip:

pip install promptground

Usage

Running a Prompt

To run a prompt and get the result, use the run method:

from promptground.PromptGround import PromptGround

# Initialize the PromptGround object
pg = PromptGround(api_key="YOUR API KEY")

# Run a prompt
result = pg.run(
    alias='Typo-grammar fixer', 
    data={
        'text': 'this text explaining promptground but is not grammatically correct'
    }
)
print(result.content)  # Outputs the corrected text
print(result.usage)    # Outputs the usage details

Understanding the Response Object

The run method returns a PromptRunResult object with the following attributes:

  • content (str): The actual output of the prompt.
  • usage (dict): The usage details which include:
    • completion_tokens (int): The number of tokens in the output.
    • prompt_tokens (int): The number of tokens in the input.
    • total_tokens (int): The total number of tokens (input + output).

Example:

# Example response handling
print("Content:", result.content)  # The corrected text
print("Usage:", result.usage)      # The usage details

Fetching Messages

If you want to fetch only the messages and run the prompt on your side, you can use the messages method:

# Fetch messages
messages = pg.messages(
    alias='Typo-grammar fixer',
    data={
        'text': 'this text explaining promptground but is not grammatically correct'
    }
)
print(messages)  # Outputs a list of messages

Methods

messages(alias, data={}, version=None)

Fetch messages from the PromptGround API.

Parameters:

  • alias (str): The prompt alias as seen on your dashboard.
  • data (dict, optional): A flat object with key=value pairs used to substitute variables in the messages.
  • version (str, optional): The specific prompt version ID to call. If not provided, the most recent prompt version will be used.

Returns:

  • list: A list of messages. Each message is a dictionary with content and role. For example, [{content: "message content", role: "system"}]. The role can be system, user, or assistant.

run(alias, data={}, metadata={}, labels=[], model=None, version=None, response_format=None)

Run a prompt and return the result.

Parameters:

  • alias (str): The prompt alias as seen on your dashboard.
  • data (dict, optional): A flat object with key=value pairs used to substitute variables in the messages.
  • metadata (dict, optional): Additional data to help you filter in the "Runs" dashboard. It should be a flat key-value object.
  • labels (list, optional): An array for distinguishing different prompts and filtering them afterward in the "Runs" dashboard.
  • model (str, optional): The model to use for the prompt. If not provided, the most recent model will be used.
  • version (str, optional): The specific prompt version ID to call. If not provided, the most recent prompt version will be used.
  • response_format (str, optional): The response format for the prompt (e.g. json_object).

Returns:

  • PromptRunResult: The result of running the prompt.

Handling Results

The result of the run method is a PromptRunResult object with the following attributes:

  • content (str): The actual output.
  • usage (dict): The token usage details, which include:
    • completion_tokens (int): The number of tokens in the output.
    • prompt_tokens (int): The number of tokens in the input.
    • total_tokens (int): The total number of tokens (input + output).

Exception Handling

Both messages and run methods will raise an Exception if there is an error with the API request. Be sure to handle these exceptions appropriately in your application.

Contributions

If something is missing or you have any suggestions, please create an issue or open a pull request. For any questions or support, feel free to contact us.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

promptground-1.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

promptground-1.1.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file promptground-1.1.1.tar.gz.

File metadata

  • Download URL: promptground-1.1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/42.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/1.26.18 tqdm/4.66.2 importlib-metadata/6.8.0 keyring/24.3.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.10.9

File hashes

Hashes for promptground-1.1.1.tar.gz
Algorithm Hash digest
SHA256 49b0f30fa333392de6b7203bc01fdbeaf1e469ca8071f19c603f5a7aa074ed6f
MD5 946f6fc54021a50ff06fa82b36eabf98
BLAKE2b-256 2a03daafb7486f19a4447abc6c2e1e135a4ea2bc2517553ceb1afa0b162005ba

See more details on using hashes here.

File details

Details for the file promptground-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: promptground-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/42.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/1.26.18 tqdm/4.66.2 importlib-metadata/6.8.0 keyring/24.3.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.10.9

File hashes

Hashes for promptground-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6087c5538989d198cb723ceaabb0f6a979fe384e7f557b7aa691e93bcac3451
MD5 08d798cfc5fd93257bca0f81c4e4a0c0
BLAKE2b-256 d5c9d87f9b34b87c2901feeb0002822e2d8fd429e21a7297d3201736af7b97ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page