diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-11-20 19:58:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-20 19:58:16 +0100 |
commit | ffb4b0d162cc29b1caa4539d854de37206804225 (patch) | |
tree | ea565c46ed908d2a6b4ef3fef1f100e68428aec3 /g4f/providers | |
parent | Update api.py (diff) | |
download | gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar.gz gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar.bz2 gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar.lz gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar.xz gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.tar.zst gpt4free-ffb4b0d162cc29b1caa4539d854de37206804225.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/providers/base_provider.py | 9 | ||||
-rw-r--r-- | g4f/providers/conversation.py | 2 | ||||
-rw-r--r-- | g4f/providers/response.py | 26 | ||||
-rw-r--r-- | g4f/providers/types.py | 5 |
4 files changed, 31 insertions, 11 deletions
diff --git a/g4f/providers/base_provider.py b/g4f/providers/base_provider.py index 9fa17fc3..b6df48e8 100644 --- a/g4f/providers/base_provider.py +++ b/g4f/providers/base_provider.py @@ -10,7 +10,8 @@ from inspect import signature, Parameter from typing import Callable, Union from ..typing import CreateResult, AsyncResult, Messages -from .types import BaseProvider, FinishReason +from .types import BaseProvider +from .response import FinishReason, BaseConversation from ..errors import NestAsyncioError, ModelNotSupportedError from .. import debug @@ -100,7 +101,7 @@ class AbstractProvider(BaseProvider): ) @classmethod - def get_parameters(cls) -> dict: + def get_parameters(cls) -> dict[str, Parameter]: return signature( cls.create_async_generator if issubclass(cls, AsyncGeneratorProvider) else cls.create_async if issubclass(cls, AsyncProvider) else @@ -258,7 +259,7 @@ class AsyncGeneratorProvider(AsyncProvider): """ return "".join([ str(chunk) async for chunk in cls.create_async_generator(model, messages, stream=False, **kwargs) - if not isinstance(chunk, (Exception, FinishReason)) + if not isinstance(chunk, (Exception, FinishReason, BaseConversation)) ]) @staticmethod @@ -307,4 +308,4 @@ class ProviderModelMixin: elif model not in cls.get_models() and cls.models: raise ModelNotSupportedError(f"Model is not supported: {model} in: {cls.__name__}") debug.last_model = model - return model + return model
\ No newline at end of file diff --git a/g4f/providers/conversation.py b/g4f/providers/conversation.py deleted file mode 100644 index 921810d3..00000000 --- a/g4f/providers/conversation.py +++ /dev/null @@ -1,2 +0,0 @@ -class BaseConversation: - ...
\ No newline at end of file diff --git a/g4f/providers/response.py b/g4f/providers/response.py new file mode 100644 index 00000000..a4d1467a --- /dev/null +++ b/g4f/providers/response.py @@ -0,0 +1,26 @@ +from __future__ import annotations + +from abc import abstractmethod + +class ResponseType: + @abstractmethod + def __str__(self) -> str: + pass + +class FinishReason(): + def __init__(self, reason: str): + self.reason = reason + + def __str__(self) -> str: + return "" + +class Sources(ResponseType): + def __init__(self, sources: list[dict[str, str]]) -> None: + self.list = sources + + def __str__(self) -> str: + return "\n\n" + ("\n".join([f"{idx+1}. [{link['title']}]({link['url']})" for idx, link in enumerate(self.list)])) + +class BaseConversation(ResponseType): + def __str__(self) -> str: + return ""
\ No newline at end of file diff --git a/g4f/providers/types.py b/g4f/providers/types.py index e7ca32ee..d6d7cccd 100644 --- a/g4f/providers/types.py +++ b/g4f/providers/types.py @@ -3,7 +3,6 @@ from __future__ import annotations from abc import ABC, abstractmethod from typing import Union, Dict, Type from ..typing import Messages, CreateResult -from .conversation import BaseConversation class BaseProvider(ABC): """ @@ -98,10 +97,6 @@ class BaseRetryProvider(BaseProvider): ProviderType = Union[Type[BaseProvider], BaseRetryProvider] -class FinishReason(): - def __init__(self, reason: str): - self.reason = reason - class Streaming(): def __init__(self, data: str) -> None: self.data = data |