Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -183,6 +183,47 @@ def respond_deepseek_qna(
|
|
183 |
return f"오류가 발생했습니다: {str(e)}"
|
184 |
|
185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
#############################
|
187 |
# [기본코드] UI 부분 - 수정/삭제 불가
|
188 |
#############################
|
|
|
183 |
return f"오류가 발생했습니다: {str(e)}"
|
184 |
|
185 |
|
186 |
+
def respond_claude_qna(
|
187 |
+
question: str,
|
188 |
+
system_message: str,
|
189 |
+
max_tokens: int,
|
190 |
+
temperature: float,
|
191 |
+
top_p: float,
|
192 |
+
claude_api_key: str
|
193 |
+
) -> str:
|
194 |
+
"""
|
195 |
+
Claude API를 사용한 개선된 응답 생성 함수
|
196 |
+
"""
|
197 |
+
if not claude_api_key:
|
198 |
+
return "Claude API 토큰이 필요합니다."
|
199 |
+
|
200 |
+
try:
|
201 |
+
client = anthropic.Anthropic(api_key=claude_api_key)
|
202 |
+
|
203 |
+
# 메시지 생성
|
204 |
+
message = client.messages.create(
|
205 |
+
model="claude-3-haiku-20240307",
|
206 |
+
max_tokens=max_tokens,
|
207 |
+
temperature=temperature,
|
208 |
+
system=system_message,
|
209 |
+
messages=[
|
210 |
+
{
|
211 |
+
"role": "user",
|
212 |
+
"content": question
|
213 |
+
}
|
214 |
+
]
|
215 |
+
)
|
216 |
+
|
217 |
+
return message.content[0].text
|
218 |
+
|
219 |
+
except anthropic.APIError as ae:
|
220 |
+
return f"Claude API 오류: {str(ae)}"
|
221 |
+
except anthropic.RateLimitError:
|
222 |
+
return "요청 한도를 초과했습니다. 잠시 후 다시 시도해주세요."
|
223 |
+
except Exception as e:
|
224 |
+
return f"예상치 못한 오류가 발생했습니다: {str(e)}"
|
225 |
+
|
226 |
+
|
227 |
#############################
|
228 |
# [기본코드] UI 부분 - 수정/삭제 불가
|
229 |
#############################
|