dtometzki commited on
Commit
139b7ee
·
verified ·
1 Parent(s): b9c3558

Handle thinking config per Gemini model

Browse files
Files changed (1) hide show
  1. app_2.py +17 -6
app_2.py CHANGED
@@ -14,21 +14,32 @@ MODELS = [
14
  "gemini-3.1-flash-preview",
15
  ]
16
 
17
- # Tools + Config (einmalig)
18
  tools = [
19
  types.Tool(url_context=types.UrlContext()),
20
  types.Tool(googleSearch=types.GoogleSearch(
21
  )),
22
  ]
23
- generate_content_config = types.GenerateContentConfig(
24
- thinking_config=types.ThinkingConfig(thinking_level="MINIMAL"),
25
- tools=tools,
26
- )
 
 
 
 
 
 
 
 
27
 
28
  def create_chat_state(model_name):
29
  return {
30
  "model": model_name,
31
- "chat": client.chats.create(model=model_name, config=generate_content_config),
 
 
 
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