Handle thinking config per Gemini model
Browse files
app_2.py
CHANGED
|
@@ -14,21 +14,32 @@ MODELS = [
|
|
| 14 |
"gemini-3.1-flash-preview",
|
| 15 |
]
|
| 16 |
|
| 17 |
-
# Tools
|
| 18 |
tools = [
|
| 19 |
types.Tool(url_context=types.UrlContext()),
|
| 20 |
types.Tool(googleSearch=types.GoogleSearch(
|
| 21 |
)),
|
| 22 |
]
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def create_chat_state(model_name):
|
| 29 |
return {
|
| 30 |
"model": model_name,
|
| 31 |
-
"chat": client.chats.create(
|
|
|
|
|
|
|
|
|
|
| 32 |
"lock": threading.Lock(),
|
| 33 |
}
|
| 34 |
|
|
|
|
| 14 |
"gemini-3.1-flash-preview",
|
| 15 |
]
|
| 16 |
|
| 17 |
+
# Tools (einmalig)
|
| 18 |
tools = [
|
| 19 |
types.Tool(url_context=types.UrlContext()),
|
| 20 |
types.Tool(googleSearch=types.GoogleSearch(
|
| 21 |
)),
|
| 22 |
]
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def build_generate_content_config(model_name):
|
| 26 |
+
config_kwargs = {"tools": tools}
|
| 27 |
+
|
| 28 |
+
# Pro-Modelle akzeptieren MINIMAL derzeit nicht.
|
| 29 |
+
if "pro" not in model_name:
|
| 30 |
+
config_kwargs["thinking_config"] = types.ThinkingConfig(
|
| 31 |
+
thinking_level="MINIMAL"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
return types.GenerateContentConfig(**config_kwargs)
|
| 35 |
|
| 36 |
def create_chat_state(model_name):
|
| 37 |
return {
|
| 38 |
"model": model_name,
|
| 39 |
+
"chat": client.chats.create(
|
| 40 |
+
model=model_name,
|
| 41 |
+
config=build_generate_content_config(model_name),
|
| 42 |
+
),
|
| 43 |
"lock": threading.Lock(),
|
| 44 |
}
|
| 45 |
|