diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2024-09-07 21:37:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-07 21:37:24 +0200 |
commit | 07fa87b4d180259d1da86afb565e14ac3d60d50b (patch) | |
tree | d474a2bf8bd79cf94bfa48cbaca3917659dd19be /g4f/Provider/TeachAnything.py | |
parent | Merge pull request #2206 from Parthsadaria/patch-1 (diff) | |
parent | g4f/models.py g4f/Provider/MagickPen.py (diff) | |
download | gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar.gz gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar.bz2 gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar.lz gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar.xz gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar.zst gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.zip |
Diffstat (limited to 'g4f/Provider/TeachAnything.py')
-rw-r--r-- | g4f/Provider/TeachAnything.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/g4f/Provider/TeachAnything.py b/g4f/Provider/TeachAnything.py index 908dd56e..3d34293f 100644 --- a/g4f/Provider/TeachAnything.py +++ b/g4f/Provider/TeachAnything.py @@ -13,7 +13,7 @@ class TeachAnything(AsyncGeneratorProvider, ProviderModelMixin): url = "https://www.teach-anything.com" api_endpoint = "/api/generate" working = True - default_model = "llama-3-70b-instruct" + default_model = "llama-3.1-70b" @classmethod async def create_async_generator( @@ -38,9 +38,23 @@ class TeachAnything(AsyncGeneratorProvider, ProviderModelMixin): timeout=timeout ) as response: response.raise_for_status() + buffer = b"" async for chunk in response.content.iter_any(): - if chunk: - yield chunk.decode() + buffer += chunk + try: + decoded = buffer.decode('utf-8') + yield decoded + buffer = b"" + except UnicodeDecodeError: + # If we can't decode, we'll wait for more data + continue + + # Handle any remaining data in the buffer + if buffer: + try: + yield buffer.decode('utf-8', errors='replace') + except Exception as e: + print(f"Error decoding final buffer: {e}") @staticmethod def _get_headers() -> Dict[str, str]: |