gsavin commited on
Commit
f42cab1
·
1 Parent(s): d13ad06

feat: add timeout with retries for the llm requests

Browse files
Files changed (3) hide show
  1. src/agent/llm.py +13 -3
  2. src/css.py +18 -2
  3. src/main.py +1 -1
src/agent/llm.py CHANGED
@@ -1,6 +1,9 @@
1
  """Utility functions for working with the language model."""
2
 
 
3
  import logging
 
 
4
  from langchain_google_genai import ChatGoogleGenerativeAI
5
 
6
  from config import settings
@@ -22,22 +25,29 @@ def create_llm(
22
  top_p: float = settings.top_p,
23
  ) -> ChatGoogleGenerativeAI:
24
  """Create a standard LLM instance."""
25
- return ChatGoogleGenerativeAI(
26
  model=MODEL_NAME,
27
  google_api_key=_get_api_key(),
28
  temperature=temperature,
29
  top_p=top_p,
30
  thinking_budget=1024,
 
 
31
  )
 
32
 
33
 
34
  def create_light_llm(temperature: float = settings.temperature, top_p: float = settings.top_p):
35
- return ChatGoogleGenerativeAI(
 
36
  model="gemini-2.0-flash",
37
  google_api_key=_get_api_key(),
38
  temperature=temperature,
39
- top_p=top_p
 
 
40
  )
 
41
 
42
 
43
  def create_precise_llm() -> ChatGoogleGenerativeAI:
 
1
  """Utility functions for working with the language model."""
2
 
3
+ import asyncio
4
  import logging
5
+
6
+ from google.api_core.exceptions import DeadlineExceeded
7
  from langchain_google_genai import ChatGoogleGenerativeAI
8
 
9
  from config import settings
 
25
  top_p: float = settings.top_p,
26
  ) -> ChatGoogleGenerativeAI:
27
  """Create a standard LLM instance."""
28
+ llm = ChatGoogleGenerativeAI(
29
  model=MODEL_NAME,
30
  google_api_key=_get_api_key(),
31
  temperature=temperature,
32
  top_p=top_p,
33
  thinking_budget=1024,
34
+ timeout=settings.request_timeout,
35
+ max_retries=3,
36
  )
37
+ return llm
38
 
39
 
40
  def create_light_llm(temperature: float = settings.temperature, top_p: float = settings.top_p):
41
+ """Create a light LLM instance with a shorter timeout."""
42
+ llm = ChatGoogleGenerativeAI(
43
  model="gemini-2.0-flash",
44
  google_api_key=_get_api_key(),
45
  temperature=temperature,
46
+ top_p=top_p,
47
+ timeout=settings.request_timeout,
48
+ max_retries=3,
49
  )
50
+ return llm
51
 
52
 
53
  def create_precise_llm() -> ChatGoogleGenerativeAI:
src/css.py CHANGED
@@ -1,17 +1,31 @@
1
  # Custom CSS for fullscreen image with overlay and styled form components
2
  custom_css = """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  /* -------- FULLSCREEN BACKGROUND & NARRATIVE -------- */
4
  .image-container {
5
  position: fixed !important;
6
  top: 0 !important;
7
  left: 0 !important;
8
  width: 100vw !important;
9
- height: 100vh !important;
10
  z-index: 1 !important;
11
  }
12
  .image-container img {
13
  width: 100vw !important;
14
- height: 100vh !important;
15
  object-fit: cover !important;
16
  }
17
 
@@ -26,6 +40,8 @@ custom_css = """
26
  padding: 40px 20px 20px !important;
27
  z-index: 10 !important;
28
  color: white !important;
 
 
29
  }
30
  .overlay-content .form {
31
  background: transparent !important;
 
1
  # Custom CSS for fullscreen image with overlay and styled form components
2
  custom_css = """
3
+ html, body {
4
+ height: 100%;
5
+ width: 100%;
6
+ margin: 0;
7
+ padding: 0;
8
+ }
9
+
10
+ .constructor-page {
11
+ height: 100vh !important;
12
+ overflow-y: auto !important;
13
+ }
14
+
15
+ gradio-app {
16
+ height: 100% !important;
17
+ }
18
+
19
  /* -------- FULLSCREEN BACKGROUND & NARRATIVE -------- */
20
  .image-container {
21
  position: fixed !important;
22
  top: 0 !important;
23
  left: 0 !important;
24
  width: 100vw !important;
 
25
  z-index: 1 !important;
26
  }
27
  .image-container img {
28
  width: 100vw !important;
 
29
  object-fit: cover !important;
30
  }
31
 
 
40
  padding: 40px 20px 20px !important;
41
  z-index: 10 !important;
42
  color: white !important;
43
+ max-height: 100vh !important;
44
+ overflow-y: auto !important;
45
  }
46
  .overlay-content .form {
47
  background: transparent !important;
src/main.py CHANGED
@@ -140,7 +140,7 @@ with gr.Blocks(
140
 
141
  # Constructor Interface (visible by default)
142
  with gr.Column(
143
- visible=True, elem_id="constructor-interface"
144
  ) as constructor_interface:
145
  gr.Markdown("# 🎮 Interactive Game Constructor")
146
  gr.Markdown(
 
140
 
141
  # Constructor Interface (visible by default)
142
  with gr.Column(
143
+ visible=True, elem_id="constructor-interface", elem_classes=["constructor-page"]
144
  ) as constructor_interface:
145
  gr.Markdown("# 🎮 Interactive Game Constructor")
146
  gr.Markdown(