LLM Assistant for Apache Spark
Installation
pip install spark-llm
Usage
Initialization
from spark_llm import SparkLLMAssistant
assistant = SparkLLMAssistant()
assistant.activate() # active partial functions for Spark DataFrame
Data Ingestion
auto_df = assistant.create_df("2022 USA national auto sales by brand")
auto_df.show(n=5)
| rank | brand | us_sales_2022 | sales_change_vs_2021 |
|---|---|---|---|
| 1 | Toyota | 1849751 | -9 |
| 2 | Ford | 1767439 | -2 |
| 3 | Chevrolet | 1502389 | 6 |
| 4 | Honda | 881201 | -33 |
| 5 | Hyundai | 724265 | -2 |
Plot
auto_df.llm.plot()
To plot with an instruction:
auto_df.llm.plot("pie char for top 5 brands and the others' market shares")
DataFrame Transformation
auto_top_growth_df=auto_df.llm.transform("top brand with the highest growth")
auto_top_growth_df.show()
| brand | us_sales_2022 | sales_change_vs_2021 |
|---|---|---|
| Cadillac | 134726 | 14 |
DataFrame Explanation
auto_top_growth_df.llm.explain()
In summary, this dataframe is retrieving the brand with the highest sales change in 2022 compared to 2021. It presents the results sorted by sales change in descending order and only returns the top result.
DataFrame Attribute Verification
auto_top_growth_df.llm.verify("expect sales change percentage to be between -100 to 100")
result: True
UDF Generation
@assistant.udf
def previous_years_sales(brand: str, current_year_sale: int, sales_change_percentage: float) -> int:
"""Calculate previous years sales from sales change percentage"""
...
spark.udf.register("previous_years_sales", previous_years_sales)
auto_df.createOrReplaceTempView("autoDF")
spark.sql("select brand as brand, previous_years_sales(brand, us_sales, sales_change_percentage) as 2021_sales from autoDF").show()
| brand | 2021_sales |
|---|---|
| Toyota | 2032693 |
| Ford | 1803509 |
| Chevrolet | 1417348 |
| Honda | 1315225 |
| Hyundai | 739045 |
Cache
The SparkLLMAssistant supports a simple in-memory and persistent cache system. It keeps an in-memory staging cache that can be persisted through the commit() method. Cache lookup is always performed on the persistent cache only.
assistant.commit()
Refer to example.ipynb for more detailed usage examples.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
Licensed under the Apache License 2.0.
Metadata
Release files for spark-llm 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spark_llm-0.1.9.tar.gz | 18.7 kB | Without provenance | Details for spark_llm-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spark_llm-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for spark_llm-0.1.9-py3-none-any.whl |
Total release size: 39.3 kB
Release files / spark_llm-0.1.9.tar.gz
| Download URL | spark_llm-0.1.9.tar.gz |
|---|---|
| Size | 18.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bec310cf8f33953bddf8938317a6b7a0300f7758f494cd59059bb6c670ebe28c
|
|
BLAKE2b-256 checksum How to use checksums |
9c7bd4ade4f894ac2b6a5037b235b8f1b3b34367b02de22a29db0d1ccdfd56dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.11.4 Darwin/22.5.0
|
Release files / spark_llm-0.1.9-py3-none-any.whl
| Download URL | spark_llm-0.1.9-py3-none-any.whl |
|---|---|
| Size | 20.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e70959977c1bbc39c835cab0bfa897e38cebab591bde543cb372d58300d7ae53
|
|
BLAKE2b-256 checksum How to use checksums |
79a0c0019e3b9723234085f68a00cecacd0266f11a3c5fc39be1dc55cecdabf6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.2 CPython/3.11.4 Darwin/22.5.0
|
Security for spark-llm 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.