diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-11-24 17:43:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-24 17:43:45 +0100 |
commit | 804a80bc7cb788a77af169242b84c892ec4fc638 (patch) | |
tree | 2cefc811ce69809982621bf8b1d6e5c1cdd2b037 /g4f/gui/server/backend.py | |
parent | Merge pull request #2412 from xtekky/arm (diff) | |
download | gpt4free-804a80bc7cb788a77af169242b84c892ec4fc638.tar gpt4free-804a80bc7cb788a77af169242b84c892ec4fc638.tar.gz gpt4free-804a80bc7cb788a77af169242b84c892ec4fc638.tar.bz2 gpt4free-804a80bc7cb788a77af169242b84c892ec4fc638.tar.lz gpt4free-804a80bc7cb788a77af169242b84c892ec4fc638.tar.xz gpt4free-804a80bc7cb788a77af169242b84c892ec4fc638.tar.zst gpt4free-804a80bc7cb788a77af169242b84c892ec4fc638.zip |
Diffstat (limited to 'g4f/gui/server/backend.py')
-rw-r--r-- | g4f/gui/server/backend.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/g4f/gui/server/backend.py b/g4f/gui/server/backend.py index 3dcae546..3c87b0e2 100644 --- a/g4f/gui/server/backend.py +++ b/g4f/gui/server/backend.py @@ -3,7 +3,7 @@ import flask import os import logging import asyncio -from flask import request, Flask +from flask import Flask, request, jsonify from typing import Generator from werkzeug.utils import secure_filename @@ -42,17 +42,26 @@ class Backend_Api(Api): app (Flask): Flask application instance to attach routes to. """ self.app: Flask = app + + def jsonify_models(**kwargs): + response = self.get_models(**kwargs) + if isinstance(response, list): + return jsonify(response) + return response + + def jsonify_provider_models(**kwargs): + response = self.get_provider_models(**kwargs) + if isinstance(response, list): + return jsonify(response) + return response + self.routes = { '/backend-api/v2/models': { - 'function': self.get_models, + 'function': jsonify_models, 'methods': ['GET'] }, '/backend-api/v2/models/<provider>': { - 'function': self.get_provider_models, - 'methods': ['GET'] - }, - '/backend-api/v2/image_models': { - 'function': self.get_image_models, + 'function': jsonify_provider_models, 'methods': ['GET'] }, '/backend-api/v2/providers': { |