refactor: Add input validation to chat_function
Browse files
app.py
CHANGED
@@ -78,9 +78,18 @@ def get_model_key(label: str) -> str:
|
|
78 |
return next(key for key, value in AVAILABLE_MODELS.items() if value == label)
|
79 |
|
80 |
|
|
|
|
|
|
|
|
|
|
|
81 |
def chat_function(
|
82 |
message: str, history: List[Tuple[str, str]], model_label: str
|
83 |
) -> Generator[str, None, None]:
|
|
|
|
|
|
|
|
|
84 |
model_key = get_model_key(model_label)
|
85 |
if STREAMING:
|
86 |
response = ""
|
@@ -113,19 +122,16 @@ with gr.Blocks(
|
|
113 |
multimodal=False,
|
114 |
examples=[
|
115 |
[
|
116 |
-
"μ€κ³ μ°¨ κ±°λλ₯Ό
|
117 |
"GPT-4o",
|
118 |
-
"gpt_4o",
|
119 |
],
|
120 |
[
|
121 |
-
"
|
122 |
"GPT-4o",
|
123 |
-
"gpt_4o",
|
124 |
],
|
125 |
[
|
126 |
-
"μ§μΈμ΄
|
127 |
"GPT-4o",
|
128 |
-
"gpt_4o",
|
129 |
],
|
130 |
],
|
131 |
additional_inputs=[model_dropdown],
|
|
|
78 |
return next(key for key, value in AVAILABLE_MODELS.items() if value == label)
|
79 |
|
80 |
|
81 |
+
def validate_input(message: str) -> bool:
|
82 |
+
"""μ
λ ₯λ λ©μμ§κ° μ ν¨νμ§ κ²μ¬ν©λλ€."""
|
83 |
+
return bool(message.strip())
|
84 |
+
|
85 |
+
|
86 |
def chat_function(
|
87 |
message: str, history: List[Tuple[str, str]], model_label: str
|
88 |
) -> Generator[str, None, None]:
|
89 |
+
if not validate_input(message):
|
90 |
+
yield "λ©μμ§λ₯Ό μ
λ ₯ν΄μ£ΌμΈμ."
|
91 |
+
return
|
92 |
+
|
93 |
model_key = get_model_key(model_label)
|
94 |
if STREAMING:
|
95 |
response = ""
|
|
|
122 |
multimodal=False,
|
123 |
examples=[
|
124 |
[
|
125 |
+
"μ€κ³ μ°¨ κ±°λλ₯Ό νλλ° λΆλμΌλ‘ μ°¨ μ리μ 500λ§μμ΄ λ€μμ΅λλ€. ν맀μμκ² λ²μ μ±
μμ λ¬Όμ μ μλμ? λΉμ·ν νλ‘λ₯Ό μκ°ν΄μ£ΌμΈμ.",
|
126 |
"GPT-4o",
|
|
|
127 |
],
|
128 |
[
|
129 |
+
"μ½ 2μ² νμ λμ§λ₯Ό ꡬ맀νλλ°, μκ³ λ³΄λ μ£Όνμ μ§μ μ μλ λ
μ΄μμ΅λλ€. μ΄μ μ μ¬ν λΆλμ° μ¬κΈ° κ΄λ ¨ νλ‘λ₯Ό μλ €μ£ΌμΈμ.",
|
130 |
"GPT-4o",
|
|
|
131 |
],
|
132 |
[
|
133 |
+
"μ§μΈμ΄ μ₯λμΌλ‘ νλλ₯Έ μΉΌμ νμ΄ 20cm κ°λ μ°λ Έμ΅λλ€. μ₯λμ΄λΌκ³ μ£Όμ₯νλλ°, μ΄μ μ μ¬ν μν΄ κ΄λ ¨ νλ‘λ₯Ό μλ €μ£ΌμΈμ.",
|
134 |
"GPT-4o",
|
|
|
135 |
],
|
136 |
],
|
137 |
additional_inputs=[model_dropdown],
|