フォーク元 g4f/gpt4free
1
1
フォーク 0
ファイルへ移動
EbaAaZ ce0672ef89 modification 2023-05-17 11:30:58 -04:00
g4f modification 2023-05-17 11:16:45 -04:00
interference modification 2023-05-17 11:30:58 -04:00
.gitignore modification 2023-05-17 09:56:59 -04:00
README.md modification 2023-05-17 09:57:36 -04:00

README.md

markdown

g4f-v2: An Unstable Early-Beta Interference OpenAI Proxy API (For Developers)

Note: This version of g4f is still unstable and intended for developers only. Use it with caution.

Introduction

g4f-v2 is a library that acts as an intermediary between your application and the OpenAI GPT-3.5 Turbo language model. It provides an API for interacting with the model and handling chat completions.

Running the Server

To start the g4f-v2 server, run the following command:

python3 -m interference.app

Usage Examples
Using the OpenAI Python Package

First, ensure you have the OpenAI Python package installed. You can then configure it to use g4f-v2 as the API endpoint:

python

import openai

openai.api_key = ''
openai.api_base = 'http://127.0.0.1:1337'

chat_completion = openai.ChatCompletion.create(stream=True,
    model='gpt-3.5-turbo', messages=[{'role': 'user', 'content': 'write a poem about a tree'}])

for token in chat_completion:
    content = token['choices'][0]['delta'].get('content')
    if content is not None:
        print(content)

Simple Usage

g4f-v2 supports multiple providers, including g4f.Providers.You, g4f.Providers.Ails, and g4f.Providers.Phind. Here's how you can use them:

python

import g4f

# Accessing provider parameters
print(g4f.Providers.Ails.params) # Displays supported arguments

# Automatic provider selection
response = g4f.ChatCompletion.create(model='gpt-3.5-turbo', messages=[
                                     {"role": "user", "content": "Hello world"}], stream=True)

for message in response:
    print(message)

# Using a specific provider
response = g4f.ChatCompletion.create(model='gpt-3.5-turbo', provider=g4f.Providers.Phind, messages=[
                                     {"role": "user", "content": "Hello world"}], stream=True)

for message in response:
    print(message)

Development

In the development section, we'll cover more instructions soon. The g4f.Providers class is a crucial component of the library. You can define default providers and their behavior in separate files within the g4f/Providers directory. Each provider file should have the following structure:

./g4f/Providers/ProviderName.py:

python

import os

url: str = 'https://{site_link}'
model: str = 'gpt-[version]'

def _create_completion(prompt: str, args...):
    return ...
    or
    yield ...

params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
    ', '.join([f"{name}: {get_type_hints(_create_completion)[name]