SpiralFilm


NameSpiralFilm JSON
Version 0.2.5 PyPI version JSON
download
home_pagehttps://github.com/Spiral-AI/spiralfilm
SummaryA thin wrapper for the OpenAI GPT family of APIs
upload_time2024-02-05 07:25:47
maintainer
docs_urlNone
authorYuichi Sasaki
requires_python>=3.8, <4
license
keywords openai gpt api wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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`

```python
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: 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. ๐Ÿงต๐Ÿ“–
```python
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 3: 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:
```python
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! ๐Ÿ’–๐ŸŒ

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Spiral-AI/spiralfilm",
    "name": "SpiralFilm",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8, <4",
    "maintainer_email": "",
    "keywords": "openai,gpt,api,wrapper",
    "author": "Yuichi Sasaki",
    "author_email": "y_sasaki@go-spiral.ai",
    "download_url": "https://files.pythonhosted.org/packages/18/d9/de7a9ca85bedc947841771542fb3eca223c076461cd029bf44fea1aa876d/SpiralFilm-0.2.5.tar.gz",
    "platform": null,
    "description": "# SpiralFilm \ud83c\udf00\ud83c\udfa5\n## Introduction \ud83d\ude80\nSpiralFilm 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. \ud83c\udf29\ufe0f\n\nHere's how we roll:\n\n- Unlike LlamaIndex \ud83e\udd99, 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. \ud83d\udcaa\n- Forget about high-level abstraction like you'd see in LangChain \ud83d\udd17. With us, you can tweak prompts without needing to dig into the dark depths of the code. \ud83d\ude0e\n- 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 \ud83d\ude80 or gpt-4. \ud83e\udd16\n\nWhat we do bring to the table includes:\n\n- Automatic retry (because sometimes, at first, you don't succeed) \u21a9\ufe0f\n- Placeholder functionality (like mad-libs, but for code) \ud83d\udd8d\ufe0f\n- Token count verification (keeping count, so you don't have to) \ud83d\udd22\n- Keeping you in the loop with confirmations of sent prompts, timing features, and logging \ud83d\udd52\n- Caching functionality (to speed up repeated requests and reduce server load) \ud83d\ude80\n- Async execution support, allowing you to run multiple tasks simultaneously, thereby making your application more efficient and responsive. \ud83d\udc7e\n- And more! \ud83c\udf89\n\n## Installation \ud83d\udd27\n\nFor the vast majority of users, the easiest way to install SpiralFilm is simply by using pip:\n```\npip install spiralfilm\n```\n\nHowever, 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:\n\n```\n# For the pip wizards \ud83e\uddd9\u200d\u2640\ufe0f\npip install git+https@github.com:Spiral-AI/SpiralFilm.git@main\n\n# For the poetry aficionados \ud83d\udd8b\ufe0f\npoetry add git+https://github.com/Spiral-AI/SpiralFilm.git@main\n```\n\nFor 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! \n\n```\ngit clone git@github.com:Spiral-AI/SpiralFilm.git\ncd SpiralFilm\npip install -e .\n```\nMagic! \ud83c\udfa9\u2728\n\n## Tutorial \ud83d\udcda\n\nNow that you've got SpiralFilm installed, let's see it in action! Here are a couple of simple examples to get you started:\n\n### Example 1: The Simple Scenario \ud83c\udfc4\u200d\u2640\ufe0f\nFor this, we'll use the script in `examples/simple_example.py`\n\n```python\nfrom spiral_film import FilmCore\n\n# First things first, let's set up the environment variable for your OpenAI API key\n# Uncomment and insert your key as shown below\n# import os\n# os.environ[\"OPENAI_API_KEY\"] = \"your key here\"\n\n# Now, let's create a filmcore instance\nf = FilmCore(\n    prompt=\"\"\"\nTalk as you want.\nYou're {{user_name}}.\n\"\"\"\n).run(placeholders={\"user_name\": \"Tom\"})  # Let's pretend we're Tom for this one\n\n# Print it out and see what Tom has to say!\nprint(f)\n```\n\n\n### Example 2: Recollections and Context Memory \ud83e\udde0\nThere'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:\n\n\nBy 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. \ud83e\uddf5\ud83d\udcd6\n```python\nfrom spiralfilm import FilmCore\n\nfc1 = FilmCore(\n    prompt=\"\"\"\nRemember that x={{num}}.\nHello!\n\"\"\"\n)\nprint(fc1.run(placeholders={\"num\": \"1234\"}))\n\nfc2 = FilmCore.create_from(\n    fc1,\n    prompt=\"\"\"\nDo you remember x?\n                         \"\"\",\n)\n\nprint(fc2.run())\n\n```\n\n\n### Example 3: Deep Dive with Embeddings \ud83c\udf0a\nIf 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:\n```python\nfrom spiralfilm import FilmEmbed\n\nexamples = []\n\nexamples.append(\"Today is a super good day.\")\nexamples.append(\"Today is a good day.\")\nexamples.append(\"Today is a bad day.\")\n\nvecs = FilmEmbed().run(texts=examples)\n\n\ndef calc_similarity(v1, v2):\n    return sum([v1[i] * v2[i] for i in range(len(v1))])\n\n\nprint(\n    f\"Similarity between '{examples[0]}' and '{examples[1]}' : \",\n    calc_similarity(vecs[0], vecs[1]),\n)\nprint(\n    f\"Similarity between '{examples[0]}' and '{examples[2]}' : \",\n    calc_similarity(vecs[0], vecs[2]),\n)\n\n```\n\nWith this, you're equipped to explore semantic spaces and better understand the relationship between different sentences. What story do your embeddings tell? \ud83e\uddd0\ud83d\udcca\n\nAnd that's it, folks! You're now ready to start making your own epic conversational masterpieces with SpiralFilm! \ud83c\udfac\ud83c\udf7f Happy coding! \ud83d\udcbb\ud83d\ude80\n\nBut 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. \ud83d\udcda\ud83d\udd0d\n\n## Contribution \ud83e\udd1d\n\nIf 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! \ud83d\udc96\ud83c\udf10\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A thin wrapper for the OpenAI GPT family of APIs",
    "version": "0.2.5",
    "project_urls": {
        "Homepage": "https://github.com/Spiral-AI/spiralfilm"
    },
    "split_keywords": [
        "openai",
        "gpt",
        "api",
        "wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c663fe2a5f3dd19b3cc780d03ee51a2ad59041b3c5267371c67faf0d4d64410a",
                "md5": "6dcf6fabd9d11a2defb8341c0d78883c",
                "sha256": "a66a3857bc37d114ad85ac91fc12aa6f2c5906ee345d832c9da193e1bf565909"
            },
            "downloads": -1,
            "filename": "SpiralFilm-0.2.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6dcf6fabd9d11a2defb8341c0d78883c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8, <4",
            "size": 18916,
            "upload_time": "2024-02-05T07:25:44",
            "upload_time_iso_8601": "2024-02-05T07:25:44.167694Z",
            "url": "https://files.pythonhosted.org/packages/c6/63/fe2a5f3dd19b3cc780d03ee51a2ad59041b3c5267371c67faf0d4d64410a/SpiralFilm-0.2.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "18d9de7a9ca85bedc947841771542fb3eca223c076461cd029bf44fea1aa876d",
                "md5": "e5a4a67c282ed3bb7eb2a36c1f230213",
                "sha256": "82d3245f2725f13466ba58b5807289fa4fb3d6bb705e3a18ec2bd2b3cb486870"
            },
            "downloads": -1,
            "filename": "SpiralFilm-0.2.5.tar.gz",
            "has_sig": false,
            "md5_digest": "e5a4a67c282ed3bb7eb2a36c1f230213",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8, <4",
            "size": 18553,
            "upload_time": "2024-02-05T07:25:47",
            "upload_time_iso_8601": "2024-02-05T07:25:47.969055Z",
            "url": "https://files.pythonhosted.org/packages/18/d9/de7a9ca85bedc947841771542fb3eca223c076461cd029bf44fea1aa876d/SpiralFilm-0.2.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-05 07:25:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Spiral-AI",
    "github_project": "spiralfilm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "spiralfilm"
}
        
Elapsed time: 0.17321s