API Call Issue when trying to connect Python to ChatGPT

I am trying to create an API call which will my python app top receive instructions from my ChatGPT AI. However I keep getting the below errors, ChatGPT itself keeps trying to use the older ChatCompletion.Create all the time. I could not see my exact issues else where only similar but their solutions did not work…any ideas what is wrong ?

Exception in Tkinter callback
Traceback (most recent call last):
File “C:\Users\AppData\Local\Programs\Python\Python311\Lib\tkinter_init_.py”, line 1967, in call
return self.func(*args)
File “C:\Users\Documents\Python\Annotator_OpenAI\annotate.py”, line 15, in open_pdf
File “C:\Users\colms\Documents\Python\Annotator_OpenAI\annotate.py”, line 46, in extract_text_and_get_suggestions
response = openai.ChatCompletion.create(
File “C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\lib_old_api.py”, line 39, in call
raise APIRemovedInV1(symbol=self._symbol)

import tkinter as tk
from tkinter import filedialog
import fitz # PyMuPDF
import openai
from tkinter import scrolledtext

Set your OpenAI API key

openai.api_key = ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’

Function to open a PDF file

def open_pdf():
file_path = filedialog.askopenfilename(filetypes=[(“PDF files”, “*.pdf”)])
if file_path:

Function to display PDF in the GUI

def display_pdf(file_path):
pdf_document = fitz.open(file_path)
page_count = len(pdf_document)

for page_num in range(page_count):
    page = pdf_document.load_page(page_num)
    pix = page.get_pixmap()
    img_path = f"temp_page_{page_num}.png"

    img = tk.PhotoImage(file=img_path)
    img_label = tk.Label(pdf_canvas, image=img)
    img_label.image = img  # Keep a reference to prevent garbage collection
    pdf_canvas.create_window(0, page_num * img.height(), anchor="nw", window=img_label)

# Configure the canvas scroll region

Function to extract text from PDF and get annotation suggestions

def extract_text_and_get_suggestions(file_path):
pdf_document = fitz.open(file_path)
page_count = len(pdf_document)

for page_num in range(page_count):
    page = pdf_document.load_page(page_num)
    text = page.get_text()

    # Get suggestions from OpenAI
    response = openai.ChatCompletion.create(
            {"role": "system", "content": "You are an expert"},
            {"role": "user", "content": f"Here is a page: {text}. Please suggest the correct annotations for each question on this page."}

    suggestions = response.choices[0].message["content"].strip()
    display_suggestions(suggestions, page_num)

Function to display suggestions in the GUI

def display_suggestions(suggestions, page_num):
suggestions_box.insert(tk.END, f"Suggestions for Page {page_num + 1}:\n")
suggestions_box.insert(tk.END, suggestions + “\n\n”)

Main GUI setup

root = tk.Tk()
root.title(“Annotation Tool”)

Frame for PDF Viewer with Scrollbar

pdf_frame = tk.Frame(root, width=600, height=800)
pdf_frame.pack(side=tk.LEFT, padx=10, pady=10, fill=tk.BOTH, expand=True)

pdf_canvas = tk.Canvas(pdf_frame)
pdf_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)

pdf_scrollbar = tk.Scrollbar(pdf_frame, orient=“vertical”, command=pdf_canvas.yview)
pdf_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)


Frame for Suggestions with Scrollbar

suggestions_frame = tk.Frame(root, width=400, height=800)
suggestions_frame.pack(side=tk.RIGHT, padx=10, pady=10, fill=tk.BOTH, expand=True)

suggestions_box = scrolledtext.ScrolledText(suggestions_frame, wrap=tk.WORD)
suggestions_box.pack(fill=tk.BOTH, expand=True)

Menu for opening PDF

menu = tk.Menu(root)
file_menu = tk.Menu(menu)
menu.add_cascade(label=“File”, menu=file_menu)
file_menu.add_command(label=“Open”, command=open_pdf)