Update app.py
Browse files
app.py
CHANGED
@@ -69,8 +69,9 @@ with gr.Blocks(css_paths="app.css") as demo:
|
|
69 |
})
|
70 |
|
71 |
def generation_code(query: Optional[str], _setting: Dict[str, str], _history: Optional[History]):
|
72 |
-
if query
|
73 |
-
query = ''
|
|
|
74 |
if _history is None:
|
75 |
_history = []
|
76 |
|
@@ -80,6 +81,7 @@ with gr.Blocks(css_paths="app.css") as demo:
|
|
80 |
claude_messages = [
|
81 |
{"role": msg["role"] if msg["role"] != "system" else "user", "content": msg["content"]}
|
82 |
for msg in messages[1:] + [{'role': Role.USER, 'content': query}]
|
|
|
83 |
]
|
84 |
|
85 |
try:
|
@@ -90,7 +92,7 @@ with gr.Blocks(css_paths="app.css") as demo:
|
|
90 |
gr.update(active_key="loading"),
|
91 |
gr.update(open=True)
|
92 |
]
|
93 |
-
|
94 |
with client.messages.stream(
|
95 |
model="claude-3-5-sonnet-20241022",
|
96 |
max_tokens=7800,
|
@@ -110,14 +112,14 @@ with gr.Blocks(css_paths="app.css") as demo:
|
|
110 |
gr.update(active_key="loading"),
|
111 |
gr.update(open=True)
|
112 |
]
|
113 |
-
|
114 |
_history = messages_to_history([
|
115 |
{'role': Role.SYSTEM, 'content': system_message}
|
116 |
] + claude_messages + [{
|
117 |
'role': Role.ASSISTANT,
|
118 |
-
|
119 |
}])
|
120 |
-
|
121 |
yield [
|
122 |
collected_content,
|
123 |
_history,
|
@@ -125,9 +127,12 @@ with gr.Blocks(css_paths="app.css") as demo:
|
|
125 |
gr.update(active_key="render"),
|
126 |
gr.update(open=True)
|
127 |
]
|
128 |
-
|
129 |
except Exception as e:
|
|
|
130 |
raise ValueError(f'Error calling Claude API: {str(e)}')
|
|
|
|
|
131 |
|
132 |
with ms.Application() as app:
|
133 |
with antd.ConfigProvider():
|
|
|
69 |
})
|
70 |
|
71 |
def generation_code(query: Optional[str], _setting: Dict[str, str], _history: Optional[History]):
|
72 |
+
if not query or query.strip() == '':
|
73 |
+
query = random.choice(DEMO_LIST)['description'] # ๋น ์ฟผ๋ฆฌ์ผ ๊ฒฝ์ฐ ๋๋ค ์์ ์ฌ์ฉ
|
74 |
+
|
75 |
if _history is None:
|
76 |
_history = []
|
77 |
|
|
|
81 |
claude_messages = [
|
82 |
{"role": msg["role"] if msg["role"] != "system" else "user", "content": msg["content"]}
|
83 |
for msg in messages[1:] + [{'role': Role.USER, 'content': query}]
|
84 |
+
if msg["content"].strip() != '' # ๋น ๋ฉ์์ง ํํฐ๋ง
|
85 |
]
|
86 |
|
87 |
try:
|
|
|
92 |
gr.update(active_key="loading"),
|
93 |
gr.update(open=True)
|
94 |
]
|
95 |
+
|
96 |
with client.messages.stream(
|
97 |
model="claude-3-5-sonnet-20241022",
|
98 |
max_tokens=7800,
|
|
|
112 |
gr.update(active_key="loading"),
|
113 |
gr.update(open=True)
|
114 |
]
|
115 |
+
|
116 |
_history = messages_to_history([
|
117 |
{'role': Role.SYSTEM, 'content': system_message}
|
118 |
] + claude_messages + [{
|
119 |
'role': Role.ASSISTANT,
|
120 |
+
'content': collected_content
|
121 |
}])
|
122 |
+
|
123 |
yield [
|
124 |
collected_content,
|
125 |
_history,
|
|
|
127 |
gr.update(active_key="render"),
|
128 |
gr.update(open=True)
|
129 |
]
|
130 |
+
|
131 |
except Exception as e:
|
132 |
+
print(f"Error details: {str(e)}") # ๋๋ฒ๊น
์ ์ํ ์๋ฌ ์ถ๋ ฅ
|
133 |
raise ValueError(f'Error calling Claude API: {str(e)}')
|
134 |
+
|
135 |
+
|
136 |
|
137 |
with ms.Application() as app:
|
138 |
with antd.ConfigProvider():
|