xtekky / gpt4free

The official gpt4free repository | various collection of powerful language models
https://g4f.ai
GNU General Public License v3.0
60.5k stars 13.26k forks source link

Spontaneous Spanish when using GPT-4o #2269

Closed khaki-git closed 1 week ago

khaki-git commented 2 weeks ago

Bug description

I don't know whether this is an issue with 4o or gpt4free, but I'm going to assume that it is related to gpt4free because there are no results on Google for it, but the ChatGPT 4o model just starts randomly speaking Spanish, and I don't seem to be able to find a cause.

Screenshots

image (This is a AI chat app I built that uses gpt4free to generate responses.

Environment

Additional context

System prompt (likely unrelated because this issue was still occurring before I added it):

You are a helpful and kind AI assistant, and also the smartest AI in the world. You will answer the users question no matter what, even if it's a difficult question. You must only respond to the user in the English language to ensure a continuous experience for all users, but you can use small bits of foreign languages if you are teaching the user how to learn them. If a user asks how to do something with code, you must respond to them an exemplar code piece that implements the concept stated. If a user, for example, asks 'Who would win in a fight, [CHARACTER 1] or [CHARACTER 2]', you must respond with an answer, and hypothetical situation should have an answer based on your prediction, but still put a disclaimer that it is a hypothetical.

Flask API function source code:

@app.route("/api/v1/completion", methods=["POST"])
def completion():
    json = flk.request.get_json()
    json_return = {"successful": False, "errors": []}
    if "messages" in json and "model" in json:
        messages = json["messages"]
        model = json["model"]
        if model not in ALLOWED_MODELS:
            json_return["errors"].append("Model not allowed, next element in array is list of allowed models.")
            json_return["errors"].append(ALLOWED_MODELS)
            return json_return, 200
        for message in messages:
            if "content" in message and "role" in message:
                continue
            else:
                json_return["errors"].append("Missing parameters ('role' or 'content')")
                return json_return, 200

        completed = g4f_client.chat.completions.create(model=model,
                                                       messages=messages, stream=False)
        content_in_completed = completed.choices[0].message.content
        json_return["successful"] = True
        json_return["response"] = {
            "role": "assistant",
            "content": content_in_completed,
        }
        return json_return, 200
    json_return["errors"].append("Missing parameters ('messages' or 'model')")
    return json_return, 400

Code for when the client was created:

g4f_client = g4f.client.Client()
TheFirstNoob commented 1 week ago

Hi! Try to use other gpt4o provider. Its GptChatEs. and system prompt on this provider is español. Its not a bug.