Theb.py 925 B

12345678910111213141516171819202122232425262728
  1. import os
  2. import json
  3. import time
  4. import subprocess
  5. from ...typing import sha256, Dict, get_type_hints
  6. url = 'https://theb.ai'
  7. model = ['gpt-3.5-turbo']
  8. supports_stream = True
  9. needs_auth = False
  10. def _create_completion(model: str, messages: list, stream: bool, **kwargs):
  11. path = os.path.dirname(os.path.realpath(__file__))
  12. config = json.dumps({
  13. 'messages': messages,
  14. 'model': model}, separators=(',', ':'))
  15. cmd = ['python3', f'{path}/helpers/theb.py', config]
  16. p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  17. for line in iter(p.stdout.readline, b''):
  18. yield line.decode('utf-8')
  19. params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
  20. '(%s)' % ', '.join([f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])