| from fastapi import FastAPI |
|
|
| import demo |
| import g4f.api |
| import g4f.Provider |
| from g4f.Provider import BackendApi |
|
|
| BackendApi.working = True |
| BackendApi.url = demo.url |
| BackendApi.headers = demo.headers |
|
|
| g4f.Provider.__map__["Feature"] = g4f.Provider.BackendApi |
|
|
| def create_app(): |
| g4f.debug.logging = True |
| g4f.api.AppConfig.gui = True |
| g4f.api.AppConfig.demo = True |
|
|
| app = FastAPI() |
|
|
| |
| app.add_middleware( |
| g4f.api.CORSMiddleware, |
| allow_origin_regex=".*", |
| allow_credentials=True, |
| allow_methods=["*"], |
| allow_headers=["*"], |
| ) |
|
|
| api = g4f.api.Api(app) |
|
|
| api.register_routes() |
| api.register_authorization() |
| api.register_validation_exception_handler() |
|
|
| gui_app = g4f.api.WSGIMiddleware(g4f.api.get_gui_app(g4f.api.AppConfig.demo)) |
| app.mount("/", gui_app) |
|
|
| return app |
|
|
| app = create_app() |