stubs.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from __future__ import annotations
  2. from pydantic import BaseModel, Field
  3. from typing import Union, Optional
  4. try:
  5. from typing import Annotated
  6. except ImportError:
  7. class Annotated:
  8. pass
  9. from g4f.typing import Messages
  10. class ChatCompletionsConfig(BaseModel):
  11. messages: Messages = Field(examples=[[{"role": "system", "content": ""}, {"role": "user", "content": ""}]])
  12. model: str = Field(default="")
  13. provider: Optional[str] = None
  14. stream: bool = False
  15. image: Optional[str] = None
  16. image_name: Optional[str] = None
  17. images: Optional[list[tuple[str, str]]] = None
  18. temperature: Optional[float] = None
  19. max_tokens: Optional[int] = None
  20. stop: Union[list[str], str, None] = None
  21. api_key: Optional[str] = None
  22. api_base: str = None
  23. web_search: Optional[bool] = None
  24. proxy: Optional[str] = None
  25. conversation_id: Optional[str] = None
  26. conversation: Optional[dict] = None
  27. history_disabled: Optional[bool] = None
  28. auto_continue: Optional[bool] = None
  29. timeout: Optional[int] = None
  30. tool_calls: list = Field(default=[], examples=[[
  31. {
  32. "function": {
  33. "arguments": {"query":"search query", "max_results":5, "max_words": 2500, "backend": "auto", "add_text": True, "timeout": 5},
  34. "name": "search_tool"
  35. },
  36. "type": "function"
  37. }
  38. ]])
  39. tools: list = None
  40. response_format: Optional[dict] = None
  41. class ImageGenerationConfig(BaseModel):
  42. prompt: str
  43. model: Optional[str] = None
  44. provider: Optional[str] = None
  45. response_format: Optional[str] = None
  46. api_key: Optional[str] = None
  47. proxy: Optional[str] = None
  48. class ProviderResponseModel(BaseModel):
  49. id: str
  50. object: str = "provider"
  51. created: int
  52. url: Optional[str]
  53. label: Optional[str]
  54. class ProviderResponseDetailModel(ProviderResponseModel):
  55. models: list[str]
  56. image_models: list[str]
  57. vision_models: list[str]
  58. params: list[str]
  59. class ModelResponseModel(BaseModel):
  60. id: str
  61. object: str = "model"
  62. created: int
  63. owned_by: Optional[str]
  64. class UploadResponseModel(BaseModel):
  65. bucket_id: str
  66. url: str
  67. class ErrorResponseModel(BaseModel):
  68. error: ErrorResponseMessageModel
  69. model: Optional[str] = None
  70. provider: Optional[str] = None
  71. class ErrorResponseMessageModel(BaseModel):
  72. message: str
  73. class FileResponseModel(BaseModel):
  74. filename: str