File size: 2,608 Bytes
2cdadb6 e154153 281cb2d e154153 2cdadb6 e154153 2cdadb6 1d1b0f1 2cdadb6 edb14b7 2cdadb6 7d44776 3d5dc7e 2cdadb6 499f79d |
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 |
import os
import pytest
from fastapi.testclient import TestClient
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from main import app
@pytest.fixture
def test_client():
with TestClient(app) as client:
yield client
@pytest.fixture
def api_key():
return os.environ.get("API")
@pytest.fixture
def get_model():
return os.environ.get("MODEL", "claude-3-5-sonnet")
def test_request_model(test_client, api_key, get_model):
request_data = {
"model": get_model,
"messages": [
{
"role": "user",
"content": "say test"
}
],
"max_tokens": 4096,
"stream": True,
"temperature": 0.5,
"top_p": 1.0,
"presence_penalty": 0.0,
"frequency_penalty": 0.0,
"n": 1,
"user": "user",
"tools": [
{
"type": "function",
"function": {
"name": "get_search_results",
"description": "Search Google to enhance knowledge.",
"parameters": {
"type": "object",
"properties": {
"prompt": {
"type": "string",
"description": "The prompt to search."
}
},
"required": ["prompt"]
}
}
},
{
"type": "function",
"function": {
"name": "get_url_content",
"description": "Get the webpage content of a URL.",
"parameters": {
"type": "object",
"properties": {
"url": {
"type": "string",
"description": "The URL to request."
}
},
"required": ["url"]
}
}
}
],
"tool_choice": "auto"
}
headers = {
'Content-Type': 'application/json',
"Authorization": f"Bearer {api_key}"
}
response = test_client.post("/v1/chat/completions", json=request_data, headers=headers)
for line in response.iter_lines():
print(line.lstrip("data: "))
assert 200 <= response.status_code < 300
if __name__ == "__main__":
pytest.main(["-s", "test/provider_test.py"]) |