测试用例和结果
This commit is contained in:
44
test/openrouter_chat_example.py
Normal file
44
test/openrouter_chat_example.py
Normal file
@ -0,0 +1,44 @@
|
||||
"""Quick demo call against the unified chat endpoint using the OpenRouter provider."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
import httpx
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
API_URL = "http://localhost:8000/v1/chat/completions"
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
payload = {
|
||||
"provider": "openrouter",
|
||||
"model": "anthropic/claude-3.5-sonnet",
|
||||
"messages": [
|
||||
{
|
||||
"role": "system",
|
||||
"content": "You are an API assistant that writes concise JSON only.",
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Return a JSON object describing this test invocation.",
|
||||
},
|
||||
],
|
||||
"temperature": 0.1,
|
||||
"max_tokens": 300,
|
||||
}
|
||||
|
||||
async with httpx.AsyncClient(timeout=httpx.Timeout(15.0)) as client:
|
||||
response = await client.post(API_URL, json=payload)
|
||||
print("Status:", response.status_code)
|
||||
try:
|
||||
print("Body:", response.json())
|
||||
except ValueError:
|
||||
print("Raw Body:", response.text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user