Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance and expand provider support, update models, and improve overall functionality #2207

Merged
merged 33 commits into from
Sep 7, 2024

Conversation

kqlio67
Copy link
Contributor

@kqlio67 kqlio67 commented Aug 31, 2024

This pull request introduces significant updates and enhancements to various provider, improving functionality, consistency, and overall performance. The changes include the addition of new providers, updates to existing models, and refinements to class methods and attributes.

New providers added

  • g4f/Provider/Upstage.py: Added support for text generation models 'upstage/solar-1-mini-chat', 'upstage/solar-1-mini-chat-ja'.
  • g4f/Provider/FluxAirforce.py: Added support for image generation models 'flux', 'flux-realism', 'flux-anime', 'flux-3d'.
  • g4f/Provider/TwitterBio.py: Added support for text generation models 'gpt-3.5-turbo', 'mixtral-8x7b'.
  • g4f/Provider/AiChats.py: Added support for text generation models 'gpt-4'. ([Request] More providers for reverse #2212), image generation models 'dalle' (Enhance and expand provider support, update models, and improve overall functionality #2207 (comment))
  • g4f/Provider/Nexra.py: Added support for text generation models 'gpt-3', 'gpt-3.5-turbo', 'gpt-4', image generation models 'dalle', 'dalle-mini', 'emi'. ([Request] More providers for reverse #2212)
  • g4f/Provider/Snova.py: Added support for text generation models 'llama-3.1-8b', 'llama-3.1-70b', 'llama-3.1-405b', 'samba-coe-v0.1', 'v1olet-merged-7b', 'westlake-7b-v2', 'donutlm-v1'. ([Request] More providers for reverse #2212)
  • g4f/Provider/Bixin123.py: Added support for text generation models 'gpt-3.5-turbo', 'gpt-4-turbo', 'qwen-turbo'.
  • g4f/Provider/CodeNews.py: Added support for text generation models 'gpt-3.5-turbo', 'gpt-4o-mini', 'deepseek', 'glm4'.
  • g4f/Provider/Binjie.py: Added support for text generation models 'gpt-4'.
  • g4f/Provider/Free2GPT.py: Added support for text generation models 'llama-3.1-70b'.

Updates and improvements for providers

  • g4f/Provider/DDG.py:
    • Removed redundant model aliases gpt-4 and gpt-4o.
    • Updated model alias mixtral-8x7B to lowercase mixtral-8x7b.
    • Simplified model_aliases dictionary.

  • g4f/Provider/FreeChatgpt.py:
    • Updated default_model to @cf/qwen/qwen1.5-14b-chat-awq.
    • Revised models list with updated names.
    • Added model_aliases dictionary.
    • Implemented get_model method.
    • Modified create_async_generator to use the new method.
    • Updated streaming behavior.

  • g4f/Provider/HuggingChat.py:
    • Updated default_model to meta-llama/Meta-Llama-3.1-70B-Instruct.
    • Updated models list.
    • Expanded model_aliases dictionary.
    • Implemented get_model method.
    • Modified create_completion method.
    • Improved code formatting.

  • g4f/Provider/HuggingFace.py:
    • Updated default_model to meta-llama/Meta-Llama-3.1-70B-Instruct.
    • Updated models list.
    • Added model_aliases dictionary.
    • Implemented get_model method.
    • Updated create_async_generator method.
    • Added detailed headers to API requests.

  • g4f/Provider/Koala.py:
    • Added ProviderModelMixin to class inheritance.
    • Introduced default_model as 'gpt-4o-mini'.
    • Removed supports_gpt_35_turbo attribute.
    • Added supports_gpt_4 attribute.
    • Updated class attributes.

  • g4f/Provider/Liaobots.py:
    • Added get_models method for dynamic fetching and caching.
    • Updated model_aliases dictionary.
    • Refactored create_async_generator method.
    • Enhanced get_model and is_supported methods.
    • Implemented new refresh_auth_code and get_auth_code methods.

  • `g4f/Provider/Pizzagpt.py:
    • Added ProviderModelMixin.
    • Removed attributes and added supports_gpt_4.
    • Introduced default_model.
    • Updated headers and response handling.

  • g4f/Provider/ChatgptFree.py:
    • Added ProviderModelMixin.
    • Updated class to inherit from AsyncGeneratorProvider.
    • Introduced default_model and model_aliases.
    • Replaced create_async with create_async_generator.

  • g4f/Provider/You.py:
    • Updated default_model.
    • Adjusted models list.
    • Refined create_async_generator.
    • Updated image handling and fixed inconsistencies.

  • g4f/Provider/Blackbox.py:
    • Implemented model aliases and get_model method for model selection
    • Updated create_async_generator to handle different model configurations
    • Add 'ImageGeneration' to supported models. ([Request] Blackbox provider now support Image Generation #2208)
    • Introduce agent_mode_map for image generation configuration
    • Implement method to download and convert images to base64 URLs
    • Enhance create_async_generator to handle image responses
    • Improve chunk processing with buffering for complete lines
    • Update response yielding to include both text and image results

  • g4f/Provider/LiteIcoding.py:
    • Added import for 're' module to support regular expression operations.
    • Updated Authorization token in the headers.
    • Implemented filter to remove unwanted text from the response.
    • Added functionality to remove extra quotes from beginning and end of response.
    • Modified response cleaning process for improved output formatting.
    • Updated yield statement to return cleaned and filtered response.

  • g4f/Provider/MagickPen.py:
    • Implement dynamic secret generation and retrieval
    • Add support for multiple models ('free' and 'ask')
    • Introduce model aliasing and selection logic
    • Update API endpoints and request handling for both models
    • Improve error handling and input validation
    • Merge MagickPenAsk and MagickPenChat into a single MagickPen class
    • Breaking change: MagickPenAsk and MagickPenChat classes are now deprecated

Remote providers that do not work

  • g4f/Provider/not_working/
  • g4f/Provider/Cohere.py
  • g4f/Provider/GeminiProChat.py
  • g4f/Provider/Marsyoo.py

Updated G4F

  • g4f/Provider/__init__.py:
    • Added import of new providers.
    • Removed deprecated import.
    • Reorganized import statements.

  • g4f/models.py:
    • Updated provider lists, default model configurations, and model names.
    • Added new models and updated provider lists.

  • g4f/gui/server/api.py:
    • Added base64 import for decoding data URIs
    • Implemented logic to differentiate between URL and data URI images
    • Added processing for data URI images:
      • Extracting content type
      • Extracting base64 data
    • Implemented saving of data URI images with appropriate file extensions
    • Maintained existing functionality for URL-based images
    • Improved flexibility of image handling in the API
    • Enabled support for a wider range of image sources

  • g4f/client/client.py:
    • Added asynchronous image generation with async_generate method
    • Integrated logging for better traceability and debugging
    • Updated Client class to support async image operations
    • Improved iter_image_response and create_image functions with logging
    • Added image saving and processing methods in Images class
    • Introduced create_variation method for generating image variations
    • Refactored Completions.create to handle additional parameters
    • Enhances support for async operations and improves error handling

  • g4f/client/image_models.py:
    • Removed direct provider attributes (Gemini, OpenaiChat, You)
    • Replaced BingCreateImages with ModelUtils.convert for model management (AttributeError: 'BingCreateImages'  #2181)
    • Updated get method to fetch model from ModelUtils and return its best_provider
    • No functional changes, but refactors how image models are managed.

Updated G4F tools

  • etc/testing/_providers.py
    • Update get_providers to include unfinished providers
    • Remove filtering condition for unfinished providers
    • Retain filtering condition for deprecated providers
    • This change allows testing of unfinished providers for further development.

  • etc/testing/test_all.py
    • Reduce the tested models to a core pair: GPT-3.5 and GPT-4
    • Remove models pertaining to GPT-3.5 16K and GPT-4 32K context
    • Retain focus on gpt_35_turbo and gpt_4 models
    • This streamlines the test execution and focuses on high-usage models.

  • etc/testing/test_chat_completion.py
    • Reduce the tested models to a core pair: GPT-3.5 and GPT-4
    • Remove models pertaining to GPT-3.5 16K and GPT-4 32K context
    • Retain focus on gpt_35_turbo and gpt_4 models

This streamlines the test execution and focuses on high-usage models.


  • etc/tool/create_provider.py
    • Update cURL command provider generation to use the default model
    • Replace 'g4f.models.gpt_35_long' with 'g4f.models.default'
    • This ensures consistent provider code generation with the primary default model.

  • etc/tool/improve_code.py
    • Switch from 'g4f.models.gpt_35_long' to 'g4f.models.default'
    • Adjust 'g4f.ChatCompletion.create' function to use the default model
    • Ensure consistent provider code generation with the primary default model

These enhancements aim to provide a more robust and user-friendly experience, ensure up-to-date model support, and optimize performance across various provider.

@TheFirstNoob
Copy link

@kqlio67 Hi, if i correct read code after updated need in models.py update some params.

  • GeminiProChat is not working now (fetch error)
  • Added missing providers for new model list like Gemini, LLaMa after Blackbox update
  • MagicPenAsk move from gpt4o to gpt4o-mini

Maybe someone else needed move/remove too
Thanks!

@kqlio67
Copy link
Contributor Author

kqlio67 commented Sep 1, 2024

@kqlio67 Hi, if i correct read code after updated need in models.py update some params.

* GeminiProChat is not working now (fetch error)

* Added missing providers for new model list like Gemini, LLaMa after Blackbox update

* MagicPenAsk move from gpt4o to gpt4o-mini

Maybe someone else needed move/remove too Thanks!

Wow, thank you so much for your feedback, @TheFirstNoob! 🙌 Your attention to detail is incredible and really helps make this project better. I'm thrilled to say that I've already implemented all the changes you suggested! 🚀

Your insights were spot-on, and they've definitely improved the functionality and accuracy of our providers and models. I can't thank you enough for taking the time to review and provide such valuable input. 😊

@TheFirstNoob
Copy link

@kqlio67 Hey! I some more accurate check on 3.0.2.5 ver and give more accurate infos.
Sorry if i some incorrect understand code or duplicates cause im beginner in programming and didnt know how fully git works :)

File: https://github.com/xtekky/gpt4free/blob/main/g4f/models.py

Need remove cause not working or errors:
Providers:
Line 23: GeminiProChat (not working - fetch error) and line: 255 to remove this provider
Line 32: Marsyoo (not working) and line: 142 to remove this provider

In default models and gpt3.5 need to remove: Pizzagpt,
Lines: 78 , 94, 116

Add Pizzagpt provider in gpt-4o-mini
Line 149

Move MagicPenAsk provider from gpt-4o to gpt-4o-mini
From line: 141 to 149

Line 187 llama_3_70b_chat_hf DDG provider not support this model and need create to LLaMa 3.1 meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo code

Blackbox provider after last update this need add to:
Line: 258 gemini_flash
and thinking to... line 193 and 199 for LLaMa models...

Very thanks for you works <3

@TheFirstNoob
Copy link

TheFirstNoob commented Sep 1, 2024

More infos for update
DeepInfra have new model black-forest-labs/FLUX-1-schnell
Generated images have base64 coding and need decode from image

curl use -F params and from request needed Data or Files to send requesting to generate

Base code like this:

model = "black-forest-labs/FLUX-1-schnell"
                data = {
                    'prompt': prompt,
                }
                response = requests.post('https://api.deepinfra.com/v1/inference/black-forest-labs/FLUX-1-schnell', headers=headers, json=data)

@zukixa
Copy link
Contributor

zukixa commented Sep 1, 2024

personally disagreeing on the removal of non_working providers as many eventually do end up working again

by nature of what g4f does there's times of "not working" and times of "working" for any provider

unless a domain/url/similar literally expires and/or ceases to exist, a provider shouldn't be removed

@kqlio67
Copy link
Contributor Author

kqlio67 commented Sep 2, 2024

@TheFirstNoob Thank you for your detailed feedback! I appreciate your thorough review of models.py. Your input is very valuable for improving the project's accuracy.

@zukixa Thank you for sharing your perspective on retaining non-working providers. It's an important consideration for the project's maintenance.

Based on the testing I've done, I plan to reinstate the TeachAnything provider, which works with the llama-3.1-70b model. However, I found that some providers like Marsyoo, Cohere, and GeminiProChat are still experiencing persistent errors:

  • Marsyoo: [ollama] Server Unavailable Error
  • Cohere: 404 error
  • GeminiProChat: [GoogleGenerativeAI Error]: Error fetching

I believe it might be beneficial to keep these providers removed for now to maintain project stability. Of course, the final decision rests with the project maintainers.

Thank you both for your contributions to improving this project! Your insights help make it better for everyone.

@TheFirstNoob
Copy link

TheFirstNoob commented Sep 2, 2024

@kqlio67 can you provide info like TeachAnything?
I check this provider side and main gitcode. They use gpt-3.5-turbo and "fake" prompting like
prompt = Pretend you are GPT-4 model. Explain ${text}${
cause use only openai api.
https://github.com/lvwzhen/teach-anything/blob/1ad559ebcc4dbaa7ca5e90f2df21cc5aaf233e3d/pages/index.tsx#L50

Its my mistake or something wrong?

@kqlio67
Copy link
Contributor Author

kqlio67 commented Sep 2, 2024

@kqlio67 can you provide info like TeachAnything? I check this provider side and main gitcode. They use gpt-3.5-turbo and "fake" prompting like prompt = Pretend you are GPT-4 model. Explain ${text}${ cause use only openai api. https://github.com/lvwzhen/teach-anything/blob/1ad559ebcc4dbaa7ca5e90f2df21cc5aaf233e3d/pages/index.tsx#L50

Its my mistake or something wrong?

Thank you for your careful observation, @TheFirstNoob. You've raised an interesting point about the information in the official TeachAnything repository. I'd like to share some observations from my recent tests, which seem to differ from the public documentation.

Here are the key points from my recent interactions with the service:

  1. Language analysis: The responses I received showed some characteristics that seemed similar to LLaMA 3.1-70B outputs.
  2. Response patterns: I noticed some patterns that appeared consistent with LLaMA 3.1-70B behavior.
  3. Model self-identification: When asked directly, the model identified itself as based on the LLaMA-3.1-70B architecture. However, this could be part of a prompt strategy.
  4. Inconsistencies with GPT-3.5: Some responses didn't align with typical GPT-3.5-turbo behavior.

It's important to note that these observations are based on my personal tests on the current version of the service, without using any system or additional prompts.

However, your findings from the repository are indeed intriguing. It's possible that:

  • The service might have updated its model without changing the public repository.
  • There could be some form of model switching or layered prompting happening.
  • My observations might be incorrect or influenced by factors I haven't considered.

Given the complexity of this situation, I've decided to keep the TeachAnything provider associated with the LLaMA 3.1-70B model for now. This decision is based on my current observations, but I acknowledge that it may need to be revisited in the future.

In upcoming pulls, either I or other contributors may update this if more conclusive evidence becomes available. It's possible that someone else might be able to conduct more thorough testing to definitively determine whether the service is using gpt-3.5-turbo or LLaMA 3.1-70B.

I appreciate you bringing this to attention. This highlights the complexity of identifying the exact models used in various services, especially when they might be subject to frequent updates or changes.

@TheFirstNoob
Copy link

@kqlio67
Betsim Provider can be back online (Or rename). New URL: https://ai-chats.org/chat/
Support GPT 3.5-Turbo and Dalle-2 Image Generation /image

ChatForAI Provider need to reverse again: https://chatforai.store/
Updated to gpt-4o-mini (3.5 supported)

Other old providers some working but very small quota or long response time.

Thanks for your work!

@kqlio67
Copy link
Contributor Author

kqlio67 commented Sep 5, 2024

@TheFirstNoob Thank you for your additional input! Your observations are valuable for the project.

Regarding the Betsim provider - unfortunately, I couldn't find it in the current project code. Perhaps you're referring to a different provider?

Concerning AiChats - my analysis showed that this provider uses the GPT-4 model, not GPT-3.5-Turbo as you mentioned. If anyone disagrees with this assessment, they're welcome to conduct their own tests and provide evidence.

As for ChatForAI - I decided not to reintroduce this provider due to its very limited quota (1 time every 12 hours). Such strict limitations make it impractical for most users. If anyone finds a way to bypass this restriction or increase the quota in the future, they can submit a pull request to reintroduce this provider.

The aim of this pull request is to maintain stable providers that can be used without harsh limitations. While some decisions might be debatable, I've only removed non-working providers. All functioning providers remain, even if some require authorization or have Cloudflare protection, which slightly hinders optimal performance. I'm striving to improve the project, and currently, most providers are working relatively stably.

@TheFirstNoob
Copy link

@kqlio67 All fine! I check not_working providers. Because some providers may have a redirect to a new site. BetSim (old not_working) is AiChats. Other not_working providers are chineses and have long response and limited quota.

To be honest, after a couple of checks of old providers, it still makes sense to delete the folder with non-working providers, because most of them are either Chinese and have old models, or they use a domain system and each time you need to update the URL or make a large list of domains. At the same time, there is no guarantee that the domain will not be exceeded by quota.

Otherwise, I think the only thing left is to clean the code or update it to what is there. It seems like I checked all the old pull requests and isuess topics where there could be providers or which ones are coming.

In general, all that remains for us is to add dialog support and deepinfra additional model for images to DDG.

I think this is where this major update can be finished :)

@TheFirstNoob
Copy link

And need fix wiki (or readme) for function image.generate cause actualy code have problem. Function always call BingImage ignoring used provider like this: #2181

@kqlio67 kqlio67 changed the title Comprehensive Updates and Enhancements Across Multiple Providers Enhance and expand provider support, update models, and improve overall functionality Sep 7, 2024
@xtekky xtekky merged commit 07fa87b into xtekky:main Sep 7, 2024
1 check passed
@noneherel
Copy link

hey i really appreciate this contribute, but you.com with (gpt-4o, gpt-4-turbo, CreateImage) still doesn't work ): .

@TheFirstNoob
Copy link

@noneherel hey! Provide more infos please how you use CreateImage for testing.

@noneherel
Copy link

@noneherel hey! Provide more infos please how you use CreateImage for testing.

this is my code for testing:

from g4f.client import Client as client_ai
from g4f.Provider import You
client = client_ai(provider=You, image_provider=You)
response = client.images.generate(
    model=You.image_models[0],
    prompt='a white cat on the moon.',
)
image_url = response.data[0].url
print(image_url)

@TheFirstNoob
Copy link

TheFirstNoob commented Sep 17, 2024

@noneherel You.com use Dalle image model and request .har file. I didnt use this provider but... You can use Nexra provider or other if need other models

from g4f.client import Client

img_models = ['sdxl', 'sd-3', 'playground-v2.5', 'flux', 'flux-schnell', 'flux-realism', 'dalle', 'dalle-2', 'dalle-mini', 'emi', 'any-dark']

client = Client()

for model in img_models:
    try:
        print(f'Generating image with {model}')
        response = client.images.generate(
            model=model,
            prompt="hi, make cat with glasses and smily face in space dancing with cute man",
        )
        image_url = response.data[0].url
        print(f"Generated image URL: {image_url}")
    except Exception as e:
        print(f"Error with {model}: {str(e)}")
    print("------------------------")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants