36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import asyncio
|
|
import aiohttp
|
|
import json
|
|
|
|
async def test_embed_with_key(key):
|
|
url = "http://localhost:11434/api/embed"
|
|
payload = {
|
|
"model": "snowflake-arctic-embed:latest",
|
|
"input": ["test"]
|
|
}
|
|
headers = {"Content-Type": "application/json"}
|
|
if key:
|
|
headers["Authorization"] = f"Bearer {key}"
|
|
async with aiohttp.ClientSession() as session:
|
|
try:
|
|
async with session.post(url, json=payload, headers=headers) as resp:
|
|
print(f"Status: {resp.status}")
|
|
if resp.status == 200:
|
|
data = await resp.json()
|
|
print("Success")
|
|
else:
|
|
text = await resp.text()
|
|
print("Error:", text)
|
|
except Exception as e:
|
|
print(f"Exception: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
# test with empty key
|
|
print("Testing with empty key:")
|
|
asyncio.run(test_embed_with_key(""))
|
|
# test with dummy key
|
|
print("\nTesting with dummy key 'governor':")
|
|
asyncio.run(test_embed_with_key("governor"))
|
|
# test with no Authorization header
|
|
print("\nTesting with no Authorization header:")
|
|
asyncio.run(test_embed_with_key(None)) |