Package: powerml-app
PowerML Python PackageRequirementsPython 3.7, 3.8, 3.9, or 3.10. Check your version usingpython --versionorpython3 --version.Installationpip install powerml_appAuthenticationYou will need a PowerML key. To get a PowerML key, go tohttps://powerml.co/and log in with your email. Contact our team if you are unable to log in and we'll add you!Quick StartCreate a python file (e.g.powerml_test.py) with this starter code and run a prediction (e.g.python powerml_test.py)!from powerml import PowerML
config = {"powerml": {"key": "<POWERML-KEY>"}}
powerml = PowerML(config)

# Run base model
myPrompt = "hello there" # Change me and see what I can do!
response = powerml.predict(prompt=myPrompt)
print(response)ConfigurationYou configure thePowerMLclass by passing in a dictionary like so:from powerml import PowerML
config = {"powerml": {"key": "<POWERML-KEY>"}}
powerml = PowerML(config)Optional: Create a config file at~/.powerml/configure.yamlwith your PowerML key. Here's an example:powerml:
    key: "<POWERML-KEY>"These are default keys for thePowerMLclass but will be overriden by any configuration dictionary passed into the class constructor.UsageYou can use the member functions of the PowerML class,predictandfit, to make predictions with the model and fit data to the model to improve and customize it.You can usepredictto run any prompt off the bat:from powerml import PowerML

powerml = PowerML()

# Run base model
myPrompt = "hello there"
response = powerml.predict(prompt=myPrompt)To fit data to the model, you can usefitas so:# Fit model to data
myData = ["item2", "item3"]
myModel = powerml.fit(myData)To run this fitted model, you can usepredictagain, specifying the new model name:# Use new model
myModelName = myModel["model_name"]
response = powerml.predict(prompt=myPrompt, model=myModelName)PowerML ClassThePowerMLclass has member functionsfitandpredict.Predictpredictaccepts the following arguments:def predict(self,
            prompt: str,
            model: str = "text-davinci-003",
            stop: str = "",
            max_tokens: int = 128,
            temperature: int = 0,
            ) -> str:predictwill return a string of the model's output.fitaccepts the following arguments:def fit(self,
        data: list[str],
        model: str = ""):fitwill 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"
    }
}ExtractTopicsModel ClassTheExtractTopicsModelclass is an example class designed to extract topics from the prompt.UsageTo instantiate aExtractTopicsModel.model = ExtractTopicsModel(topics)To customize yourExtractTopicsModelinstance, you can pass it examples and topics to fit.# Examples in json for the model to fit to, in the format:
# [
#    { "example": "Using VS here for my IDE", labels: ["vscode"] },
#    { "example": "A dashboard on Chrome", labels: ["web", "dashboard"] },
# ]
examples = get_json_examples()

# Topics, e.g. ["vscode", "web", "dashboard"]
topics = get_list_of_topics()

model.fit(examples, topics)Now, you can run this model on new examples withpredict:new_example = "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)"

example_topics = model.predict(new_example)Methods__init__is defined as follows:def __init__(self, config={}, model_name=None):fitis defined as follows:def fit(self, 
        examples: list[
            {"example": str, "labels": list[str]}
        ],
        topics: list[str],
        ):where examples is a list of dictionaries with format{"example": str, "labels": list[str]}.predictis defined as follows:def predict(self, prompt: str):CreateTopicsModel ClassTheCreateTopicsModelclass is an example class designed to generate topics from a list of data. This is a batch process and may take a few minutes.Usagedocs = get_list_of_data()
learn_topics = CreateTopicsModel()
learn_topics.fit(docs, topic_type='one-word system components')
topics = learn_topics.predict()Usage withExtractTopicsModelTopics can be learned byCreateTopicsModel, then used inExtractTopicsModel.First, get topics fromCreateTopicsModel:docs = get_list_of_data()
learn_topics = CreateTopicsModel()
learn_topics.fit(docs, topic_type='one-word system components')
topics = learn_topics.predict()Then, useExtractTopicsModelas you normally would (as above) to fit it to examples, and then predict on new examples:topic_model = ExtractTopicsModel()
labeled_data = get_formatted_examples()
topic_model.fit(labeled_data, topics)

new_example = "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)"
new_example_topics = topic_model.predict(new_example)Methods__init__is defined as follows:def __init__(
        self,
        config={},
        max_output_tokens=256,):fitis defined as follows:def fit(self, documents: Dict[str,str], topic_type: str):where documents is a list of strings.predictis defined as follows:def predict(self):and returns a list of dictionaries with format{"name": str, “score”: float, "keywords": list[str]}.SummarizeTopicModel ClassTheSummarizeTopicModelclass is an example class designed to generate topics from a list of data. This is a batch process and may take a few minutes.Usagemodel = SummarizeTopicModel()
summary = model.predict(topic_name, documents)Methods__init__is defined as follows:def __init__(
        self,
        config={},):predictis defined as follows:def predict(self, topic: str, documents: List[str],) -> str:and returns a string summary of the topic, using the documents provided.WriteEmailModel ClassTheWriteEmailModelclass is an example class designed to generate emails from a subject.Usagemodel = WriteEmailModel()
email = model.predict("Toys'r'Us")ExtractMenuItemsModel ClassTheExtractMenuItemsModelclass is an example class designed to generate orders from a conversation.Usagemodel = ExtractMenuItemsModel()
items = model.predict("1 Chicken Burrito")ForecastSequenceModel ClassTheForecastSequenceModelclass is an example class designed to generate a numeric sequence from a title.Usagemodel = ForecastSequenceModel()
autocompletion = model.predict("Freakonomics Radio")AutocompleteSQLModel ClassTheAutocompleteSQLModelclass is an example class designed to generate sql completions from a prompt.Usagemodel = AutocompleteSQLModel()
model.fit(
    table_schemas=[
        "CREATE TABLE users ( id SERIAL PRIMARY KEY, first_name TEXT, last_name TEXT);"
    ],
    example_queries=[
        "SELECT * FROM users WHERE id=?"
    ])
autocompletion = model.predict("select * from ")QuestionAnswerModel ClassTheQuestionAnswerModelclass is an example class designed to generate questions from study material.Usagemodel = QuestionAnswerModel()
note = "Greek Philosophy"
examples = [
    {'note': note,
    'questions': [{'Q': "Who said 'The only true wisdom is in knowing you know nothing.'", 'A': 'Socrates'},
    {'Q': "Who said 'I am the wisest man alive, for I know one thing, and that is that I know nothing.'", 'A': 'Socrates'}]}
]
model.fit(examples)
num_questions = 1
question_and_answer = model.predict(note, num_questions)