File size: 1,707 Bytes
ead2510 |
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 |
import os
import uvicorn
import argparse
from rich.console import Console
from rich.panel import Panel
from dotenv import load_dotenv
# Load environment variables from .env file if present
load_dotenv()
console = Console()
def main():
parser = argparse.ArgumentParser(description='Run the OpenAI-compatible API server for DeepInfra')
parser.add_argument('--host', default='0.0.0.0', help='Host to bind the server to')
parser.add_argument('--port', type=int, default=8000, help='Port to bind the server to')
parser.add_argument('--reload', action='store_true', help='Enable auto-reload for development')
args = parser.parse_args()
console.print(Panel.fit(
"[bold green]DeepInfra OpenAI-Compatible API Server[/bold green]\n"
f"Starting server on http://{args.host}:{args.port}\n"
"Press Ctrl+C to stop the server.",
title="Server Info",
border_style="blue"
))
# Additional info on endpoints
console.print("[bold cyan]Available endpoints:[/bold cyan]")
console.print("- [yellow]/v1/models[/yellow] - List available models")
console.print("- [yellow]/v1/chat/completions[/yellow] - Chat completions endpoint")
console.print("- [yellow]/v1/completions[/yellow] - Text completions endpoint")
console.print("- [yellow]/health[/yellow] - Health check endpoint")
console.print("\nAPI documentation available at [link]http://localhost:8000/docs[/link]")
# Run the server
uvicorn.run(
"openai_compatible_api:app",
host=args.host,
port=args.port,
reload=args.reload
)
if __name__ == "__main__":
main()
|