#openai gpt turbo 3.5 help

6 messages · Page 1 of 1 (latest)

narrow dew
#
import openai
import pyperclip
import time

openai.api_key = "redacted"

prev_clipboard_text = pyperclip.paste()

while True:

    clipboard_text = pyperclip.paste()


    if clipboard_text != prev_clipboard_text:

        prompt = f"Translate the following {source_lang} text into {target_lang}: '{clipboard_text}'"
        response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
          {"role": "system", "content": "translate any japanese text to english"},
          {"role": "user", "content": "{clipboard_text}"}
    ]
)


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

        filename = "translation.txt"
        with open(filename, "w", encoding="utf-8") as f:
            f.write(clipboard_text + "=" + output_text + "\n")

        print("the translation is =" + clipboard_text + "=" + output_text + "\n")


        prev_clipboard_text = clipboard_text


    time.sleep(0.5)

with this code i am translating japanese text from the clipboard to english using the openai api, i am just stuck on how to give the gpt-3.5-turbo the prompt to use the variable clipboard_text as the japanese text that it needs to translate, if i do copy some text it will tell me that it has not received any japanese text to translate

narrow dew
#

it was working just fine giving the input as a variable with the davinci model engine thing whatever

final jasper
#

Your issue lies in "content": "{clipboard_text}"

#

This is not an fstring in python so {clipboard_text} is rendered as exactly "{clipboard_text}" and not the actual value of the clipboard text

#

Try changing "content": "{clipboard_text}" to "content": f"{clipboard_text}"

narrow dew