Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add G4F model and enhance install.sh #35

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

![Animated GIF](https://github.com/wunderwuzzi23/blog/raw/master/static/images/2023/yolo-shell-anim-gif.gif)

# Update Yolo v0.6 - Support for G4F and Improved Installation

* Added G4F (GPT4Free) support. No API key required! Just set `api: g4f` in your `yolo.yaml`.
* Default model for G4F is `gpt-3.5-turbo`
* Now configured as the default API in yolo.yaml since no API key configuration is needed
* Improved installation process with `install.sh`:
- Creates an isolated virtual environment for clean dependency management
- Particularly beneficial for Arch Linux users to avoid conflicts with system packages
- Automatically handles venv activation/deactivation when running commands
- Supports both bash and zsh shells with proper shell function integration
* Simplified model initialization and error handling

# Update Yolo v0.5 - Support for Claude and other providers

* Added Claude support. Can an API key from Anthropic, current model `claude-3-5-sonnet-20240620`.
Expand Down Expand Up @@ -78,6 +90,11 @@ There are three ways to configure the key on Linux and macOS:
- You can either `export GROQ_API_KEY=<yourkey>`, or have a `.env` file in the same directory as `yolo.py` with `GROQ_API_KEY="<yourkey>"` as a line
- Set `api` and `model` (e.g llama3-8b-8192) in `yolo.yaml` configuration file

### G4F Configuration
- No API key required!
- Set `api: g4f` in `yolo.yaml` configuration file
- Default model is `gpt-3.5-turbo`

## Aliases

To set the alias, like `yolo` or `computer` on each login, add them to .bash_aliases (or .zshrc on macOS) file. Make sure the path is the one you want to use.
Expand Down
20 changes: 20 additions & 0 deletions ai_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ollama import Client
from openai import AzureOpenAI
from anthropic import Anthropic
from g4f.client import Client as G4FClient
import os

class AIModel(ABC):
Expand Down Expand Up @@ -58,6 +59,9 @@ def get_model_client(config):
#ollama_model = os.environ.get("OLLAMA_MODEL", "llama3-8b-8192")
return OllamaModel(ollama_api)

elif api_provider == "g4f":
return G4FModel()

if api_provider == "anthropic":
api_key = os.getenv("ANTHROPIC_API_KEY")
if not api_key:
Expand Down Expand Up @@ -124,6 +128,22 @@ def chat(self, messages, model, temperature, max_tokens):
def moderate(self, message):
return self.client.moderations.create(input=message)

class G4FModel(AIModel):
def __init__(self, api_key=None):
self.client = G4FClient()

def chat(self, messages, model, temperature, max_tokens):
resp = self.client.chat.completions.create(
model="gpt-3.5-turbo",
messages=messages,
temperature=temperature,
max_tokens=max_tokens
)
return resp.choices[0].message.content

def moderate(self, message):
return self.client.moderations.create(input=message)

class AnthropicModel(AIModel):
def __init__(self, api_key):
self.client = Anthropic(api_key=api_key)
Expand Down
76 changes: 56 additions & 20 deletions install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ goto :EOF
:: Installs optional files if user wants
:install_optional
cls
call :print_apikey
choice /n /c YN /m "Let me know which option you want to select: "
call :print_optional_menu
choice /n /c YNOC /m "Let me know which option you want to select: "
set /a createAPIKEY=!ERRORLEVEL!

if /i !createAPIKEY!==1 ( call :create_openai_apikey )
if /i !createAPIKEY!==3 ( exit /b 0 )
goto :EOF

:: Creates a directory to hold yolo.py and prompt.txt
Expand Down Expand Up @@ -198,9 +199,10 @@ echo.
echo Installation Options:
echo.
echo [Y] Yolo, Default installation to your home folder ( `%HOMEDRIVE%%HOMEPATH%\` )
echo Uses G4F by default (no API key needed)
echo [N] Non-default install, Set custom install locations
echo [C] Cancel, Do not install (exit this script)
echo [O] Optional Files (advanced options)
echo [O] Optional Files (API keys for other providers)
echo.
echo You probably want to use [Y].
echo.
Expand Down Expand Up @@ -246,6 +248,21 @@ echo You probably want to use [Y], you can manually move the `yolo.bat` file aft
echo.
goto :EOF

:: Prints a prompt for `.openai.apikey`
:print_optional_menu
echo.
echo Optional Files:
echo.
echo Note: By default, Yolo uses G4F which requires no API key.
echo These options are only needed if you want to use other providers.
echo.
echo Y. Yes - Create optional API key files
echo N. No - Skip (recommended for G4F)
echo O. Only create optional files and exit
echo C. Cancel
echo.
goto :EOF

:: Prints a prompt for `.openai.apikey`
:print_apikey
echo.
Expand Down Expand Up @@ -298,22 +315,41 @@ goto :EOF

:print_apikey_guide
echo.
echo API Key:
echo.
echo You need to provide your OpenAI API key to use yolo.
echo.
echo You can get a key from `https://platform.openai.com/account/api-keys` after logging in.
echo There are multiple options for providing the key:
echo (1) You can put the key into a `.openai.apikey` file in `%HOMEDRIVE%%HOMEPATH%\`
echo Run `install.bat` again and select `O`ptional Files to create a `.openai.apikey` file
echo (2) You can paste `OPENAI_API_KEY="[yourkey]"` into a `.env` file that should be in the folder yolo is installed in currently.
if /i !createDIR!==1 ( echo `.env` should be in: !TARGET_DIR! )
if /i !createDIR!==2 ( echo `.env` should be in: %~dp0 )
echo (3) You can run `$env:OPENAI_API_KEY="[yourkey]"` in your terminal before using yolo in that terminal
echo -If you run PowerShell as administrator you can then run `setx OPENAI_API_KEY "[yourkey]"` to permanently and use yolo in any terminal (you may need to reopen the terminal once).
echo -Go to `Start` and search `edit environment variables for your account` and manually create the variable with name `OPENAI_API_KEY` and value `[yourkey]`
echo (4) Another option is to put the API key in the yolo.yaml configuration file (since v.0.2)
echo.
echo Yolo also supports Azure OpenAI, and many other LLMs now. Configure settings in yolo.yaml accordingly.
echo API Key Configuration:
echo.
echo By default, Yolo uses G4F which requires no API key.
echo However, if you want to use other providers, you'll need their respective API keys.
echo.
echo There are multiple options for providing API keys:
echo (1) Environment Variables (Recommended)
echo Run these commands in PowerShell:
echo $env:OPENAI_API_KEY="[yourkey]"
echo $env:AZURE_OPENAI_API_KEY="[yourkey]"
echo $env:ANTHROPIC_API_KEY="[yourkey]"
echo $env:GROQ_API_KEY="[yourkey]"
echo.
echo (2) Configuration File
echo Edit yolo.yaml and add your keys:
if /i !createDIR!==1 ( echo yolo.yaml is in: !TARGET_DIR! )
if /i !createDIR!==2 ( echo yolo.yaml is in: %~dp0 )
echo.
echo (3) Environment File
echo Create a .env file with your keys:
if /i !createDIR!==1 ( echo .env should be in: !TARGET_DIR! )
if /i !createDIR!==2 ( echo .env should be in: %~dp0 )
echo.
echo (4) API Key File
echo Put your OpenAI key in .openai.apikey in %HOMEDRIVE%%HOMEPATH%
echo Run install.bat again and select Optional Files to create it
echo.
echo Supported Providers:
echo - G4F (Default, no key needed)
echo - OpenAI
echo - Azure OpenAI
echo - Anthropic (Claude)
echo - Groq
echo - Ollama
echo.
echo To change providers, update the 'api' setting in yolo.yaml
echo.
goto :EOF
Loading