Introduction to PromptLayer Library
PromptLayer is a groundbreaking platform crafted specifically for prompt engineers who work with OpenAI's GPT models. As the first platform of its kind, it optimally tracks, manages, and shares GPT prompt engineering efforts. This tool acts as a middleware, seamlessly integrating with the user's code and OpenAI's Python library, which ensures all API requests made through OpenAI are logged and can be explored via the PromptLayer dashboard.
Key Features of PromptLayer
-
Tracking and Managing Requests: PromptLayer records all API requests to OpenAI, allowing users to search through their request history. This can be particularly helpful to revisit and analyze previous prompts or patterns.
-
Easy Integration: By introducing a single library, PromptLayer requires minimal code changes to enable its capabilities. Developers continue their work with OpenAI as usual, but with an added layer of logging and management.
Installation and Setup
Installing PromptLayer
To start using PromptLayer, users simply need to install it via pip:
pip install promptlayer
For local installations, the command is slightly different:
pip install .
Getting Started
First, users must create an account on the PromptLayer website and generate an API key. This key is necessary for the library to operate but is never sent to PromptLayer's servers, ensuring privacy and security.
Integrating PromptLayer into a project involves adding just a few lines of code. Import and initialize PromptLayer and OpenAI as shown:
from promptlayer import PromptLayer
promptlayer = PromptLayer(api_key="<YOUR PromptLayer API KEY pl_xxxxxx>")
openai = promptlayer.openai
After this setup, users can use the openai
object as if they imported it directly from the OpenAI library.
Enhanced Features with pl_tags
PromptLayer also enables users to tag their requests with pl_tags
. This optional feature allows users to label and categorize prompts to efficiently organize and track them within the dashboard. Although not mandatory, tagging enhances the management process by grouping similar requests.
Example usage with tags:
openai.Completion.create(
engine="text-ada-001",
prompt="My name is",
pl_tags=["name-guessing", "pipeline-2"]
)
Accessing via REST API
Apart from the Python library, PromptLayer's services are available through a REST API, making it versatile across different programming languages like Javascript. This widens its accessibility for developers not tied to Python.
Here’s an example of how one might send a request using the REST API:
import requests
request_response = requests.post(
"https://api.promptlayer.com/track-request",
json={
"function_name": "openai.Completion.create",
"args": [],
"kwargs": {"engine": "text-ada-001", "prompt": "My name is"},
"tags": ["hello", "world"],
"request_response": {"id": "cmpl-6TEeJCRVlqQSQqhD8CYKd1HdCcFxM", "object": "text_completion", "created": 1672425843, "model": "text-ada-001", "choices": [{"text": " advocacy\"\n\nMy name is advocacy.", "index": 0, "logprobs": None, "finish_reason": "stop"}]},
"request_start_time": 1673987077.463504,
"request_end_time": 1673987077.463504,
"api_key": "pl_<YOUR API KEY>",
},
)
Open Source Contributions
PromptLayer encourages contributions to its open-source project. Whether it's for developing new features, enhancing infrastructure, or bettering documentation, the project welcomes collaborators. Queries or contributions can be directed to their team at [email protected].
PromptLayer represents a significant step forward for prompt engineers, offering a robust set of tools to efficiently track and manage their OpenAI projects while ensuring seamless integration and privacy.