Skip to main content

PowerML python package

Reason this release was yanked:

Please install most recent version

Project description

PowerML Python Package

Installation

pip install powerml_app

Configure

In order to use this library, first create a config file at ~/.powerml/configure.yaml. Here's an example:

powerml:
    key: "<POWERML-KEY>"
openai:
    key: "<OPENAI-KEY>"

You may also configure the PowerML class by passing in a dictionary with the following specified format

from powerml import PowerML
config = {"powerml": {"key": "<POWERML-KEY>"}}
powerml = PowerML(config)

PowerML Key

To get a powerml key, go to https://staging.powerml.co/ and log in with your email. Contact our team if you are unable to log in and we'll add you!

Usage

How to use:

After configuring PowerML, we can use its member functions fit and predict

from powerml import PowerML
config = {"powerml": {"key": "<POWERML-KEY>"}}
powerml = PowerML(config)

testPrompt = "hello there"
response = powerml.predict(prompt=testPrompt)
data = ["item2", "item3"]
model_details = powerml.fit(data)

You may further calibrate any model using PowerML.fit

model_details = powerml.fit(data, model="<MODEL_NAME>")

Currently the default model is openai's text-davinci-003.

Fit

fit will return a dictionary object in the following format:

{
    "model_id":"23",
    "project_id":"None",
    "user_id":"12",
    "job_id":"89",
    "model_name":"be894276039088c5f8db3f6bfaeb19953ed9ffe55f37a847a58f9fb320d307bc",
    "job_config":"{\"type\": \"prompt_tune\", \"model_name\": \"llama\"}",
    "prompt":"item2item3{{input}}",
    "creation_time":"2022-12-20 02:19:36.519260",
    "job":{
        "job_id":"89",
        "project_id":"None",
        "user_id":"12",
        "config":"{\"type\": \"prompt_tune\", \"model_name\": \"llama\"}",
        "status":"COMPLETED",
        "name":"be894276039088c5f8db3f6bfaeb19953ed9ffe55f37a847a58f9fb320d307bc",
        "metric":"None",
        "history":"None",
        "start_time":"2022-12-20 02:19:36.369450",
        "end_time":"2022-12-20 02:19:35.837668"
    }
}

Predict

In the dictionary object returned from Powerml.fit, model_name is the name of your newly fit model. The PowerML class will immediately start using this model in predictions, so all you need to do now is to call predict:

response = powerml.predict("test")

Alternatively, you may use any model of a model you've trained before

response = powerml.predict("test", model="<MODEL_NAME>")

Currently the default model is openai's text-davinci-003.

PowerML Class

The PowerML class has member functions fit and predict.

predict accepts the following arguments:

def predict(self,
            prompt: str,
            model: str = "",
            stop: str = "",
            max_tokens: int = 128,
            temperature: int = 0,
            ) -> str:

fit accepts the following arguments:

def fit(self,
        data: list[str],
        model: str = ""):

PowerMLTopicModel Class

The PowerMLTopicModel class is an example class designed to extract topics from the prompt.

Usage

def get_examples():
    examples_path = os.path.join(os.path.dirname(__file__), "examples.json")
    with open(examples_path) as examples_file:
        examples = json.load(examples_file)
    return examples

def get_topics():
    return ["vscode","web","dashboard"]

config = {"powerml": {"key": "<POWERML-KEY>"}}
model = PowerMLTopicModel(get_topics(), config)
examples = get_examples()
model.fit(examples)
topics = model.predict("Move invite teammates page to its own base route . per designs:   This PR just moves existing views around and adds a new base route (i.e. no new functionality)")
print("topics:", topics)

Methods

__init__ is defined as follows:

def __init__(self, topics: list[str], config={}):

fit is defined as follows:

def fit(self, 
        examples: list[
            {"example": str, "labels": list[str]}
        ]):

where examples is a list of dictionaries with format {"example": str, "labels": list[str]}.

predict is defined as follows:

def predict(self, prompt: str):

PowerMLLearnTopics Class

The PowerMLLearnTopics class is an example class designed to generate topics from a list of documents.

Usage

def preprocess_data_into_messages(data):
    data = data.split('\n')
    return [d for d in data if d]

with open('data.txt', 'r') as f:
    data = f.read()
docs = preprocess_data_into_messages(data)
model = PowerMLLearnTopics()
model.add_data(docs)

topics = model.get_topics()
print(topics)

Methods

__init__ is defined as follows:

def __init__(self, config={}, num_subsamples=100, sample_size=50):

add_data is defined as follows:

def add_data(self, documents):

where documents is a list of strings.

get_topics is defined as follows:

def get_topics(self):

and returns a set of strings

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

powerml_app-0.0.17.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

powerml_app-0.0.17-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file powerml_app-0.0.17.tar.gz.

File metadata

  • Download URL: powerml_app-0.0.17.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for powerml_app-0.0.17.tar.gz
Algorithm Hash digest
SHA256 0d7756a878c863e9bca0f9dfb1eee9a8d1d9d8126a256cb576f86222378bc20f
MD5 548b5a244daa179ff8b47ee08c2e8bff
BLAKE2b-256 80908148659ee4901e7a4e0fd55d85c770d566b4fc1c78d0e7b86e611af1fafe

See more details on using hashes here.

File details

Details for the file powerml_app-0.0.17-py3-none-any.whl.

File metadata

  • Download URL: powerml_app-0.0.17-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for powerml_app-0.0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 0a0c9c7ff9d974e761cf5ffe04ce0607f78f7d8ec3ef4c26a699d0ede211854a
MD5 b1e7446b6aae6aada7f36f1a94918867
BLAKE2b-256 639145d6f163e7007c554cfa37a67dfcf3961475594789cf4e10aa8d2eba1145

See more details on using hashes here.

Supported by

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