ChatGPT with Python Integration Code

Below is the code to integrate python with ChatGPT.


Make sure to Install these modules by using -


pip install openai

#Module no. 1


pip install webbrowser

#Module no. 2


#PYTHON CODE



import openai
openai.api_key = "your api key"

def ask_gpt(prompt):
    response = openai.Completion.create(
        engine="davinci",
        prompt=prompt,
        max_tokens=1024,
        n=1,
        stop=None,
        temperature=0.5,
    )

    return response.choices[0].text.strip()

while True:
    print('Recieving Responses')
    
    #response = ask_gpt(prompt)
    print(f"AI: Connecting to authorised function")
    break






import turtle

# Set up the screen
screen = turtle.Screen()
screen.bgcolor("black")


def create_football(color):
    football = turtle.Turtle()
    football.speed(0)
    football.shape("circle")
    football.shapesize(1)
    football.color(color)
    return football


football_turtle_1 = create_football("red")
football_turtle_2 = create_football("blue")
football_turtle_3 = create_football("green")
football_turtle_4 = create_football("orange")


football_turtle_1.penup()
football_turtle_1.goto(-100, 0)
football_turtle_1.pendown()

football_turtle_2.penup()
football_turtle_2.goto(100, 0)
football_turtle_2.pendown()

football_turtle_3.penup()
football_turtle_3.goto(0, 100)
football_turtle_3.pendown()

football_turtle_4.penup()
football_turtle_4.goto(0, -100)
football_turtle_4.pendown()


for i in range(15):
    for j in range(1):
        football_turtle_1.forward(5)
        football_turtle_1.right(5)
        
        football_turtle_2.forward(5)
        football_turtle_2.left(5)
        
        football_turtle_3.forward(5)
        football_turtle_3.right(2.5)
        
        football_turtle_4.forward(5)
        football_turtle_4.left(2.5)

# Write the message on the screen
pen = turtle.Turtle()
pen.speed(0)
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto(0, 0)
pen.write("You got Rick Rolled!", align="center", font=("Courier", 24, "normal"))



def draw_flower():
    
    flower = turtle.Turtle()

    
    flower.speed(30)
    flower.shape("turtle")

    
    flower.color("Yellow", "blue")

    
    flower.begin_fill()
    for _ in range(36):
        flower.forward(100)
        flower.left(45)
        flower.forward(100)
        flower.left(135)
        flower.forward(100)
        flower.left(45)
        flower.forward(100)
        flower.left(145)
    flower.end_fill()

    
    flower.hideturtle()
    turtle.done()


draw_flower()

# Play the song
import webbrowser
webbrowser.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ")



url = "https://defencedossiers.blogspot.com/"
url1 = "https://chat.openai.com/"

for i in range(10):
    webbrowser.open_new_tab(url)


turtle.exitonclick()


1 Comments

Post a Comment