|
|
import requests |
|
|
import json |
|
|
import os |
|
|
from dotenv import load_dotenv |
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
API_URL = os.getenv("MODAL_API_URL", "").strip() |
|
|
|
|
|
if not API_URL: |
|
|
raise ValueError("MODAL_API_URL not found in .env file. Please set it to your Modal endpoint URL.") |
|
|
|
|
|
def test_embeddings(): |
|
|
print(f"Testing API at: {API_URL}") |
|
|
|
|
|
|
|
|
payload = { |
|
|
"inputs": [ |
|
|
"Hello, this is a test sentence.", |
|
|
"Running text embeddings on Modal is fast." |
|
|
] |
|
|
} |
|
|
|
|
|
try: |
|
|
|
|
|
response = requests.post(API_URL, json=payload) |
|
|
|
|
|
|
|
|
response.raise_for_status() |
|
|
|
|
|
|
|
|
data = response.json() |
|
|
|
|
|
|
|
|
model_name = data.get("model", "Unknown") |
|
|
embeddings = data.get("embeddings", []) |
|
|
dims = data.get("dimensions", 0) |
|
|
|
|
|
print("\n--- Success! ---") |
|
|
print(f"Model used: {model_name}") |
|
|
print(f"Vector dimensions: {dims}") |
|
|
print(f"Number of texts embedded: {len(embeddings)}") |
|
|
|
|
|
|
|
|
if embeddings: |
|
|
print(f"\nFirst 5 values of first embedding:\n{embeddings[0][:5]}...") |
|
|
|
|
|
except requests.exceptions.RequestException as e: |
|
|
print(f"\nError calling API: {e}") |
|
|
if response is not None: |
|
|
print(f"Server response: {response.text}") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
test_embeddings() |