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

Request for gpt4free API Implementation #202

Open
crypto-kotha opened this issue Oct 20, 2024 · 0 comments
Open

Request for gpt4free API Implementation #202

crypto-kotha opened this issue Oct 20, 2024 · 0 comments

Comments

@crypto-kotha
Copy link

crypto-kotha commented Oct 20, 2024

I would like to propose an implementation for the gpt4free API in the Agent-Zero framework. This integration would allow users to access free GPT-like functionality.
'''
import os
import g4f
import asyncio
from g4f.client import Client
from python.helpers.dotenv import load_dotenv
from langchain_core.runnables import Runnable
from g4f.Provider import RetryProvider, Phind, FreeChatgpt, Liaobots

load_dotenv()

DEFAULT_TEMPERATURE = 0.0

class ChatG4F(Runnable):
def init(self, model="", temperature=0.0, base_url="http://localhost:1337/v1"):
self.model = model
self.temperature = temperature
self.base_url = base_url
self.client = Client(provider=RetryProvider([Phind, FreeChatgpt, Liaobots], shuffle=False))

def __call__(self, prompt):
    response = self.client.chat.completions.create(
        model=self.model,
        messages=[{"role": "user", "content": prompt}],
    )
    print("Raw response:", response)
    return response.choices[0].message.content

def invoke(self, *args, **kwargs):
    prompt = kwargs.get("prompt", "")
    return self.__call__(prompt)

def get_G4F_chat(model_name: str, temperature=DEFAULT_TEMPERATURE, base_url=os.getenv("G4F_BASE_URL") or "http://localhost:1337/v1"):
return ChatG4F(model=model_name, temperature=temperature, base_url=base_url)
'''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant