llm-static-assert


Namellm-static-assert JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/kdunee/llm-static-assert
SummaryA Python library that leverages Language Models (LLMs) to perform static assertions on code, combining natural language flexibility with static analysis rigor.
upload_time2024-10-16 17:39:12
maintainerNone
docs_urlNone
authorKosma Dunikowski
requires_python<4.0,>=3.10
licenseMIT
keywords llm static-analysis assertions code-quality natural-language
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LLM Static Assert

LLM Static Assert is a powerful Python library that leverages Language Models (LLMs) to perform static assertions on code. This innovative approach combines the flexibility of natural language with the rigor of static analysis, offering a unique solution for code quality and correctness verification.

## Why LLM Static Assert?

Traditional static analysis tools often struggle with complex, context-dependent code properties. LLM Static Assert bridges this gap by utilizing the advanced reasoning capabilities of large language models to evaluate code against natural language expectations.

### Benefits

1. **Natural Language Assertions**: Express complex code properties and expectations using plain English, making it easier to write and understand assertions.
2. **Flexibility**: Evaluate a wide range of code properties that might be challenging for traditional static analysis tools.
3. **Context-Aware**: LLMs can consider broader context and nuanced relationships within the code.
4. **Customizable**: Adjust the assertion process with options like quorum size and model selection.

### Drawbacks

1. **Computational Overhead**: LLM inference can be more resource-intensive than traditional static analysis.
2. **Potential for Ambiguity**: Natural language assertions may sometimes lead to ambiguous interpretations.
3. **Dependence on LLM Quality**: The effectiveness of assertions relies on the capabilities of the underlying language model.

## When to Use LLM Static Assert

- When you need to verify complex, context-dependent code properties.
- For catching subtle logical errors that might escape traditional static analysis.
- In projects where code correctness is critical, and you want an additional layer of verification.
- When you want to express code expectations in a more natural, readable format.

## When Not to Use LLM Static Assert

- For simple, straightforward assertions that can be easily handled by traditional unit tests or type checkers.
- In environments where computational resources are severely constrained.
- When you need deterministic, 100% reproducible results (due to the potential variability in LLM outputs).

## Installation

You can install LLM Static Assert using pip:

```bash
pip install llm-static-assert
```

Or if you're using Poetry:

```bash
poetry add llm-static-assert
```

## Usage

Here's a basic example of how to use LLM Static Assert:

```python
from llm_static_assert import LLMStaticAssert, LLMStaticAssertOptions

# Create an instance of LLMStaticAssert with custom options
options = LLMStaticAssertOptions(quorum_size=3, model="gpt-4o-mini")
lsa = LLMStaticAssert(options)

# Define a class or function you want to assert about
class MyClass:
    def some_method(self):
        pass

# Perform a static assertion
lsa.static_assert(
    "{class} should have a method named 'some_method'",
    {"class": MyClass}
)
```

In this example, we're asserting that `MyClass` has a method named `some_method`. The LLM will analyze the provided class and evaluate whether it meets this expectation.

### Advanced Usage

You can customize the assertion process by adjusting the `LLMStaticAssertOptions`:

```python
options = LLMStaticAssertOptions(
    quorum_size=5,  # Perform 5 inferences and use majority voting
    model="gpt-4"   # Use a more advanced model for complex assertions
)
lsa = LLMStaticAssert(options)

# You can also provide custom options for a specific assertion
lsa.static_assert(
    "{class} should implement proper error handling in all methods",
    {"class": MyComplexClass},
    options=LLMStaticAssertOptions(quorum_size=7, model="gpt-4")
)
```

## Contributing

Contributions to LLM Static Assert are welcome! Please refer to the project's issues page on GitHub for areas where help is needed or to suggest improvements.

## License

[MIT License](LICENSE)

## Acknowledgements

This project uses [LiteLLM](https://github.com/BerriAI/litellm) for LLM integration.

---

LLM Static Assert is an experimental tool and should be used in conjunction with, not as a replacement for, traditional testing and static analysis methods. Always validate its results and use it responsibly.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kdunee/llm-static-assert",
    "name": "llm-static-assert",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "llm, static-analysis, assertions, code-quality, natural-language",
    "author": "Kosma Dunikowski",
    "author_email": "kosmadunikowski@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d5/80/8b197296287cf3a6ab1fddadbbbf87165ea3f74c16450222db0fff4224d5/llm_static_assert-0.1.0.tar.gz",
    "platform": null,
    "description": "# LLM Static Assert\n\nLLM Static Assert is a powerful Python library that leverages Language Models (LLMs) to perform static assertions on code. This innovative approach combines the flexibility of natural language with the rigor of static analysis, offering a unique solution for code quality and correctness verification.\n\n## Why LLM Static Assert?\n\nTraditional static analysis tools often struggle with complex, context-dependent code properties. LLM Static Assert bridges this gap by utilizing the advanced reasoning capabilities of large language models to evaluate code against natural language expectations.\n\n### Benefits\n\n1. **Natural Language Assertions**: Express complex code properties and expectations using plain English, making it easier to write and understand assertions.\n2. **Flexibility**: Evaluate a wide range of code properties that might be challenging for traditional static analysis tools.\n3. **Context-Aware**: LLMs can consider broader context and nuanced relationships within the code.\n4. **Customizable**: Adjust the assertion process with options like quorum size and model selection.\n\n### Drawbacks\n\n1. **Computational Overhead**: LLM inference can be more resource-intensive than traditional static analysis.\n2. **Potential for Ambiguity**: Natural language assertions may sometimes lead to ambiguous interpretations.\n3. **Dependence on LLM Quality**: The effectiveness of assertions relies on the capabilities of the underlying language model.\n\n## When to Use LLM Static Assert\n\n- When you need to verify complex, context-dependent code properties.\n- For catching subtle logical errors that might escape traditional static analysis.\n- In projects where code correctness is critical, and you want an additional layer of verification.\n- When you want to express code expectations in a more natural, readable format.\n\n## When Not to Use LLM Static Assert\n\n- For simple, straightforward assertions that can be easily handled by traditional unit tests or type checkers.\n- In environments where computational resources are severely constrained.\n- When you need deterministic, 100% reproducible results (due to the potential variability in LLM outputs).\n\n## Installation\n\nYou can install LLM Static Assert using pip:\n\n```bash\npip install llm-static-assert\n```\n\nOr if you're using Poetry:\n\n```bash\npoetry add llm-static-assert\n```\n\n## Usage\n\nHere's a basic example of how to use LLM Static Assert:\n\n```python\nfrom llm_static_assert import LLMStaticAssert, LLMStaticAssertOptions\n\n# Create an instance of LLMStaticAssert with custom options\noptions = LLMStaticAssertOptions(quorum_size=3, model=\"gpt-4o-mini\")\nlsa = LLMStaticAssert(options)\n\n# Define a class or function you want to assert about\nclass MyClass:\n    def some_method(self):\n        pass\n\n# Perform a static assertion\nlsa.static_assert(\n    \"{class} should have a method named 'some_method'\",\n    {\"class\": MyClass}\n)\n```\n\nIn this example, we're asserting that `MyClass` has a method named `some_method`. The LLM will analyze the provided class and evaluate whether it meets this expectation.\n\n### Advanced Usage\n\nYou can customize the assertion process by adjusting the `LLMStaticAssertOptions`:\n\n```python\noptions = LLMStaticAssertOptions(\n    quorum_size=5,  # Perform 5 inferences and use majority voting\n    model=\"gpt-4\"   # Use a more advanced model for complex assertions\n)\nlsa = LLMStaticAssert(options)\n\n# You can also provide custom options for a specific assertion\nlsa.static_assert(\n    \"{class} should implement proper error handling in all methods\",\n    {\"class\": MyComplexClass},\n    options=LLMStaticAssertOptions(quorum_size=7, model=\"gpt-4\")\n)\n```\n\n## Contributing\n\nContributions to LLM Static Assert are welcome! Please refer to the project's issues page on GitHub for areas where help is needed or to suggest improvements.\n\n## License\n\n[MIT License](LICENSE)\n\n## Acknowledgements\n\nThis project uses [LiteLLM](https://github.com/BerriAI/litellm) for LLM integration.\n\n---\n\nLLM Static Assert is an experimental tool and should be used in conjunction with, not as a replacement for, traditional testing and static analysis methods. Always validate its results and use it responsibly.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library that leverages Language Models (LLMs) to perform static assertions on code, combining natural language flexibility with static analysis rigor.",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/kdunee/llm-static-assert"
    },
    "split_keywords": [
        "llm",
        " static-analysis",
        " assertions",
        " code-quality",
        " natural-language"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8824d62b64592fa866829c3410df67ba4f4ad208867d88f52a00f0ab584870c",
                "md5": "7a239b8c86eabd463eb0b611a2cb1948",
                "sha256": "fbd5d9c982c5ee57e225cd88e9d98c4d972097057ca5c37ca8abd5d0941f8b74"
            },
            "downloads": -1,
            "filename": "llm_static_assert-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7a239b8c86eabd463eb0b611a2cb1948",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 7256,
            "upload_time": "2024-10-16T17:39:09",
            "upload_time_iso_8601": "2024-10-16T17:39:09.556819Z",
            "url": "https://files.pythonhosted.org/packages/c8/82/4d62b64592fa866829c3410df67ba4f4ad208867d88f52a00f0ab584870c/llm_static_assert-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d5808b197296287cf3a6ab1fddadbbbf87165ea3f74c16450222db0fff4224d5",
                "md5": "f3131e25f7fd243f6166f8ca505df5fb",
                "sha256": "6b995542ccf3d1e79dd2d1fc1542d886cc35827c73625697ec090f1d05b0b463"
            },
            "downloads": -1,
            "filename": "llm_static_assert-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f3131e25f7fd243f6166f8ca505df5fb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 5851,
            "upload_time": "2024-10-16T17:39:12",
            "upload_time_iso_8601": "2024-10-16T17:39:12.489955Z",
            "url": "https://files.pythonhosted.org/packages/d5/80/8b197296287cf3a6ab1fddadbbbf87165ea3f74c16450222db0fff4224d5/llm_static_assert-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-16 17:39:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kdunee",
    "github_project": "llm-static-assert",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "llm-static-assert"
}
        
Elapsed time: 1.17324s