luli331/oppy_google
0
1import os2from dotenv import load_dotenv3 4load_dotenv()5 6 7def test_gemini_connection():8 from google import genai9 10 api_key = os.getenv("GOOGLE_API_KEY")11 assert api_key and api_key != "your_key_here", "GOOGLE_API_KEY not set in .env"12 13 client = genai.Client(api_key=api_key)14 15 # Use gemini-2.0-flash — update MODEL_NAME if hackathon provides different model16 MODEL_NAME = "gemini-2.0-flash"17 18 response = client.models.generate_content(19 model=MODEL_NAME,20 contents="Reply with exactly: OK",21 )22 assert "OK" in response.text23 print(f"Gemini OK (model={MODEL_NAME}): {response.text.strip()}")24 25 26def test_gemini_function_calling_api():27 """Verify the SDK supports the function calling API we need."""28 from google.genai import types29 30 assert hasattr(types.Part, "from_function_response"), (31 "types.Part.from_function_response not found — SDK version may be incompatible. "32 "Try: pip install --upgrade google-genai"33 )34 print("Gemini SDK function calling API: OK")35 36 37def test_huggingface_model():38 import torch39 from sentence_transformers import CrossEncoder40 41 model = CrossEncoder(42 "cross-encoder/ms-marco-MiniLM-L6-v2",43 default_activation_function=torch.nn.Sigmoid(),44 )45 pairs = [("urgent action required deadline missed", "Le product owner attend les corrections avant lundi. C'est bloquant.")]46 scores = model.predict(pairs)47 score = float(scores[0])48 assert 0.0 <= score <= 1.049 print(f"HuggingFace OK: score={score:.3f}")50 51 52if __name__ == "__main__":53 test_gemini_connection()54 test_gemini_function_calling_api()55 test_huggingface_model()56 print("\nAll smoke tests passed.")57 