provider_init.py 824 B

12345678910111213141516171819202122232425262728293031323334
  1. from pathlib import Path
  2. def main():
  3. content = create_content()
  4. with open("g4f/provider/__init__.py", "w", encoding="utf-8") as f:
  5. f.write(content)
  6. def create_content():
  7. path = Path()
  8. paths = path.glob("g4f/provider/*.py")
  9. paths = [p for p in paths if p.name not in ["__init__.py", "base_provider.py"]]
  10. classnames = [p.stem for p in paths]
  11. import_lines = [f"from .{name} import {name}" for name in classnames]
  12. import_content = "\n".join(import_lines)
  13. classnames.insert(0, "BaseProvider")
  14. all_content = [f' "{name}"' for name in classnames]
  15. all_content = ",\n".join(all_content)
  16. all_content = f"__all__ = [\n{all_content},\n]"
  17. return f"""from .base_provider import BaseProvider
  18. {import_content}
  19. {all_content}
  20. """
  21. if __name__ == "__main__":
  22. main()