can you fix this code to use the new openai api and embeddigs and model list?
# app.py
import os
import base64
import subprocess
import sys
import re

import openai
from openai import OpenAI
from bokeh.io import curdoc
from bokeh.layouts import row, column
from bokeh.models import (
    Button, Select, TextInput, Div, TextAreaInput,
    Tabs, Panel as BokehPanel, PreText, FileInput
)
from bokeh.events import ButtonClick

# OpenAI API Key from environment variable
openai_api_key = os.environ.get('OPENAI_API_KEY')
if not openai_api_key:
    raise ValueError("Please set the OPENAI_API_KEY environment variable.")

openai.api_key = openai_api_key

# Get list of available models from OpenAI
def get_available_models():
    models = openai.Model.list()
    model_ids = [model['id'] for model in models['data']]
    # Filter models to include only chat models
    model_options = [model_id for model_id in model_ids if 'gpt' in model_id]
    return model_options

model_options = get_available_models()

# Left Panel - Settings and Inputs
# Model Selection
model_select = Select(title="Model", value="gpt-3.5-turbo", options=model_options)

# Max Tokens Input with +/- buttons
max_tokens_input = TextInput(title="Max Tokens", value="1000")
increase_button = Button(label="+", width=30)
decrease_button = Button(label="-", width=30)

def increase_max_tokens():
    current_value = int(max_tokens_input.value)
    max_tokens_input.value = str(current_value + 100)

def decrease_max_tokens():
    current_value = int(max_tokens_input.value)
    new_value = max(current_value - 100, 0)
    max_tokens_input.value = str(new_value)

increase_button.on_click(increase_max_tokens)
decrease_button.on_click(decrease_max_tokens)

# Log Panel
log_div = Div(text='', sizing_mode='stretch_both', style={'overflow-y': 'scroll', 'height': '200px'})

# Left Panel Layout
left_panel = column(
    Div(text="<h2>Settings</h2>"),
    model_select,
    row(decrease_button, max_tokens_input, increase_button),
    Div(text="<h3>Log Panel</h3>"),
    log_div,
    sizing_mode='stretch_both'
)

# Central Pane - Tabs for Code and Files
tabs = Tabs(tabs=[])

# Attach File Input
file_input = FileInput(accept=".txt,.py,.md")

def file_input_callback(attr, old, new):
    if new:
        content = base64.b64decode(new)
        text = content.decode('utf-8')
        filename = file_input.filename
        code_area = PreText(text=text, sizing_mode='stretch_both')
        new_tab = BokehPanel(child=code_area, title=filename)
        tabs.tabs.append(new_tab)
        log_div.text += f"<p>Loaded file: {filename}</p>"
        file_input.value = ''

file_input.on_change('value', file_input_callback)

# Right Panel - Chat Interface
chat_output = Div(text='', sizing_mode='stretch_both', style={'overflow-y': 'scroll', 'height': '400px'})
chat_input = TextAreaInput(rows=4, sizing_mode='stretch_width')
send_button = Button(label="📨", button_type="success", width=50)

def extract_code_blocks(text):
    # Extract code blocks enclosed in triple backticks
    pattern = r'```(?:[\s\S]*?\n)?([\s\S]*?)```'
    matches = re.findall(pattern, text)
    return matches

def send_message():
    user_text = chat_input.value.strip()
    if not user_text:
        return

    # Prepare messages, including code and files from central pane
    messages = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
    
    # Include contents from the central pane
    for tab in tabs.tabs:
        content = tab.child.text
        messages.append({'role': 'system', 'content': f"Content from {tab.title}:\n{content}"})

    messages.append({'role': 'user', 'content': user_text})

    try:
        
        client = OpenAI()

        response = client.chat.completions.create(
            model="gpt-4o-mini",        
            #model=model_select.value,
            messages=messages,
            max_tokens=int(max_tokens_input.value)
        )

        assistant_reply = response['choices'][0]['message']['content']

        # Display conversation
        chat_output.text += f"<p><b>User:</b> {user_text}</p>"
        chat_output.text += f"<p><b>Assistant:</b> {assistant_reply}</p>"

        # Extract and display code blocks
        code_blocks = extract_code_blocks(assistant_reply)
        for i, code in enumerate(code_blocks):
            code_area = PreText(text=code, sizing_mode='stretch_both')
            new_tab = BokehPanel(child=code_area, title=f"Assistant Code {i+1}")
            tabs.tabs.append(new_tab)
            log_div.text += f"<p>Added code from assistant: Assistant Code {i+1}</p>"

        chat_input.value = ''

    except Exception as e:
        log_div.text += f"<p style='color:red;'>Error: {str(e)}</p>"

send_button.on_click(send_message)

# Chat Interface Layout
chat_interface = column(
    Div(text="<h2>Chat Interface</h2>"),
    chat_output,
    chat_input,
    row(send_button, file_input),
    sizing_mode='stretch_both'
)

# Terminal Panel at Bottom
terminal_output = Div(text='', sizing_mode='stretch_both', style={'overflow-y': 'scroll', 'height': '200px'})

# Run Code Button
play_button = Button(label="▶", button_type="success", width=50)

def run_code():
    if tabs.tabs:
        active_tab_idx = tabs.active
        active_tab = tabs.tabs[active_tab_idx]
        code = active_tab.child.text

        try:
            # Execute the code using subprocess
            process = subprocess.Popen([sys.executable, '-c', code],
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       text=True)

            stdout, stderr = process.communicate()

            if stdout:
                terminal_output.text += f"<pre>{stdout}</pre>"

            if stderr:
                terminal_output.text += f"<pre style='color:red;'>{stderr}</pre>"

            log_div.text += f"<p>Executed code from tab: {active_tab.title}</p>"

        except Exception as e:
            terminal_output.text += f"<pre style='color:red;'>Error: {str(e)}</pre>"
            log_div.text += f"<p style='color:red;'>Error executing code: {str(e)}</p>"
    else:
        terminal_output.text += "<pre style='color:red;'>No code to run.</pre>"

play_button.on_click(run_code)

# Main Panel Layout with Play Button
main_panel = column(
    row(Div(text="<h2>Code and Files</h2>"), play_button),
    tabs,
    Div(text="<h2>Terminal Output</h2>"),
    terminal_output,
    sizing_mode='stretch_both'
)

# Complete Layout
app_layout = row(
    left_panel,
    main_panel,
    chat_interface,
    sizing_mode='stretch_both'
)

# Add layout to the current document
curdoc().add_root(app_layout)
curdoc().title = "LLM Code Runner"


new openai api code:
from openai import OpenAI
client = OpenAI()

def get_embedding(text, model="text-embedding-3-small"):
   text = text.replace("\n", " ")
   return client.embeddings.create(input = [text], model=model).data[0].embedding

df['ada_embedding'] = df.combined.apply(lambda x: get_embedding(x, model='text-embedding-3-small'))
df.to_csv('output/embedded_1k_reviews.csv', index=False)

from openai import OpenAI
client = OpenAI()

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Who won the world series in 2020?"},
    {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
    {"role": "user", "content": "Where was it played?"}
  ]
)