mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-12-25 12:16:17 +03:00
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
from __future__ import annotations
|
|
from typing import Any, Dict
|
|
import inspect
|
|
|
|
from aiohttp import ClientSession
|
|
|
|
from ..typing import AsyncResult, Messages
|
|
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
|
|
from .helper import format_prompt
|
|
from .airforce.AirforceChat import AirforceChat
|
|
from .airforce.AirforceImage import AirforceImage
|
|
|
|
class Airforce(AsyncGeneratorProvider, ProviderModelMixin):
|
|
url = "https://api.airforce"
|
|
api_endpoint_completions = AirforceChat.api_endpoint_completions
|
|
api_endpoint_imagine2 = AirforceImage.api_endpoint_imagine2
|
|
working = True
|
|
supports_stream = AirforceChat.supports_stream
|
|
supports_system_message = AirforceChat.supports_system_message
|
|
supports_message_history = AirforceChat.supports_message_history
|
|
|
|
default_model = AirforceChat.default_model
|
|
models = [*AirforceChat.text_models, *AirforceImage.image_models]
|
|
|
|
model_aliases = {
|
|
**AirforceChat.model_aliases,
|
|
**AirforceImage.model_aliases
|
|
}
|
|
|
|
@classmethod
|
|
def get_model(cls, model: str) -> str:
|
|
if model in cls.models:
|
|
return model
|
|
elif model in cls.model_aliases:
|
|
return cls.model_aliases[model]
|
|
else:
|
|
return cls.default_model
|
|
|
|
@classmethod
|
|
async def create_async_generator(cls, model: str, messages: Messages, **kwargs) -> AsyncResult:
|
|
model = cls.get_model(model)
|
|
|
|
provider = AirforceChat if model in AirforceChat.text_models else AirforceImage
|
|
|
|
if model not in provider.models:
|
|
raise ValueError(f"Unsupported model: {model}")
|
|
|
|
# Get the signature of the provider's create_async_generator method
|
|
sig = inspect.signature(provider.create_async_generator)
|
|
|
|
# Filter kwargs to only include parameters that the provider's method accepts
|
|
filtered_kwargs = {k: v for k, v in kwargs.items() if k in sig.parameters}
|
|
|
|
# Add model and messages to filtered_kwargs
|
|
filtered_kwargs['model'] = model
|
|
filtered_kwargs['messages'] = messages
|
|
|
|
async for result in provider.create_async_generator(**filtered_kwargs):
|
|
yield result
|