Refactor provider type determination to use 'chat' for non-image models and update download URL configuration

This commit is contained in:
hlohaus 2025-09-04 12:07:42 +02:00
parent 01e7af68c0
commit 2dfa807cfb
3 changed files with 11 additions and 7 deletions

View file

@ -5,10 +5,14 @@ from os import path
sys.path.append(str(Path(__file__).parent.parent.parent)) sys.path.append(str(Path(__file__).parent.parent.parent))
# Enable logging
import g4f import g4f
g4f.debug.logging = True g4f.debug.logging = True
# Read auth files
from g4f.cookies import read_cookie_files
read_cookie_files()
def read_code(text): def read_code(text):
if match := re.search(r"```(python|py|)\n(?P<code>[\S\s]+?)\n```", text): if match := re.search(r"```(python|py|)\n(?P<code>[\S\s]+?)\n```", text):
return match.group("code") return match.group("code")
@ -114,9 +118,8 @@ And replace "gpt-3.5-turbo" with `model`.
print("Create code...") print("Create code...")
response = [] response = []
for chunk in g4f.ChatCompletion.create( for chunk in g4f.ChatCompletion.create(
model=g4f.models.gpt_4o, model=g4f.models.default,
messages=[{"role": "user", "content": prompt}], messages=prompt,
timeout=300,
stream=True, stream=True,
): ):
print(chunk, end="", flush=True) print(chunk, end="", flush=True)

View file

@ -372,7 +372,7 @@ class Api:
"vision": model in getattr(provider, "vision_models", []), "vision": model in getattr(provider, "vision_models", []),
"audio": model in getattr(provider, "audio_models", []), "audio": model in getattr(provider, "audio_models", []),
"video": model in getattr(provider, "video_models", []), "video": model in getattr(provider, "video_models", []),
"type": "image" if model in getattr(provider, "image_models", []) else "text", "type": "image" if model in getattr(provider, "image_models", []) else "chat",
} for model in models] } for model in models]
} }

View file

@ -24,6 +24,7 @@ GITHUB_REPOSITORY = f"xtekky/{ORGANIZATION}"
STATIC_DOMAIN = f"{PACKAGE_NAME}.dev" STATIC_DOMAIN = f"{PACKAGE_NAME}.dev"
STATIC_URL = f"https://{STATIC_DOMAIN}/" STATIC_URL = f"https://{STATIC_DOMAIN}/"
DIST_DIR = f"./{STATIC_DOMAIN}/dist" DIST_DIR = f"./{STATIC_DOMAIN}/dist"
DOWNLOAD_URL = f"https://raw.githubusercontent.com/{ORGANIZATION}/{STATIC_DOMAIN}/refs/heads/main/"
DEFAULT_MODEL = "openai/gpt-oss-120b" DEFAULT_MODEL = "openai/gpt-oss-120b"
JSDELIVR_URL = "https://cdn.jsdelivr.net/" JSDELIVR_URL = "https://cdn.jsdelivr.net/"
DOWNLOAD_URL = f"{JSDELIVR_URL}gh/{ORGANIZATION}/{STATIC_DOMAIN}/"
# DOWNLOAD_URL = f"https://raw.githubusercontent.com/{ORGANIZATION}/{STATIC_DOMAIN}/refs/heads/main/"