File size: 1,837 Bytes
bc6d235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
import requests
from dotenv import load_dotenv

def test_mistral():
    print("--- Teste de Ambiente AKIRA ---")
    
    # 1. Testar carregamento do .env
    dotenv_path = os.path.join(os.getcwd(), ".env")
    if os.path.exists(dotenv_path):
        load_dotenv(dotenv_path)
        print(f"✅ Arquivo .env encontrado em: {dotenv_path}")
    else:
        print("❌ Arquivo .env NÃO encontrado no diretório atual.")
        return

    mistral_key = os.getenv("MISTRAL_API_KEY")
    if not mistral_key or mistral_key == "sua_chave_aqui":
        print("❌ MISTRAL_API_KEY não configurada corretamente no .env")
        return
    else:
        print(f"✅ MISTRAL_API_KEY carregada (Início: {mistral_key[:5]}...)")

    # 2. Testar chamada real para a Mistral
    print("\n--- Testando API Mistral ---")
    url = "https://api.mistral.ai/v1/chat/completions"
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {mistral_key}"
    }
    data = {
        "model": "mistral-tiny",
        "messages": [{"role": "user", "content": "Oi, você está funcionando? Responda curto."}],
        "max_tokens": 50
    }

    try:
        response = requests.post(url, headers=headers, json=data, timeout=10)
        if response.status_code == 200:
            result = response.json()
            message = result['choices'][0]['message']['content']
            print(f"✅ API Mistral respondendo com sucesso!")
            print(f"💬 Resposta: {message}")
        else:
            print(f"❌ Erro na API Mistral: Status {response.status_code}")
            print(f"🔍 Detalhes: {response.text}")
    except Exception as e:
        print(f"❌ Erro ao conectar com API Mistral: {e}")

if __name__ == "__main__":
    test_mistral()