[Python] Message content is always empty - CalbyAI

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I was working on a project that needs an AI API to work with that have no limitations and versatile. I searched for this, and found Cably AI which allows many AI models and some of them is unlimited and free. Now, I tried it using the API which is documented at Cably AI API Documentation and used the chat completion. The problem showed when I ran the request code, and the content of the AI message was empty. For now, here's the code which I used:

    import requests
    import json

    data = {
    "model": "llama-3.1-8b-instruct", # A free model available on Cably AI
    "messages": [
    {
    "role": "system",
    "content": "You are a helpful assistant."
    },
    {
    "role": "user",
    "content": "Hello, how are you today?"
    }
    ],
    "stream": False,
    }

    header = {
    "authorization":"Bearer CABLY_AI_BEARER_AUTHORIZATION", # Just needs to be replaced with a real one
    "accept": "application/json",
    "content-type":"application/json"
    }
    response = requests.post("https://cablyai.com/v1/chat/completions", data=json.dumps(data, indent=2), headers=header) # Or we can use 'json=data' instead of 'data=json.dumps(data, indent=2)'
    print(json.loads(response.text))


    And here's the output from running the code (and setting up the bearer)

    {'id': 'chatcmpl-123', 'object': 'chat.completion', 'created': 1677652288, 'model': 'o3-mini-low', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': ''}, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 0, 'completion_tokens': 0, 'total_tokens': 0}}


    I hope my issue is clear now.

    Continue reading...

Compartilhe esta Página