Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add templates module and update version #98

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions promptlayer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

from promptlayer.promptlayer import PromptLayerBase

from . import templates

api_key = os.environ.get("PROMPTLAYER_API_KEY")


def __getattr__(
name: Union[Literal["openai"], Literal["anthropic"], Literal["prompts"]]
name: Union[Literal["openai"], Literal["anthropic"], Literal["prompts"]],
):
if name == "openai":
import openai as openai_module
Expand Down Expand Up @@ -39,4 +41,4 @@ def __getattr__(
raise AttributeError(f"module {__name__} has no attribute {name}")


__all__ = ["api_key", "openai", "anthropic"]
__all__ = ["api_key", "openai", "anthropic", "templates"]
14 changes: 14 additions & 0 deletions promptlayer/templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Dict, Union

from promptlayer.utils import get_prompt_template


def get(
*,
prompt_name: str,
provider: Union[str, None] = None,
input_variables: Dict[str, str] = {},
):
return get_prompt_template(
prompt_name=prompt_name, provider=provider, input_variables=input_variables
)
27 changes: 27 additions & 0 deletions promptlayer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import types
from copy import deepcopy
from typing import Dict, Union

import requests

Expand Down Expand Up @@ -514,3 +515,29 @@ def promptlayer_track_group(request_id, group_id):
raise Exception(
f"PromptLayer had the following error while tracking your group: {e}"
)


def get_prompt_template(
*,
prompt_name: str,
provider: Union[str, None] = None,
input_variables: Dict[str, str] = {},
):
try:
response = requests.get(
f"{URL_API_PROMPTLAYER}/prompt-templates/{prompt_name}",
headers={"X-API-KEY": get_api_key()},
params={
"provider": provider,
"input_variables": json.dumps(input_variables),
},
)
if response.status_code != 200:
raise Exception(
f"PromptLayer had the following error while getting your prompt template: {response.text}"
)
return response.json()
except requests.exceptions.RequestException as e:
raise Exception(
f"PromptLayer had the following error while getting your prompt template: {e}"
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "promptlayer"
version = "0.4.0"
version = "0.4.1"
description = "PromptLayer is a platform for prompt engineering and tracks your LLM requests."
authors = ["Magniv <[email protected]>"]
license = "Apache-2.0"
Expand Down