Forefront.py 1.2 KB

123456789101112131415161718192021222324252627282930
  1. import os
  2. import json
  3. import requests
  4. from ...typing import sha256, Dict, get_type_hints
  5. url = 'https://forefront.com'
  6. model = ['gpt-3.5-turbo']
  7. supports_stream = True
  8. needs_auth = False
  9. def _create_completion(model: str, messages: list, stream: bool, **kwargs):
  10. json_data = {
  11. 'text': messages[-1]['content'],
  12. 'action': 'noauth',
  13. 'id': '',
  14. 'parentId': '',
  15. 'workspaceId': '',
  16. 'messagePersona': '607e41fe-95be-497e-8e97-010a59b2e2c0',
  17. 'model': 'gpt-4',
  18. 'messages': messages[:-1] if len(messages) > 1 else [],
  19. 'internetMode': 'auto'
  20. }
  21. response = requests.post( 'https://streaming.tenant-forefront-default.knative.chi.coreweave.com/free-chat',
  22. json=json_data, stream=True)
  23. for token in response.iter_lines():
  24. if b'delta' in token:
  25. token = json.loads(token.decode().split('data: ')[1])['delta']
  26. yield (token)
  27. params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
  28. '(%s)' % ', '.join([f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])