forked from google/adk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_installation.py
More file actions
198 lines (162 loc) · 6.33 KB
/
test_installation.py
File metadata and controls
198 lines (162 loc) · 6.33 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env python3
"""
Teste Rápido: Validação da Instalação ADK + LiteLLM
Execute este script para verificar se tudo está configurado corretamente.
"""
import sys
import os
from typing import Dict, List
def test_imports() -> Dict[str, bool]:
"""Testa as importações necessárias"""
results = {}
# Testar importações básicas
try:
from google.adk import Agent
results["google.adk.Agent"] = True
except ImportError as e:
results["google.adk.Agent"] = False
print(f"❌ Erro ao importar Agent: {e}")
try:
from google.adk.models.lite_llm import LiteLlm
results["google.adk.models.lite_llm.LiteLlm"] = True
except ImportError as e:
results["google.adk.models.lite_llm.LiteLlm"] = False
print(f"❌ Erro ao importar LiteLlm: {e}")
try:
from google.adk.sessions.in_memory_session_service import InMemorySessionService
results["InMemorySessionService"] = True
except ImportError as e:
results["InMemorySessionService"] = False
print(f"❌ Erro ao importar InMemorySessionService: {e}")
try:
from google.adk.runners import Runner
results["google.adk.runners.Runner"] = True
except ImportError as e:
results["google.adk.runners.Runner"] = False
print(f"❌ Erro ao importar Runner: {e}")
try:
from google.genai import types
results["google.genai.types"] = True
except ImportError as e:
results["google.genai.types"] = False
print(f"❌ Erro ao importar types: {e}")
try:
import litellm
results["litellm"] = True
except ImportError as e:
results["litellm"] = False
print(f"❌ Erro ao importar litellm: {e}")
return results
def check_api_keys() -> Dict[str, bool]:
"""Verifica se as chaves de API estão configuradas"""
keys_to_check = {
"OPENAI_API_KEY": "OpenAI",
"ANTHROPIC_API_KEY": "Anthropic",
"GOOGLE_API_KEY": "Google AI",
"GOOGLE_CLOUD_PROJECT": "Google Cloud",
"COHERE_API_KEY": "Cohere",
"MISTRAL_API_KEY": "Mistral AI"
}
results = {}
for key, service in keys_to_check.items():
results[service] = bool(os.getenv(key))
return results
def test_agent_creation() -> Dict[str, bool]:
"""Testa a criação de agentes básicos"""
results = {}
try:
from google.adk import Agent
from google.adk.models.lite_llm import LiteLlm
# Teste com modelo OpenAI (mesmo sem chave, deve criar o objeto)
agent = Agent(
model=LiteLlm(model="openai/gpt-4o"),
name="test_agent",
description="Agente de teste"
)
results["Criação de Agente OpenAI"] = True
except Exception as e:
results["Criação de Agente OpenAI"] = False
print(f"❌ Erro ao criar agente OpenAI: {e}")
try:
from google.adk import Agent
from google.adk.models.lite_llm import LiteLlm
# Teste com modelo Anthropic
agent = Agent(
model=LiteLlm(model="anthropic/claude-3-sonnet-20240229"),
name="test_claude",
description="Agente Claude de teste"
)
results["Criação de Agente Claude"] = True
except Exception as e:
results["Criação de Agente Claude"] = False
print(f"❌ Erro ao criar agente Claude: {e}")
return results
def print_results(title: str, results: Dict[str, bool]):
"""Imprime os resultados de forma organizada"""
print(f"\n📋 {title}")
print("=" * 60)
success_count = 0
for item, success in results.items():
status = "✅" if success else "❌"
print(f"{status} {item}")
if success:
success_count += 1
print("-" * 60)
print(f"✅ {success_count}/{len(results)} itens passaram no teste")
return success_count == len(results)
def main():
"""Função principal do teste"""
print("🔍 Teste de Validação: ADK + LiteLLM")
print("=" * 80)
print("Este script verifica se a instalação está funcionando corretamente.")
print()
# Informações do Python
print(f"🐍 Python: {sys.version}")
print(f"📁 Diretório atual: {os.getcwd()}")
print()
# Teste de importações
import_results = test_imports()
imports_ok = print_results("Importações", import_results)
# Verificação de chaves de API
api_results = check_api_keys()
apis_ok = print_results("Chaves de API Configuradas", api_results)
# Teste de criação de agentes
if imports_ok:
agent_results = test_agent_creation()
agents_ok = print_results("Criação de Agentes", agent_results)
else:
agents_ok = False
print("\n⚠️ Pulando teste de criação de agentes devido a erros de importação")
# Resumo final
print("\n" + "=" * 80)
print("📊 RESUMO FINAL")
print("=" * 80)
if imports_ok:
print("✅ Importações: SUCESSO - Todas as bibliotecas estão funcionando")
else:
print("❌ Importações: FALHA - Problemas com bibliotecas")
api_count = sum(api_results.values())
if api_count > 0:
print(f"✅ APIs: {api_count} serviços configurados")
else:
print("⚠️ APIs: Nenhuma chave configurada (opcional para testes)")
if agents_ok:
print("✅ Agentes: SUCESSO - Criação de agentes funcionando")
else:
print("❌ Agentes: FALHA - Problemas na criação de agentes")
# Recomendações
print("\n💡 PRÓXIMOS PASSOS:")
if not imports_ok:
print(" 1. Reinstale as dependências: pip install google-adk litellm")
print(" 2. Verifique se está no ambiente Python correto")
elif api_count == 0:
print(" 1. Configure pelo menos uma chave de API no arquivo .env")
print(" 2. Execute: python examples/multi_model_examples.py")
else:
print(" ✨ Tudo configurado! Execute os exemplos:")
print(" 📚 python examples/multi_model_examples.py")
print(" 📖 Consulte: docs/ADK_LITELLM_GUIDE.md")
print("\n🎯 Status geral:", "PRONTO PARA USO" if (imports_ok and agents_ok) else "PRECISA DE AJUSTES")
print("=" * 80)
if __name__ == "__main__":
main()