My API program cannot translate the PDF I uploaded

My API program cannot translate the PDF I uploaded. Please tell me what I did wrong?

import openai
import time
from ipywidgets import widgets
from IPython.display import display, clear_output

client = openai.Client(api_key='-',)

# Upload your knowledge base document
file = client.files.create(
    file=open("sample_data/療癒泉力.pdf", "rb"),
    purpose='assistants'
)


assistant = client.beta.assistants.create(
    name="api版翻譯",
    instructions="將文件翻譯成簡體中文",
    tools=[{"type": "code_interpreter"}],
    file_ids=[file.id],
    model="gpt-4-1106-preview"
)

thread = client.beta.threads.create(
  messages=[
    {
      "role": "user",
      "content": "翻譯成簡體中文",
      "file_ids": [file.id]
    }
  ]
)
message = client.beta.threads.messages.create(
  thread_id=thread.id,
  role="user",
  content="翻譯成簡體中文",
  file_ids=[file.id]
)
def chat_with_assistant():
    print("Welcome to the Customer Support Assistant! Ask any question, or type 'quit' to exit.")
    while True:
        user_input = input("You: ")
        if user_input.lower() == 'quit':
            break

        message = client.beta.threads.messages.create(
            thread_id=thread.id,
            role="user",
            content=user_input,
            file_ids=[file.id]
        )

        run = client.beta.threads.runs.create(
            thread_id=thread.id,
            assistant_id=assistant.id
        )

        while True:
            run_status = client.beta.threads.runs.retrieve(
                thread_id=thread.id,
                run_id=run.id
            )

            if run_status.completed_at is not None:
                break

            time.sleep(1)  # Sleep for a second
        messages = client.beta.threads.messages.list(
            thread_id=thread.id
        )

        # Assistant's response
        for msg in messages.data:
            if msg.role == 'assistant':
                for content in msg.content:
                    if content.type == 'text':
                        print("Assistant:", content.text.value)

chat_with_assistant()

send_button.on_click(send_to_assistant)

Is this an editable PDF or a scanned image?

1 Like