Followup question - using 1 or 2 requests?

Hello - i translate a hebraic text to english using the following code

        resp = openai.ChatCompletion.create(
          model = "gpt-3.5-turbo",
          messages=[{"role": "user", "content": wText}],
          request_timeout = 600, 
          temperature = 0,
        )

And the text looks like:

f'Translate the following Hebraic text to English: "{wText}"'

this works generally fine.
As a follow up i would now like to fix the grammar in the translated english text.

Should i create a follow up request to openAI?
Or shoudl i integrate this grammar fixing the the initial question?
And when its better to do a second new request - can i somehow use the previous question as basis or do i have to provide
the full translated text again to the second question?

I think yopu are asking how to continue the same conversation on with extra questions? if so you can simply use the append function in python to add a new role to the messages structure, first add the reply from the AI under the “assistant” role and then add the next question from the user with a “user” role and then send that entire message structure to the API again.

You’d end up with a message structure that looks something like this

messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Hello"},
        {"role": "assistant", "content": "Hello, how can I help you"},
        {"role": "user", "content": "What is more stylish Pikachu or Neo"},
        {"role": "assistant", "content": "Well Neo of course"},
        {"role": "user", "content": "Why?"},
        {"role": "assistant", "content": "Well Pikachu is naked! there is no style in that"},
    ]

with you having added all of the extra replies and new questions to the structure with a messages.append command.

I would use a System message for the instructions and ask it to translate into grammatically correct English.

Something like this maybe…

resp = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are a language model that can translate Hebraic text into grammatically correct English. When given Hebraic text, you translate it to natural language English."},
        {"role": "user", "content": f' "{wText}"'}
    ],
    request_timeout=600,
    temperature=0
)

That would be what I tried first.

If that isn’t good enough quality, you could try something like this (which would be two requests)…

resp = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are a language model that can translate Hebraic text into grammatically correct English. When given Hebraic text, you translate it to natural language English."},
        {"role": "user", "content": f' "{wText}"'},
        {"role": "assistant", "content": "[Assistant's translation goes here]"},
        {"role": "user", "content": "Please correct any grammar mistakes in the translated text."}
    ],
    request_timeout=600,
    temperature=0
)

Give it a shot and let us know.

1 Like

@PaulBellow
thx for the response

The first request is clear for me - but for the second example with the 2 requests i am not sure -

I have to send 2 seperate requests -

1st request:

resp = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are a language model that can translate Hebraic text into grammatically correct English. When given Hebraic text, you translate it to natural language English."},
        {"role": "user", "content": f' "{wText}"'},
    ],
    request_timeout=600,
    temperature=0
)

2nd request:

resp = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "system", "content": "You are a language model that can translate Hebraic text into grammatically correct English. When given Hebraic text, you translate it to natural language English."},
        {"role": "assistant", "content": "***here goes the output from the 1st request***"},
        {"role": "user", "content": "Please correct any grammar mistakes in the translated text."}
    ],
    request_timeout=600,
    temperature=0
)

Correct?
Or can i do this somehow with one request in python (and internally openai makes 2 requesets out of that?
But how should this work cause i don´t have this information when i am calling the request: [Assistant’s translation goes here]

Yeah, you would need two API requests as OpenAI doesn’t make multiple requests with one prompt.

You send the first request, wait for answer. Append the user’s message and the translation to the prompt (as user and assistant messages) then send again…