-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,5 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
plvenv |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from promptlayer.promptlayer import PromptLayer | ||
import openai | ||
import os | ||
|
||
api_key = os.environ.get("PROMPTLAYER_API_KEY") | ||
openai = PromptLayer(openai, function_name='openai') | ||
|
||
|
||
__all__ = [ | ||
"api_key", | ||
"openai", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import requests | ||
|
||
class PromptLayer(object): | ||
__slots__ = ["_obj", "__weakref__", "_function_name"] | ||
def __init__(self, obj, function_name=''): | ||
object.__setattr__(self, "_obj", obj) | ||
object.__setattr__(self, "_function_name", function_name) | ||
|
||
def __getattr__(self, name): | ||
return PromptLayer(getattr(object.__getattribute__(self, "_obj"), name), function_name=f'{object.__getattribute__(self, "_function_name")}.{name}') | ||
|
||
def __delattr__(self, name): | ||
delattr(object.__getattribute__(self, "_obj"), name) | ||
|
||
def __setattr__(self, name, value): | ||
setattr(object.__getattribute__(self, "_obj"), name, value) | ||
|
||
def __call__(self, *args, **kwargs): | ||
from promptlayer.utils import get_api_key | ||
# response = object.__getattribute__(self, "_obj")(*args, **kwargs) | ||
response = None | ||
requests.post("https://api.promptlayer.com/track", | ||
headers = { | ||
"Authorization": f"Bearer {get_api_key()}" | ||
}, | ||
data={ | ||
"function_name": object.__getattribute__(self, "_function_name"), | ||
"args": args, | ||
"kwargs": kwargs, | ||
"response": response | ||
} | ||
) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import promptlayer | ||
|
||
def get_api_key(): | ||
# raise an error if the api key is not set | ||
if promptlayer.api_key is None: | ||
raise Exception("Please set your PROMPTLAYER_API_KEY environment variable or set API KEY in code using 'promptlayer.api_key = <your_api_key>' ") | ||
else: | ||
return promptlayer.api_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from setuptools import find_packages, setup | ||
|
||
setup( | ||
name="promptlayer", | ||
description="PromptLayer is a package to keep track of your LM models training", | ||
author_email="[email protected]", | ||
url="https://www.magniv.io", | ||
project_urls={ | ||
"Documentation": "https://docs.magniv.io", | ||
}, | ||
version="0.1.0", | ||
py_modules=["promptlayer"], | ||
packages=find_packages(), | ||
install_requires=["requests", "openai"], | ||
) |