/
Nekzes00
/
AIBOT_with_OpenRouterAPI
Обзор
Документация
Войти
/
Nekzes00
/
AIBOT_with_OpenRouterAPI
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
FastApi_Bot.py
45 строк
1 KB
Nekzes00
create FastApi_Bot.py
03 дек 2025, 21:38
03 дек 2025, 21:38
8d29f01
Код
Авторство
О чём код?
from openai import OpenAI from fastapi import FastAPI app = FastAPI() client = OpenAI( base_url="https://openrouter.ai/api/v1", api_key="YOUR API TOKEN", ) def response_to_AI(content_for_api): response = client.chat.completions.create( model="MODEL NAME (пример: x-ai/grok-4.1-fast:free)", messages=[ { "role": "user", "content": content_for_api } ], extra_body={"reasoning": {"enabled": True}} ) response_1 = response.choices[0].message return response_1.content @app.get("/") def home(): return { "message": "AI API Server is running! 🚀", "endpoints": { "ai_endpoint": "GET /response/{your_text}", "example": "http://localhost:8000/response/Привет, как дела?", "docs": "http://localhost:8000/docs" } } @app.get("/response/{data}") def response_hendlery(data: str): print(f"Request: {data}") ai_response = response_to_AI(data) return { 'output': f'{ai_response}', 'status': '1' }