Skip to main content

AIpython is designed to effortlessly embed AI capabilities into Python, allowing users to solve problems through natural language descriptions and gradually transition to writing code.

Project description

AIpy(love-python): Seamless AI Integration into Python

AIpy is a third-party library designed to effortlessly embed AI capabilities into Python, allowing users to solve problems through natural language descriptions and gradually transition to writing code. Inspired by the GitHub project vibesort, AIpy aims to go beyond simple sorting by enabling AI to handle a wide range of tasks directly.

Key Features

  • @ai_func: Directly uses AI to perform calculations. Ideal for complex problems (slower but low error rate).
  • @ai_act: Generates Python code from natural language descriptions. Best for simple tasks (faster but moderate error rate).
  • @ai_code: Automatically selects the most suitable method (AI calculation or code generation) for any problem (fast and low error rate).

How It Works

  1. Function Documentation: AIpy parses the function's docstring, parameters, and return types.
  2. AI Invocation: Based on the analysis, it calls the large language model to generate either:
    • A direct calculation result (@ai_func)
    • Executable Python code (@ai_act)
    • Optimized code generation (@ai_code)
  3. Result Handling: The result is automatically converted to the expected type and returned.

Installation

pip install aipython

Quick Start

Example: Solving a Problem with @ai_code

from aipy import ai_code

@ai_code
def find_max(numbers: list[int]) -> int:
    """
    Find the maximum number in a list.
    """
    # AI will fill this in

print(find_max([3, 1, 4, 1, 5]))  # Output: 5

Example: Using @ai_func for Calculation

from aipy import ai_func

@ai_func
def calculate_area(radius: float) -> float:
    """
    Calculate the area of a circle with the given radius.
    """
    # AI will compute the result directly

print(calculate_area(5.0))  # Output: 78.53981633974483

Performance Optimization

To minimize token usage and execution time, AIpy caches generated code in ./__pycache__/.aipy/. If the function name and prompt remain unchanged, the cached code is reused. You can force regeneration by setting force=True in the decorator.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.


AIpy(爱-Python):让AI无缝嵌入Python

AIpy 是一个第三方库,旨在将AI能力无缝嵌入Python,使用户能够通过自然语言描述解决问题,并逐步过渡到编写代码。灵感来源于GitHub项目vibesort,AIpy的目标是超越简单的排序,让AI直接处理各种任务。

主要功能

  • @ai_func:直接使用AI完成计算。适合复杂问题(速度较慢但错误率低)。
  • @ai_act:从自然语言描述生成Python代码。适合简单任务(速度快但错误率中等)。
  • @ai_code:自动选择最合适的处理方式(AI计算或代码生成),适用于任何问题(速度快且错误率低)。

工作原理

  1. 函数文档解析:AIpy解析函数的注释、参数和返回类型。
  2. 调用AI:根据分析,调用大语言模型生成:
    • 直接计算结果(@ai_func
    • 可执行Python代码(@ai_act
    • 优化后的代码生成(@ai_code
  3. 结果处理:结果自动转换为预期类型并返回。

安装

pip install aipython

快速入门

示例:使用@ai_code解决问题

from aipy import ai_code

@ai_code
def find_max(numbers: list[int]) -> int:
    """
    找出列表中的最大数。
    """

print(find_max([3, 1, 4, 1, 5]))  # 输出: 5

示例:使用@ai_func进行计算

from aipy import ai_func

@ai_func
def calculate_area(radius: float) -> float:
    """
    计算给定半径的圆的面积。
    """

print(calculate_area(5.0))  # 输出: 78.53981633974483

性能优化

为减少Token消耗和运行时间,AIpy将生成的代码缓存到./__pycache__/.aipy/。如果函数名和提示词不变,将重用缓存代码。您可以在装饰器参数中设置force=True强制更新。

贡献

欢迎贡献!请打开issue或提交pull request。

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

love_python-0.1.1.tar.gz (33.9 kB view details)

Uploaded Source

Built Distribution

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

love_python-0.1.1-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file love_python-0.1.1.tar.gz.

File metadata

  • Download URL: love_python-0.1.1.tar.gz
  • Upload date:
  • Size: 33.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for love_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7c3806a2119b4a13dce417123c682ae8dfe10826e62c513ba4c270b5c660309e
MD5 ccebbb1af51cfbd4f7423a42a9ef45cc
BLAKE2b-256 cfe54df04dab2e8b579ca15f1d0618f55b1567284065eae81921392730951a3b

See more details on using hashes here.

File details

Details for the file love_python-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: love_python-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for love_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b932f0d7c209dc35bf3a15f9453ec9bede249bfa0a9cc6437d315521a994359f
MD5 2cb58c0ced74ae8c0b8a30f39fedd9af
BLAKE2b-256 f03209a32a165552e61b28575bbd78cdbe6fc3862cbe61bf0b302939c9acfce3

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