mak448a / AI-Drawing-Chatbot

An image generator Discord bot written in Python with no GPU requirement! It can be easily deployed to your favorite VPS for hosting.
MIT License
28 stars 5 forks source link

Free OpenAI API proxy #40

Closed mishl-dev closed 1 year ago

mishl-dev commented 1 year ago

https://gpt4.gravityengine.cc/api/openai/v1/chat/completions

Request example for chat style models

curl https://gpt4.gravityengine.cc/api/openai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-3.5-turbo",
  "messages": [{"role": "user", "content": "Hello, how are you doing today?"}],
  "temperature": 1,
  "max_tokens": 256,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0
}'

And for normal models:

curl https://gpt4.gravityengine.cc/api/openai/v1/completions  -H "Content-Type: application/json" -d '{
  "model": "text-davinci-003",
  "prompt": "Hello, my name is ",
  "temperature": 1,
  "max_tokens": 256,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0
}'
mak448a commented 1 year ago

I'm not sure why, but this command doesn't work when running in the terminal.

mishl-dev commented 1 year ago

Idk man just use this

async def generate_response(prompt):
    base_url = 'https://gpt4.gravityengine.cc/api/openai/'
    error_base_url = 'https://askgpt.cn/api/openai/'
    arguments = '/v1/engines/text-davinci-003/completions'
    endpoint = base_url + arguments

    headers = {
        'Content-Type': 'application/json',
    }

    data = {
        'prompt': prompt,
        'max_tokens': 800,
        'temperature': 0.8
    }

    try:
        async with aiohttp.ClientSession() as session:
            async with session.post(endpoint, headers=headers, json=data) as response:
                response_data = await response.json()
                return(response_data['choices'][0]['text'])
    except aiohttp.ClientError as error:
        print('Error making the request retrying with fallback model')
        endpoint = error_base_url + arguments
        async with aiohttp.ClientSession() as session:
            async with session.post(endpoint, headers=headers, json=data) as response:
                response_data = await response.json()
                return(response_data['choices'][0]['text'])
mak448a commented 1 year ago

I've edited your comment with the working code.

mak448a commented 1 year ago

Idk man just use this

async def generate_response(prompt):
    base_url = 'https://gpt4.gravityengine.cc/api/openai/'
    error_base_url = 'https://askgpt.cn/api/openai/'
    arguments = '/v1/engines/text-davinci-003/completions'
    endpoint = base_url + arguments

    headers = {
        'Content-Type': 'application/json',
    }

    data = {
        'prompt': prompt,
        'max_tokens': 800,
        'temperature': 0.8
    }

    try:
        async with aiohttp.ClientSession() as session:
            async with session.post(endpoint, headers=headers, json=data) as response:
                response_data = await response.json()
                return(response_data['choices'][0]['text'])
    except aiohttp.ClientError as error:
        print('Error making the request retrying with fallback model')
        endpoint = error_base_url + arguments
        async with aiohttp.ClientSession() as session:
            async with session.post(endpoint, headers=headers, json=data) as response:
                response_data = await response.json()
                return(response_data['choices'][0]['text'])

I got the terminal command working, and this will be useful for actually using it. Thanks!

mak448a commented 1 year ago

Should I use the davinci model in the chatbot?

mishl-dev commented 1 year ago

Should I use the davinci model in the chatbot?

Davinci model is kinda shit use text-davinci-003 instead

mak448a commented 1 year ago

Got it. Posted a working test script to here

mak448a commented 1 year ago

By the way, how do you keep finding all this stuff?

mishl-dev commented 1 year ago

By the way, how do you keep finding all this stuff?

https://github.com/LiLittleCat/awesome-free-chatgpt

mak448a commented 1 year ago

Thanks!

mak448a commented 1 year ago

Added text-davinci-003