Dua Rajper commited on
Commit
41e1e8b
·
verified ·
1 Parent(s): 9a69b78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -5,6 +5,7 @@ from dotenv import load_dotenv
5
  import json
6
  import textwrap
7
  import time # For handling potential rate limits
 
8
 
9
  # Load environment variables
10
  load_dotenv()
@@ -39,7 +40,7 @@ with st.sidebar:
39
  - **Clear Instructions**: Provide explicit and unambiguous directions.
40
  - **Delimiters**: Use special characters to separate input parts.
41
  - **Structured Output**: Request output in a specific format (JSON).
42
- - **Assumption Checking**: Verify conditions in the input.
43
  - **Few-Shot Prompting**: Provide input-output examples.
44
  - **Temperature Control**: Adjust output randomness.
45
  - **Chain of Thought (CoT)**: Elicit step-by-step reasoning.
@@ -72,7 +73,7 @@ def code_block(text: str, language: str = "text") -> None:
72
  st.markdown(f"```{language}\n{text}\n```", unsafe_allow_html=True)
73
 
74
 
75
- def display_response(response: genai.GenerateContentResponse) -> None:
76
  """Displays the model's response, handling text, and error cases."""
77
  if response.text:
78
  st.subheader("Generated Response:")
@@ -84,7 +85,7 @@ def display_response(response: genai.GenerateContentResponse) -> None:
84
  st.error(f"Full response object: {response}") # Print the full response for debugging
85
 
86
 
87
- def generate_with_retry(prompt: str, generation_config: genai.types.GenerationConfig, max_retries: int = 3, delay: int = 5) -> genai.GenerateContentResponse:
88
  """
89
  Generates content with retry logic to handle potential API errors (e.g., rate limits).
90
 
@@ -254,4 +255,4 @@ if st.button("Generate Response"):
254
  display_response(response)
255
 
256
  except Exception as e:
257
- st.error(f"An error occurred: {e}")
 
5
  import json
6
  import textwrap
7
  import time # For handling potential rate limits
8
+ from typing import Any, Optional
9
 
10
  # Load environment variables
11
  load_dotenv()
 
40
  - **Clear Instructions**: Provide explicit and unambiguous directions.
41
  - **Delimiters**: Use special characters to separate input parts.
42
  - **Structured Output**: Request output in a specific format (JSON).
43
+ - **Assumption Checking**: Verify conditions in the input.
44
  - **Few-Shot Prompting**: Provide input-output examples.
45
  - **Temperature Control**: Adjust output randomness.
46
  - **Chain of Thought (CoT)**: Elicit step-by-step reasoning.
 
73
  st.markdown(f"```{language}\n{text}\n```", unsafe_allow_html=True)
74
 
75
 
76
+ def display_response(response: Any) -> None: # Removed the type hint GenerateContentResponse
77
  """Displays the model's response, handling text, and error cases."""
78
  if response.text:
79
  st.subheader("Generated Response:")
 
85
  st.error(f"Full response object: {response}") # Print the full response for debugging
86
 
87
 
88
+ def generate_with_retry(prompt: str, generation_config: genai.types.GenerationConfig, max_retries: int = 3, delay: int = 5) -> Any: # Removed the type hint
89
  """
90
  Generates content with retry logic to handle potential API errors (e.g., rate limits).
91
 
 
255
  display_response(response)
256
 
257
  except Exception as e:
258
+ st.error(f"An error occurred: {e}")