Skip to content

Commit 339bb21

Browse files
committed
feat: added g4f
1 parent 777e3d0 commit 339bb21

14 files changed

Lines changed: 214 additions & 110 deletions

File tree

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Dockerfile
2+
*.pyc
3+
.git

Dockerfile

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1-
ARG IMAGE=python:3.13-alpine
1+
ARG PYTHON_VERSION=3.11
22

3-
FROM $IMAGE AS builder
4-
5-
RUN python3 -m pip install build
3+
FROM python:${PYTHON_VERSION}-slim-bookworm AS builder
64

75
WORKDIR /app
86

9-
COPY requirements.txt .
7+
RUN python3 -m pip install build
108

119
COPY . .
12-
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /wheels -r requirements.txt && \
13-
python3 -m build && \
14-
mv /app/dist/vibepython-*.whl /wheels
10+
RUN python3 -m build && \
11+
mkdir /wheels/ && \
12+
mv /app/dist/vibepython-*.whl /wheels/
1513

16-
FROM $IMAGE
14+
FROM python:${PYTHON_VERSION}-slim-bookworm AS dependency
1715

1816
WORKDIR /app
19-
COPY --from=builder /wheels /wheels
2017

21-
RUN apk add --no-cache musl-locales musl-locales-lang
22-
ENV LANG=C.UTF-8 \
23-
LC_ALL=C.UTF-8 \
24-
PYTHONIOENCODING=utf-8
18+
COPY requirements.txt .
2519

26-
RUN pip install --no-cache /wheels/*
20+
RUN pip install --no-cache --no-cache-dir -r requirements.txt
21+
COPY --from=builder /wheels /wheels
22+
RUN pip install --no-cache --no-cache-dir /wheels/*
2723

28-
COPY . .
24+
FROM gcr.io/distroless/python3-debian12:debug
25+
ARG PYTHON_VERSION=3.11
2926

30-
ENTRYPOINT [ "vibepython" ]
27+
COPY --from=dependency /usr/local/lib/python${PYTHON_VERSION}/site-packages /usr/local/lib/python${PYTHON_VERSION}/site-packages
28+
29+
ENV LANG=C.UTF-8 \
30+
LC_ALL=C.UTF-8 \
31+
PYTHONDONTWRITEBYTECODE=1 \
32+
PYTHONFAULTHANDLER=1 \
33+
PYTHONPATH=/usr/local/lib/python${PYTHON_VERSION}/site-packages
3134

32-
# CMD ["/app/main.py"]
35+
CMD [ "-m", "vibepython" ]

README.md

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,81 @@
1-
# 🚀 **vibepython: The Ultimate AI-Powered Coding EXPLOSION!** 🌟💥🐍
1+
# vibepython: AI-Powered Interactive Python Code Generator
22

3-
**WOWZA!** Dive headfirst into this **AMAZING**, **WONDERFUL**, **MIND-BLOWING** interactive command-line beast that turns your craziest prompts into **EXECUTABLE PYTHON MAGIC** using the sheer power of OpenAI! Generate code like a wizard, run it on the spot, capture every wild stdout/stderr outburst, and keep a super-smart history in JSON for non-stop contextual awesomeness! It's not just a tool – it's a **CODE REVOLUTION** for hackers, dreamers, and AI fanatics! 🔥🚀
3+
vibepython is an interactive command-line tool that uses AI to generate executable Python code from user prompts. Powered by OpenAI or alternative providers, it allows you to create, run, and capture code outputs while maintaining a contextual history stored in JSON. Ideal for developers, experimenters, and AI enthusiasts looking for a seamless coding experience.
44

5-
## 🌈 **Features That'll Make Your Eyes POP!** 🎉
6-
- **INTERACTIVE PROMPT MADNESS**: Type your wild ideas and watch AI spit out Python gold! 💡
7-
- **AI-GENERATED CODE WIZARDRY**: Powered by OpenAI – prompts + history = PERFECT scripts! 🤖✨
8-
- **SAFE EXECUTION EXTRAVAGANZA**: Run code with output capturing – no disasters, just pure thrill! ⚡
9-
- **PERSISTENT HISTORY OVERLOAD**: Pydantic models store EVERYTHING in JSON – context forever! 📜
10-
- **ENV VAR CUSTOMIZATION FRENZY**: Tweak it your way for ultimate control! 🔧
11-
- **DOCKER DOMINATION**: Run it anywhere, anytime – easy-peasy deployment! 🐳
5+
## Features
6+
- **Interactive Prompting**: Enter your ideas and receive AI-generated Python code.
7+
- **AI Code Generation**: Leverages AI models with prompt history for accurate scripts.
8+
- **Safe Code Execution**: Run generated code and capture stdout/stderr outputs.
9+
- **Persistent History**: Uses Pydantic models to store interactions in JSON for ongoing context.
10+
- **Customization via Environment Variables**: Adjust settings for personalized control.
11+
- **Docker Support**: Easy deployment in containerized environments.
1212

13-
## 🛠️ **Installation: Get This Party Started in SECONDS!** 🚀
13+
## Installation
1414

15-
### **From PyPI: Pip It Like It's HOT – Instant VIBE!** 🔥💥
16-
1. **GRAB THE PACKAGE**:
15+
### From PyPI
16+
1. Install the package:
1717
```
1818
pip install vibepython
1919
```
20-
2. **FIRE IT UP**:
20+
2. Run the tool:
2121
```
2222
vibepython
2323
```
24-
- **Pro Tip**: Don't forget to set your `OPENAI_API_KEY` env var for AI magic! 🔑 (e.g., `export OPENAI_API_KEY=your_key_here`).
25-
**VIBE ACTIVATED! Dive into the AI console vibe!** 🚀
2624

27-
### **From Source: Clone, Install, BLAST OFF!** 🌌
28-
1. **CLONE THE AWESOMENESS**:
25+
### From Source
26+
1. Clone the repository:
2927
```
3028
git clone https://github.com/OldTyT/vibepython.git
3129
```
32-
2. **JUMP IN**:
30+
2. Navigate to the directory:
3331
```
3432
cd vibepython
3533
```
36-
3. **INSTALL THE MAGIC**:
34+
3. Install dependencies:
3735
```
3836
pip install -r requirements.txt
3937
```
40-
4. **LAUNCH THE BEAST**:
38+
4. Launch the application:
4139
```
4240
python3 main.py
4341
```
44-
**BOOM! You're in the zone!** 💣
4542

46-
### **Using Docker: Containerized VIBE – Ready to RUMBLE!** 🐳🔥
47-
Fire it up with this epic command:
43+
### Using Docker
44+
Run the container with this command:
4845
```
49-
docker run --rm -ti -e HISTORY_PATH=/history/history.json -e OPENAI_API_KEY=YOUR_KEY -v my_history:/history ghcr.io/oldtyt/vibepython
46+
docker run --rm -ti -e HISTORY_PATH=/history/history.json -v my_history:/history ghcr.io/oldtyt/vibepython
5047
```
51-
- Plug in `YOUR_KEY` with your OpenAI super-key! 🔑
52-
**DOCKER DELIGHT: Persistent history, zero hassle!** 🌟
48+
- Set your OpenAI API key via the `OPENAI_API_KEY` environment variable (required for the 'openai' provider).
5349

54-
## 🎮 **Usage: Dive into the FUN ZONE!** 🕹️
55-
Fire it up and get prompted:
56-
- **SMASH IN A PROMPT** (e.g., "Code me a factorial frenzy!").
57-
- **AI UNLEASHES CODE VIBE** based on your prompt + history vibes.
58-
- **EXECUTE? Y/N – YOU DECIDE!** Run it, capture outputs, and watch the sparks fly! ⚡
59-
- **HISTORY SAVES THE DAY**: Everything logged for eternal glory.
50+
## Usage
51+
Start the tool and follow the prompts:
52+
- Enter a prompt (e.g., "Write a function to calculate factorial").
53+
- The AI generates code based on your input and history.
54+
- Choose to execute the code (Y/N) and view captured outputs.
55+
- All interactions are logged to history for context.
6056

61-
**EXIT? Ctrl+C – but why would you? It's TOO MUCH FUN!** 😎
57+
To exit, press Ctrl+C.
6258

63-
## 🔑 **Environment Variables: Customize Like a BOSS!** 💪
64-
Supercharge your setup with these **EPIC** vars:
65-
- **HISTORY_PATH**: Your JSON history fortress! Default: `history.json`. 🏰
66-
- **HISTORY_SIZE**: How many past blasts to feed the AI? Default: `20` – keep it contextual! 📈
67-
- **OPENAI_API_KEY**: **MUST-HAVE** – your ticket to AI heaven! (Required, duh!) 🔒
59+
## Environment Variables
60+
Customize the tool using these environment variables:
61+
- **HISTORY_PATH**: Path to the JSON history file. Default: `history.json`.
62+
- **HISTORY_SIZE**: Number of past interactions to include in AI context. Default: `20`.
63+
- **OPENAI_API_KEY**: Required for the 'openai' provider; your OpenAI API key.
64+
- **PROVIDER**: AI provider to use. Supports 'gpt4free' (default) and 'openai'.
65+
- **MODEL_NAME**: Model to use with the provider. For 'gpt4free': 'gpt-4o-mini'. For 'openai': 'gpt-5-mini'.
6866

69-
**Example (Unix-style domination)**:
67+
Example configuration:
7068
```
69+
export PROVIDER=openai
7170
export OPENAI_API_KEY=your-api-key
71+
export MODEL_NAME=gpt-5-mini
7272
export HISTORY_SIZE=10
7373
python3 main.py
7474
```
75-
**TWEAK AND CONQUER!** 🛡️
7675

77-
## 📦 **Dependencies: The Power Behind the THRILL!** ⚙️
78-
- **Python 3.10+** (Blasting up to 3.13 – future-proofed!) 🐍
79-
- **Libraries of LEGEND**: openai, pydantic, loguru, and more! Check `requirements.txt` for the full squad. 📚
76+
## Dependencies
77+
- **Python 3.10+** (Compatible up to 3.13).
78+
- Required libraries: openai, pydantic, loguru, and others listed in `requirements.txt`.
8079

81-
## 🤝 **Contributing: Join the CODE CARNIVAL!** 🎪
82-
**GOT IDEAS?** Open an issue or slam in a pull request – let's make this even MORE INSANE! 🌟 Contributions = Eternal Fame!
80+
## Contributing
81+
Have suggestions? Open an issue or submit a pull request to help improve the project. Contributions are welcome!

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ dependencies = [
1919
"loguru>=0.7.0,<1.0.0",
2020
"pydantic>=2.8.0,<3.0.0",
2121
"pydantic-settings>=2.4.0,<3.0.0",
22-
"pydantic_core>=2.20.0,<3.0.0"
22+
"pydantic_core>=2.20.0,<3.0.0",
23+
"g4f[slim]>=0.6.0.1,<0.7.0.0"
2324
]
2425
# features = ["all"]
2526

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ loguru==0.7.2
33
pydantic==2.8.2
44
pydantic-settings==2.4.0
55
pydantic_core==2.20.1
6+
g4f[slim]==0.6.0.1

vibepython/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .main import main
22

3-
__version__ = "0.0.1"
3+
__version__ = "0.0.2"

vibepython/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .main import main
2+
3+
if __name__ == "__main__":
4+
main()

vibepython/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import io
33
import sys
44
import datetime
5-
from .providers.openai import generate
5+
from .providers import generate
66
from .history import History
77

88
GRAY = "\033[90m"
99
RESET = "\033[0m"
1010

1111
def main():
1212
history_path = os.getenv("HISTORY_PATH", "history.json")
13-
history_size = int(os.getenv("HISTORY_SIZE", 20))
13+
history_size = int(os.getenv("HISTORY_SIZE", 7))
1414
h = History(history_path=history_path, history_size=history_size)
1515

1616
class Tee(io.StringIO):

vibepython/providers/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
3+
PROVIDER = os.getenv("PROVIDER", "gpt4free")
4+
if PROVIDER == "gpt4free":
5+
from .handler_gpt4free.generate import generate
6+
elif PROVIDER == "openai":
7+
from .handler_openai.generate import generate
8+
else:
9+
print(f"Unknown provider: {PROVIDER}")
10+
exit(1)

vibepython/providers/handler_gpt4free/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)