stubs.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. web_search: Optional[bool] = None
  23. proxy: Optional[str] = None
  24. conversation_id: Optional[str] = None
  25. conversation: Optional[dict] = None
  26. history_disabled: Optional[bool] = None
  27. auto_continue: Optional[bool] = None
  28. timeout: Optional[int] = None
  29. tool_calls: list = Field(default=[], examples=[[
  30. {
  31. "function": {
  32. "arguments": {"query":"search query", "max_results":5, "max_words": 2500, "backend": "api", "add_text": True, "timeout": 5},
  33. "name": "search_tool"
  34. },
  35. "type": "function"
  36. }
  37. ]])
  38. tools: list = None
  39. class ImageGenerationConfig(BaseModel):
  40. prompt: str
  41. model: Optional[str] = None
  42. provider: Optional[str] = None
  43. response_format: Optional[str] = None
  44. api_key: Optional[str] = None
  45. proxy: Optional[str] = None
  46. class ProviderResponseModel(BaseModel):
  47. id: str
  48. object: str = "provider"
  49. created: int
  50. url: Optional[str]
  51. label: Optional[str]
  52. class ProviderResponseDetailModel(ProviderResponseModel):
  53. models: list[str]
  54. image_models: list[str]
  55. vision_models: list[str]
  56. params: list[str]
  57. class ModelResponseModel(BaseModel):
  58. id: str
  59. object: str = "model"
  60. created: int
  61. owned_by: Optional[str]
  62. class UploadResponseModel(BaseModel):
  63. bucket_id: str
  64. url: str
  65. class ErrorResponseModel(BaseModel):
  66. error: ErrorResponseMessageModel
  67. model: Optional[str] = None
  68. provider: Optional[str] = None
  69. class ErrorResponseMessageModel(BaseModel):
  70. message: str
  71. class FileResponseModel(BaseModel):
  72. filename: str