ThebApi.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from __future__ import annotations
  2. from ...typing import CreateResult, Messages
  3. from .OpenaiAPI import OpenaiAPI
  4. models = {
  5. "theb-ai": "TheB.AI",
  6. "gpt-3.5-turbo": "GPT-3.5",
  7. "gpt-3.5-turbo-16k": "GPT-3.5-16K",
  8. "gpt-4-turbo": "GPT-4 Turbo",
  9. "gpt-4": "GPT-4",
  10. "gpt-4-32k": "GPT-4 32K",
  11. "claude-2": "Claude 2",
  12. "claude-1": "Claude",
  13. "claude-1-100k": "Claude 100K",
  14. "claude-instant-1": "Claude Instant",
  15. "claude-instant-1-100k": "Claude Instant 100K",
  16. "palm-2": "PaLM 2",
  17. "palm-2-codey": "Codey",
  18. "vicuna-13b-v1.5": "Vicuna v1.5 13B",
  19. "llama-2-7b-chat": "Llama 2 7B",
  20. "llama-2-13b-chat": "Llama 2 13B",
  21. "llama-2-70b-chat": "Llama 2 70B",
  22. "code-llama-7b": "Code Llama 7B",
  23. "code-llama-13b": "Code Llama 13B",
  24. "code-llama-34b": "Code Llama 34B",
  25. "qwen-7b-chat": "Qwen 7B"
  26. }
  27. class ThebApi(OpenaiAPI):
  28. label = "TheB.AI API"
  29. url = "https://theb.ai"
  30. working = True
  31. needs_auth = True
  32. default_model = "gpt-3.5-turbo"
  33. models = list(models)
  34. @classmethod
  35. def create_async_generator(
  36. cls,
  37. model: str,
  38. messages: Messages,
  39. api_base: str = "https://api.theb.ai/v1",
  40. temperature: float = 1,
  41. top_p: float = 1,
  42. **kwargs
  43. ) -> CreateResult:
  44. if "auth" in kwargs:
  45. kwargs["api_key"] = kwargs["auth"]
  46. system_message = "\n".join([message["content"] for message in messages if message["role"] == "system"])
  47. if not system_message:
  48. system_message = "You are ChatGPT, a large language model trained by OpenAI, based on the GPT-3.5 architecture."
  49. messages = [message for message in messages if message["role"] != "system"]
  50. data = {
  51. "model_params": {
  52. "system_prompt": system_message,
  53. "temperature": temperature,
  54. "top_p": top_p,
  55. }
  56. }
  57. return super().create_async_generator(model, messages, api_base=api_base, extra_data=data, **kwargs)