Skip to main content

Build on large language models faster

Project description

Llama

Stop prompt tuning. Create your own Generative AI.

Installation

    pip install llama-llm

Setup your keys

Go to powerml.co. Log in to get you API key and purchase credits.

Create ~/.powerml/configure_llama.yaml and put a key in it.

production:
    key: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

Define the LLM interface

Define the input and output types. Don't forget the context. They help the LLM understand the data.

class Tweet(Type):
    tweet: str = Context("a viral tweet")
    likes: int = Context("likes the tweet gets")
    retweets: int = Context("retweets the tweet gets")


class User(Type):
    username: str = Context("a user's handle on twitter")

Instantiate an LLM engine

from llama import LLM

llm = LLM(name="feedback")

Define a function, call the llm to convert between types. Mix standard python and LLM code.

@llm.function
def generate_tweet(user: User) -> Tweet:
    return llm(user, output_type=Tweet)

Use the LLM to generate something new

example_tweet = generate_tweet(user=User(username="llamas4sale"))

print("tweet before training", example_tweet)

Train the LLM on your data

llm.add_data(
    data=[
        {
            "input": User(username="i_heart_llamas"),
            "output": Tweet(tweet="I like llamas", likes=5, retweets=3),
        },
        {
            "input": User(username="llamas4ever"),
            "output": Tweet(tweet="I like llamas so much", likes=8, retweets=5),
        },
    ]
)

example_tweet = generate_tweet(user=User(username="llamas4sale"))

print("tweet after adding data", example_tweet)

Look at the results, and add your feedback to improve the LLM

llm.improve(on="tweet", to="have more {likes}")
llm.improve(on="tweet", to="have over 100 {retweets}")
llm.improve(
    on="tweet",
    to="make it shorter",
    good_examples=[
        Tweet(
            tweet="Move over cats and dogs, llamas are the new internet sensation! These furry and friendly creatures have captured our hearts and become the most adorable animals on the planet! From their soft wool to their quirky personalities, llamas are simply irresistible! #llamalove #cuteoverload 🦙💕🌟",
            likes=13452,
            retweets=9724,
        )
    ],
    bad_examples=[
        Tweet(
            tweet="Good evening everyone, I hope you're all having a lovely day. I was taking a walk in the countryside earlier and happened to come across a group of llamas. Llamas are interesting animals with a long history of domestication by indigenous people in South America. They're known for their wool, which is used to make various textiles, and also for their use as pack animals. Although some people may find llamas cute and quirky, they can also be quite stubborn and difficult to train. Anyway, that was my llama encounter for the day. Hope you found it mildly interesting. #llamas #naturewalk #animalencounter",
            likes=14,
            retweets=3,
        )
    ],
)
llm.improve(on="tweet", to="have no hashtags")

tweet_after_feedback = generate_tweet(user=User(username="llamas4sale"))

print("tweet after feedback", tweet_after_feedback)

Build complex programs

Project details


Download files

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

Source Distribution

llama-llm-0.0.8.post2.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_llm-0.0.8.post2-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file llama-llm-0.0.8.post2.tar.gz.

File metadata

  • Download URL: llama-llm-0.0.8.post2.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for llama-llm-0.0.8.post2.tar.gz
Algorithm Hash digest
SHA256 699fb1beeb99c73b1d428f3d44b2eebd18a860ae238e5eb7b2a61fd8e2e90218
MD5 47abc979ac35dab3680df9e49475a94e
BLAKE2b-256 cb33cba51332bc9a38e535c33bbbbd4abed1437d43c32c04ba67c265f58c2e6a

See more details on using hashes here.

File details

Details for the file llama_llm-0.0.8.post2-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_llm-0.0.8.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 a12455e8dbdc46776a03ad00d907e11456b67f84041a238caf34d2a04db0c72b
MD5 d5d4b41cdfbf758544f4a1165d3f6fbc
BLAKE2b-256 6b47ca15d5bfb8e10853c635067fedaddbb7b631f77f495d3955516c170cbb02

See more details on using hashes here.

Supported by

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