habulaj commited on
Commit
0ce6056
·
verified ·
1 Parent(s): 100df4e

Create enums.py

Browse files
Files changed (1) hide show
  1. gemini_client/enums.py +116 -0
gemini_client/enums.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ from enum import Enum
3
+
4
+ class Endpoint(Enum):
5
+ """
6
+ Enum for Google Gemini API endpoints.
7
+
8
+ Attributes:
9
+ INIT (str): URL for initializing the Gemini session.
10
+ GENERATE (str): URL for generating chat responses.
11
+ ROTATE_COOKIES (str): URL for rotating authentication cookies.
12
+ UPLOAD (str): URL for uploading files/images.
13
+ """
14
+ INIT = "https://gemini.google.com/app"
15
+ GENERATE = "https://gemini.google.com/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate"
16
+ ROTATE_COOKIES = "https://accounts.google.com/RotateCookies"
17
+ UPLOAD = "https://content-push.googleapis.com/upload"
18
+
19
+ class Headers(Enum):
20
+ """
21
+ Enum for HTTP headers used in Gemini API requests.
22
+
23
+ Attributes:
24
+ GEMINI (dict): Headers for Gemini chat requests.
25
+ ROTATE_COOKIES (dict): Headers for rotating cookies.
26
+ UPLOAD (dict): Headers for file/image upload.
27
+ """
28
+ GEMINI = {
29
+ "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
30
+ "Host": "gemini.google.com",
31
+ "Origin": "https://gemini.google.com",
32
+ "Referer": "https://gemini.google.com/",
33
+ # User-Agent will be handled by curl_cffi impersonate
34
+ # "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
35
+ "X-Same-Domain": "1",
36
+ }
37
+ ROTATE_COOKIES = {
38
+ "Content-Type": "application/json",
39
+ }
40
+ UPLOAD = {"Push-ID": "feeds/mcudyrk2a4khkz"}
41
+
42
+ class Model(Enum):
43
+ """
44
+ Enum for available Gemini model configurations.
45
+
46
+ Attributes:
47
+ model_name (str): Name of the model.
48
+ model_header (dict): Additional headers required for the model.
49
+ advanced_only (bool): Whether the model is available only for advanced users.
50
+ """
51
+ # Updated model definitions based on reference implementation
52
+ UNSPECIFIED = ("unspecified", {}, False)
53
+ G_2_0_FLASH = (
54
+ "gemini-2.0-flash",
55
+ {"x-goog-ext-525001261-jspb": '[1,null,null,null,"f299729663a2343f"]'},
56
+ False,
57
+ )
58
+ G_2_0_FLASH_THINKING = (
59
+ "gemini-2.0-flash-thinking",
60
+ {"x-goog-ext-525001261-jspb": '[null,null,null,null,"7ca48d02d802f20a"]'},
61
+ False,
62
+ )
63
+ G_2_5_FLASH = (
64
+ "gemini-2.5-flash",
65
+ {"x-goog-ext-525001261-jspb": '[1,null,null,null,"35609594dbe934d8"]'},
66
+ False,
67
+ )
68
+ G_2_5_PRO = (
69
+ "gemini-2.5-pro",
70
+ {"x-goog-ext-525001261-jspb": '[1,null,null,null,"2525e3954d185b3c"]'},
71
+ False,
72
+ )
73
+ G_2_0_EXP_ADVANCED = (
74
+ "gemini-2.0-exp-advanced",
75
+ {"x-goog-ext-525001261-jspb": '[null,null,null,null,"b1e46a6037e6aa9f"]'},
76
+ True,
77
+ )
78
+ G_2_5_EXP_ADVANCED = (
79
+ "gemini-2.5-exp-advanced",
80
+ {"x-goog-ext-525001261-jspb": '[null,null,null,null,"203e6bb81620bcfe"]'},
81
+ True,
82
+ )
83
+
84
+ def __init__(self, name, header, advanced_only):
85
+ """
86
+ Initialize a Model enum member.
87
+
88
+ Args:
89
+ name (str): Model name.
90
+ header (dict): Model-specific headers.
91
+ advanced_only (bool): If True, model is for advanced users only.
92
+ """
93
+ self.model_name = name
94
+ self.model_header = header
95
+ self.advanced_only = advanced_only
96
+
97
+ @classmethod
98
+ def from_name(cls, name: str):
99
+ """
100
+ Get a Model enum member by its model name.
101
+
102
+ Args:
103
+ name (str): Name of the model.
104
+
105
+ Returns:
106
+ Model: Corresponding Model enum member.
107
+
108
+ Raises:
109
+ ValueError: If the model name is not found.
110
+ """
111
+ for model in cls:
112
+ if model.model_name == name:
113
+ return model
114
+ raise ValueError(
115
+ f"Unknown model name: {name}. Available models: {', '.join([model.model_name for model in cls])}"
116
+ )