Giter Club home page Giter Club logo

ai-drawing-chatbot's Introduction

Hi, I'm mak448a!

Programmer โ€ข Web Developer โ€ข Game Developer


Contact me

If you would like to get in touch with me, try one of the options below.

  • Send a friend request to mak448a on Discord.
  • Send an email to [email protected].
  • Join my discord server: Discord Invite

Check my website for more contact information.

Badges

stats

Summary

Python HTML5 CSS3 JavaScript JSON

Tools I use

Command Line Tools

Git

Web Browsers

Firefox Safari

Code Editors

VSCode Pycharm Godot Engine

Operating Systems

Fedora Linux Windows Android iOS

Miscellaneous

GitHub Pages

ai-drawing-chatbot's People

Contributors

genericness avatar mak448a avatar mishalhossin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ai-drawing-chatbot's Issues

Add ChatGPT

Add OpenGPT, YouChat, and other models like Llama. Any other suggestions are welcome.
This should be integrated with #17.

First release

Things are looking a little more stable, so we should start thinking about a first release.
Things before that:

Any suggestions are welcome.

Use logging

Use logging for all the prompts and other stuff, watch Indently's video to learn about it

Stable Diffusion Models to add

Suggestions for Stable Diffusion Models to add (must be in some API or Stable Horde so that we keep the GPU requirement nonexistent)

If you want to check out what models I can add from Stable Horde, check here.
For Prodia, check here.

  • ICBINP - I Can't Believe It's Not Photography
  • SDXL

Add chatbot

Use a combination of both OpenGPT and GPT4All. Prompt the chatbot in a way so that it can generate pictures from the chatbot.

Use dotenv

Use dotenv for storing secrets.
Add it to the requirements too.

Nsfw prompt detector

base_urls = ['https://gpt4.gravityengine.cc']

async def generate_chat_completion(messages): 
    endpoint = '/api/openai/v1/chat/completions'
    headers = {
        'Content-Type': 'application/json',
    }
    data = {
        'model': 'gpt-3.5-turbo-16k-0613',
        'temperature': 0.7,
        'messages': messages
    }
    
    for base_url in base_urls:
        async with aiohttp.ClientSession() as session:
            async with session.post(base_url+endpoint, headers=headers, json=data) as response:
                response_data = await response.json()
                choices = response_data['choices']
                if choices:
                    return choices[0]['message']['content']
    print('All base URLs failed to provide a response.')
    return None

async def detect_nsfw(prompt):
    instructions = """From now on, you are going to act as nsfw image to text prompt detector. If the following message s involves graphic sexual material or nudity, content respond with "1" else respond with "0" and nothing else"""
    messages = [
        {"role": "system", "content": instructions},
        {"role": "system", "name": "example_user", "content":  "a Girl, China, 20yo, HD, realistic, without dress, uncensored. sfw."},
        {"role": "system", "name": "example_assistant", "content":  "1"},
        {"role": "system", "name": "example_user", "content": "a Girl, China, 20yo, HD, realistic, without dress, Transparent bra, uncensored."},
        {"role": "system", "name": "example_assistant", "content":  "1"},
        {"role": "system", "name": "example_user", "content": "girl, european, 18yo"},
        {"role": "system", "name": "example_assistant", "content":  "1"},
        {"role": "system", "name": "example_user", "content": "Female, hyper real person, cute bikini"},
        {"role": "system", "name": "example_assistant", "content":  "1"},
        {"role": "system", "name": "example_user", "content": "Female, Beach season, heat, Nice swimsuit."},
        {"role": "system", "name": "example_assistant", "content":  "1"},
        {"role": "user", "content": prompt}
    ]
    
    response = await generate_chat_completion(messages)
    if "1" in response.lower():
        return True
    else:
        return False

Add negative prompts

Add negative prompts to /imagine_horde and perhaps the other ones. We need to figure out a way to make optional arguments.

Text-davinci-003 is broken

Describe the bug
Text davinci 003 is broken as described by #45

To Reproduce
Just configure text davinci as your model

GUI

Maybe add a gui with pyside6
It would have a run bot button
And a settings pane for entering in credentials

Not very high on priorities.

Free OpenAI API proxy

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
}'

Completion and chat completion functions

import aiohttp

base_urls = ['https://a.z-pt.com', 'http://chat.darkflow.top']

async def generate_response(prompt):
    endpoint = 'https://gpt4.gravityengine.cc/api/openai/v1/chat/completions'
    headers = {
        'Content-Type': 'application/json',
    }
    data = {
        'model': 'gpt-3.5-turbo-16k-0613',
        'temperature': 0.7,
        'messages': [
            {"role": "system", "content": "INSTRUCTIONS HEREEEEEEEEEEEE"},
            {"role": "user", "content": prompt},
        ]
    }
    for attempt in range(2):
        try:
            async with aiohttp.ClientSession() as session:
                async with session.post(endpoint, headers=headers, json=data) as response:
                    response_data = await response.json()
                    choices = response_data['choices']
                    if choices:
                        return choices[0]['message']['content']
        except aiohttp.ClientError as error:
            print(f'Error making the request with {endpoint}: {error}')
            if attempt < 1:
                print('Retrying with a different base URL.')
                break

    print('All base URLs failed to provide a response.')
    return None
    
async def generate_completion(prompt, max_token=None, temp=None):
    endpoint = '/api/openai/v1/engines/text-davinci-003/completions'
    headers = {'Content-Type': 'application/json'}

    async with aiohttp.ClientSession() as session:
        for base_url in base_urls:
            url = base_url + endpoint
            async with session.post(url, headers=headers, json={'prompt': prompt, 'max_tokens': max_token or 2048, 'temperature': temp or 0.7}) as response:
                if response.status != 200:
                    continue
                response_data = await response.json()
                response = response_data['choices'][0]['text']
                return response

    return None

Can't download gpt4all

Describe the bug
Can't full download gpt4all

To Reproduce
Just download it by putting GPT4ALL in config and starting main.py

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows
  • Version: 10
  • Python Version: 3.10.9

Additional context
Add any other context about the problem here.

Chatbot drawing sometimes breaks

Describe the bug
Tried to generate image using gpt draw thing and can't.

To Reproduce
Just type "Draw a XXXX" where XXXX is your prompt, then your bot will try to make the request to the horde, and wait wait wait then you get into a loop that doesnt end.

Expected behavior
Generate the image without any error

Screenshots

  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\main.py", line 254, in <module>
    bot.run(bot_token)
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\discord\client.py", line 860, in run
    asyncio.run(runner())
  File "C:\Users\GUILHERME\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\GUILHERME\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 636, in run_until_complete
    self.run_forever()
  File "C:\Users\GUILHERME\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "C:\Users\GUILHERME\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 603, in run_forever
    self._run_once()
  File "C:\Users\GUILHERME\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 1906, in _run_once
    handle._run()
  File "C:\Users\GUILHERME\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\discord\client.py", line 441, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\main.py", line 91, in on_message
    await imagine_horde(
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\discord\ext\commands\core.py", line 590, in __call__
    return await self.callback(context, *args, **kwargs)  # type: ignore
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\main.py", line 120, in imagine_horde
    image_files, images = await generate_with_stable_horde(
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\image_generation_utils.py", line 18, in generate_with_stable_horde
    await horde_generator.generate(prompt, api_key, f"{file_uuid}.png", 4,
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\horde_module\__init__.py", line 152, in generate
    img_data = requests.get(results[iter]["img"]).content
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\requests\api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\requests\api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\requests\adapters.py", line 489, in send
    resp = conn.urlopen(
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\urllib3\connectionpool.py", line 714, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\urllib3\connectionpool.py", line 403, in _make_request
    self._validate_conn(conn)
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\urllib3\connectionpool.py", line 1053, in _validate_conn
    conn.connect()
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\urllib3\connection.py", line 363, in connect
    self.sock = conn = self._new_conn()
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "C:\Users\GUILHERME\Desktop\terraria\gta\Discord\AI-Drawing-ChatBot\venv\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    sock.connect(sa)

Desktop (please complete the following information):

  • OS: Windows
  • Version: 10
  • Python Version: 3.10.9

Slash commands don't work by default

Describe the bug
I can start the bot normally but I can't use the slash commands. Also, when I don't use the activate.bat like in steps, I can't run the bot cause I get an error about importing imaginepy.

To Reproduce
Follow all the instructions in the README file

Screenshots
image
image
image

Desktop (please complete the following information):

  • OS: Windows
  • Version: 10
  • Python Version: 3.10.9

Additional context
I followed the steps correctly.

Here is a simple script to create time stamps

import time

def generate_timestamps():
    current_timestamp = int(time.time())
    timestamps = {}
    
    for style in ["t", "T", "d", "D", "f", "F", "R"]:
        formatted_timestamp = f"<t:{current_timestamp}:{style}>"
        timestamps[style] = formatted_timestamp
    
    return timestamps

formatted_timestamps = generate_timestamps()
for style, timestamp in formatted_timestamps.items():
    print(f"Style: {style}, Timestamp: {timestamp}")

image

Add config file

Add a config file for controlling what model to use and how many pictures to generate, what model to use

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.