Forefront.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from __future__ import annotations
  2. import json
  3. import requests
  4. from ...typing import Any, CreateResult
  5. from ..base_provider import BaseProvider
  6. class Forefront(BaseProvider):
  7. url = "https://forefront.com"
  8. supports_stream = True
  9. supports_gpt_35_turbo = True
  10. @staticmethod
  11. def create_completion(
  12. model: str,
  13. messages: list[dict[str, str]],
  14. stream: bool, **kwargs: Any) -> CreateResult:
  15. json_data = {
  16. "text" : messages[-1]["content"],
  17. "action" : "noauth",
  18. "id" : "",
  19. "parentId" : "",
  20. "workspaceId" : "",
  21. "messagePersona": "607e41fe-95be-497e-8e97-010a59b2e2c0",
  22. "model" : "gpt-4",
  23. "messages" : messages[:-1] if len(messages) > 1 else [],
  24. "internetMode" : "auto",
  25. }
  26. response = requests.post("https://streaming.tenant-forefront-default.knative.chi.coreweave.com/free-chat",
  27. json=json_data, stream=True)
  28. response.raise_for_status()
  29. for token in response.iter_lines():
  30. if b"delta" in token:
  31. yield json.loads(token.decode().split("data: ")[1])["delta"]