Spaces:
Sleeping
Sleeping
| import os | |
| # Указываем путь к папке, которую мы разрешили в Dockerfile | |
| os.environ['G4F_DATA_DIRECTORY'] = '/tmp/har_and_cookies' | |
| from fastapi import FastAPI | |
| import g4f | |
| app = FastAPI() | |
| def home(): | |
| return {"status": "API is running"} | |
| async def ask(prompt: str): | |
| try: | |
| # Убираем явное указание провайдера. | |
| # Библиотека сама переберет все варианты (Blackbox, DuckDuckGo и др.) | |
| response = g4f.ChatCompletion.create( | |
| model=g4f.models.default, # Автовыбор модели | |
| messages=[{"role": "user", "content": prompt}], | |
| ) | |
| return {"answer": response} | |
| except Exception as e: | |
| return {"error": str(e)} |