Saturday, December 10, 2022

OpenAI GPT-3 Chatter Bot

As a backgrounder, GPT-3 (Generative Pretrained Transformer 3) is a state-of-the-art language processing AI model developed by OpenAI. It is capable of generating human-like text and has a wide range of applications, including language translation, language modelling, and generating text for applications such as chatbots. It is one of the largest and most powerful language processing AI models to date, with 175 billion parameters. See more info here.

There is a lot of speculation that in the near future it will wipe out millions of jobs, one of them is programming. See the youtube video here for a simple demo. Please note that Tech with Tim(the youtuber) used ChatGPT which is an online demo program of GPT-3.

Ok, I am a programmer so I am creating a future competitor, here is a simple python chat program that allows interaction with is future job ripper. 

Sample output:



Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pyttsx3

from PyQt6.QtGui import *
from PyQt6.QtCore import *
from PyQt6.QtWidgets import *

import openai


class Window(QWidget):
    def __init__(self):
        super(Window, self).__init__()

 
        self.le = QTextEdit(self)
        
        self.le.setGeometry(5, 40, 890, 400)

        self.le1 = QTextEdit(self)
        
        self.le1.setGeometry(5, 5, 790, 30)
        
        self.btnStart = QPushButton("Ask", self)
        self.btnStart.setGeometry(800, 5, 90, 30)
  
        self.btnStart.clicked.connect(self.onClickedStart)
        #self.runnable = SpeechRunnable()
        #self.btnStop.clicked.connect(self.runnable.stop)
        self.setGeometry(25, 45, 900, 450)
        self.setWindowTitle('Open AI  GPT-3 Chatter Bot')
        
    def speaker(self, otext):
        engine = pyttsx3.init()
        engine.setProperty('rate', 150)
        engine.say(otext)
        engine.runAndWait()

    def onClickedStart(self):
        
        openai.api_key = "sk-XXXXXXX"
        response = openai.Completion.create(
        engine="davinci",
        prompt= self.le1.toPlainText() + "\nAI:",
        temperature=0.9,
        max_tokens=150,
        top_p=1,
        frequency_penalty=0.0,
        presence_penalty=0.6,
        stop=["\n", " Human:", " AI:"]
        )
        otext =response["choices"][0]["text"]
        self.le.setPlainText(self.le.toPlainText() + '\n' + self.le1.toPlainText() + '\n AI:' + otext)
        self.le.repaint()
        self.le1.setPlainText(text)
        self.speaker(otext)
        
        
text = ''
if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    w = Window()
    w.show()
    sys.exit(app.exec())

No comments:

Post a Comment