Skip to main content

A thin wrapper for the OpenAI GPT family of APIs

Project description

SpiralFilm ๐ŸŒ€๐ŸŽฅ

Introduction ๐Ÿš€

SpiralFilm is your friendly neighborhood wrapper for the OpenAI ChatGPT family of APIs. It's designed for those knowledge-hungry language model enthusiasts who can't wait to whip up various applications at lightning speed. ๐ŸŒฉ๏ธ

Here's how we roll:

  • Unlike LlamaIndex ๐Ÿฆ™, we're not into the whole integration-with-VectorDB-and-the-likes thing. We believe in you, developers, and trust in your abilities to call upon various databases as you please. ๐Ÿ’ช
  • Forget about high-level abstraction like you'd see in LangChain ๐Ÿ”—. With us, you can tweak prompts without needing to dig into the dark depths of the code. ๐Ÿ˜Ž
  • We're not into overcomplicating stuff. So, unlike guidance, we won't boggle you down with complex processing of prompts. We're more of a keep-it-simple-stupid kind of wrapper, especially when it comes to APIs like gpt-3.5-turbo ๐Ÿš€ or gpt-4. ๐Ÿค–

What we do bring to the table includes:

  • Automatic retry (because sometimes, at first, you don't succeed) โ†ฉ๏ธ
  • Placeholder functionality (like mad-libs, but for code) ๐Ÿ–๏ธ
  • Token count verification (keeping count, so you don't have to) ๐Ÿ”ข
  • Keeping you in the loop with confirmations of sent prompts, timing features, and logging ๐Ÿ•’
  • Caching functionality (to speed up repeated requests and reduce server load) ๐Ÿš€
  • Async execution support, allowing you to run multiple tasks simultaneously, thereby making your application more efficient and responsive. ๐Ÿ‘พ
  • And more! ๐ŸŽ‰

Installation ๐Ÿ”ง

For the vast majority of users, the easiest way to install SpiralFilm is simply by using pip:

pip install spiralfilm

However, for those adventurous spirits who want the very latest version, or perhaps the ones who love to walk on the bleeding edge, here's how you can get the freshest cut from our repository:

# For the pip wizards ๐Ÿง™โ€โ™€๏ธ
pip install git+https@github.com:Spiral-AI/SpiralFilm.git@main

# For the poetry aficionados ๐Ÿ–‹๏ธ
poetry add git+https://github.com/Spiral-AI/SpiralFilm.git@main

For our dear developers, once you've cloned from git, jump into the folder and give this command a spin. Now you can see your modifications to SpiralFilm take effect in real-time in your other code!

git clone git@github.com:Spiral-AI/SpiralFilm.git
cd SpiralFilm
pip install -e .

Magic! ๐ŸŽฉโœจ

Tutorial ๐Ÿ“š

Now that you've got SpiralFilm installed, let's see it in action! Here are a couple of simple examples to get you started:

Example 1: The Simple Scenario ๐Ÿ„โ€โ™€๏ธ

For this, we'll use the script in examples/simple_example.py

from spiral_film import FilmCore

# First things first, let's set up the environment variable for your OpenAI API key
# Uncomment and insert your key as shown below
# import os
# os.environ["OPENAI_API_KEY"] = "your key here"

# Now, let's create a filmcore instance
f = FilmCore(
    prompt="""
Talk as you want.
You're {{user_name}}.
"""
).run(placeholders={"user_name": "Tom"})  # Let's pretend we're Tom for this one

# Print it out and see what Tom has to say!
print(f)

Example 2: Parallel Processing Magic ๐Ÿช„

Sometimes you might need to generate content for multiple prompts in parallel. Doing them one by one can be time-consuming, especially when dealing with a large number. This is where the run_parallel method shines, making the most out of the available computational power.

For this, we'll use the script in examples/parallel_example.py:

from spiralfilm import FilmCore, FilmConfig

# Configuration setup: Here, we're specifying that up to 10 tasks can be run concurrently.
config = FilmConfig(max_queues=10)

# Preparing our placeholders list
placeholders_list = []
for i in range(20):  # Creating 20 placeholders
    placeholders_list.append({"number": str(i)})

# Now, let's create a FilmCore instance with our specified configuration
f = FilmCore(
    prompt="""
Your lucky number is {{number}}.
""",
    config=config,
)

# Using the run_parallel method, all the prompts will be processed concurrently
results = f.run_parallel(placeholders_list=placeholders_list)

# Displaying the results
print(results)
print(f"Processed {len(results)} prompts in parallel!")

In this example, the run_parallel method allows for concurrent processing of multiple prompts, drastically reducing the time it would take if done sequentially. This is especially handy for batch processing or when dealing with real-time requirements.

Example 3: Recollections and Context Memory ๐Ÿง 

There's immense power in context, and with FilmCore, you can harness this power seamlessly. This example, which you can find in examples/conversation_example.py, showcases how you can retain context and query it in subsequent interactions:

By using the create_from method, we can ensure a smooth continuation of the conversation. So, whether it's a fact, a story detail, or a crucial piece of data, FilmCore helps keep the narrative threads intact. ๐Ÿงต๐Ÿ“–

from spiralfilm import FilmCore

fc1 = FilmCore(
    prompt="""
Remember that x={{num}}.
Hello!
"""
)
print(fc1.run(placeholders={"num": "1234"}))

fc2 = FilmCore.create_from(
    fc1,
    prompt="""
Do you remember x?
                         """,
)

print(fc2.run())

Example 4: Deep Dive with Embeddings ๐ŸŒŠ

If you're keen on exploring semantic relationships between sentences, the FilmEmbed utility is your new best friend. Dive into the embedding space and uncover hidden dimensions of meaning. Let's see it in action in the examples/embed_example.py script:

from spiralfilm import FilmEmbed

examples = []

examples.append("Today is a super good day.")
examples.append("Today is a good day.")
examples.append("Today is a bad day.")

vecs = FilmEmbed().run(texts=examples)


def calc_similarity(v1, v2):
    return sum([v1[i] * v2[i] for i in range(len(v1))])


print(
    f"Similarity between '{examples[0]}' and '{examples[1]}' : ",
    calc_similarity(vecs[0], vecs[1]),
)
print(
    f"Similarity between '{examples[0]}' and '{examples[2]}' : ",
    calc_similarity(vecs[0], vecs[2]),
)

With this, you're equipped to explore semantic spaces and better understand the relationship between different sentences. What story do your embeddings tell? ๐Ÿง๐Ÿ“Š

And that's it, folks! You're now ready to start making your own epic conversational masterpieces with SpiralFilm! ๐ŸŽฌ๐Ÿฟ Happy coding! ๐Ÿ’ป๐Ÿš€

But wait, there's more! Be sure to check out the "examples" folder for more usage scenarios and ideas. We've packed it full of tips, tricks, and goodies to get you up and running in no time. ๐Ÿ“š๐Ÿ”

Contribution ๐Ÿค

If you feel like giving back, we always welcome contributions. But remember, at SpiralFilm, we're all about keeping it simple and transparent. We love that you're excited to add features, but let's keep it in line with our "thin-wrapper" philosophy. That way, everyone can continue to enjoy the beauty of simplicity! ๐Ÿ’–๐ŸŒ

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

SpiralFilm-0.1.20.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

SpiralFilm-0.1.20-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file SpiralFilm-0.1.20.tar.gz.

File metadata

  • Download URL: SpiralFilm-0.1.20.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

File hashes

Hashes for SpiralFilm-0.1.20.tar.gz
Algorithm Hash digest
SHA256 328217ccd932f404222a1cfaf0211b128863bae49b899570c2d43a36f5994c8d
MD5 dbabfbee12d8a827ea242716d4acff76
BLAKE2b-256 a1748f08c1eba4f8e6de0292b9c0f623a3c2120789b05db276804cea7726f7ec

See more details on using hashes here.

File details

Details for the file SpiralFilm-0.1.20-py3-none-any.whl.

File metadata

  • Download URL: SpiralFilm-0.1.20-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

File hashes

Hashes for SpiralFilm-0.1.20-py3-none-any.whl
Algorithm Hash digest
SHA256 96eefb6a383a945002ca0b9bb15a2ef54bd3a3ac9f5e7b7a897bd3f23eba8cda
MD5 52a36fc2da12f30e073d5436c47b417a
BLAKE2b-256 1e5511bb82073a9e2d1c90088f07febf8e0baaf7293bab2b77d1ec8bdf31b153

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