Files
catonline_ai/vw-agentic-rag/tests/func_test.py

33 lines
1.1 KiB
Python
Raw Normal View History

2025-09-26 17:15:54 +08:00
import httpx
def get_embedding(text: str) -> list[float]:
"""Get embedding vector for text using the configured embedding service"""
api_key = "h7ARU7tP7cblbpIQFpFXnhxVdFwH9rLXP654UfSJd8xKCJzeg4VOJQQJ99AKACi0881XJ3w3AAABACOGTlOf"
model = "text-embedding-3-small"
base_url = "https://aoai-lab-jpe-fl.openai.azure.com/openai/deployments/text-embedding-3-small/embeddings?api-version=2024-12-01-preview"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
payload = {
"input": text,
"model": model
}
try:
response = httpx.post(f"{base_url}", json=payload, headers=headers )
response.raise_for_status()
result = response.json()
print(result)
return result["data"][0]["embedding"]
except Exception as e:
print(f"Failed to get embedding: {e}")
raise Exception(f"Embedding generation failed: {str(e)}")
if __name__ == "__main__":
print("Begin")
text = "Sample text for embedding"
result = get_embedding(text)
print(result)