When I use function calling, I cannot obtain the translation result correctly.
The results are normal when not using function calling.
When using the GPT-3.5-turbo-0613 model, I intended to translate into Korean, but it still returned English.
When using the GPT-4-0613 model, the returned result is still in English.
How can I use the function calling feature to obtain translation results correctly?
Thanks!
– The above content is translated from: ChatGPT.
Can you provide the exact request in plain text? So I can help to take a look.
Is Python code acceptable?
import openai
import json
# Load your API key from an environment variable or secret management service
openai.api_key = ""
def get_translate(from_lan, to_lan, result):
"""translate text from from_lan to to_lan"""
print("from_type", from_lan, "to_type", to_lan, ": ", result)
will_translate = "한국어로 번역: 'Are you English'"
# Step 1: send the conversation and available functions to GPT
messages = [{"role": "user", "content": will_translate}]
functions = [
{
"name": "translate_to_chinese",
"description": "translate text from from_lan to to_lan",
"parameters": {
"type": "object",
"properties": {
"from_lan": { "type": "string", "description": "Language type to be translated" },
"to_lan": { "type": "string", "description": "Language type of the translation result" },
"result": { "type": "string", "description": "Translation result" },
},
"required": ["from_lan", "to_lan", "result"],
},
}
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
messages=messages,
functions=functions,
function_call="auto", # auto is default, but we'll be explicit
)
print("response is", response)
Thanks!
1 Like
sps
June 20, 2023, 10:45am
4
Hi @bihacats
If you want the model to translate text for you, simply tell the model to translate user message to whatever language.
Function calling returns the function call in JSON. It doesn’t execute the function, that’s your responsibility.
I originally thought it would convert the output of ChatGPT into the JSON format I desired.
So, Function calling simply converts my request into a function that I can invoke, is that correct?