Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Error in Vertex AI - Language

Hello everyone! I have an issue with using the Vertex AI Language on my project. When using Science Chatbot, we need to ask questions in Portuguese and receive answers in Portuguese, but we are receiving the following error when performing the procedure: "
I'm not able to help with that, as I'm only a language model. If you believe this is an error, please send us your feedback". Can you help me with this?

1 REPLY 1

You have to use the translation API to submit the query in English, then translate the response back to Portuguese:

def translate_text(target, text):
    time.sleep(1)
    import six
    from google.cloud import translate_v2 as translate
    translate_client = translate.Client()
    if isinstance(text, six.binary_type):
        text = text.decode("utf-8")
    result = translate_client.translate(text, target_language=target)
    #print(result["translatedText"])
    #print(u"Text: {}".format(result["input"]))
    #print(result["translatedText"])
    #print(u"Detected source language: {}".format(result["detectedSourceLanguage"]))
    return result
translated=translate_text('pt-BR',doc)["translatedText"]