Spaces:
Sleeping
Sleeping
Byungsoo Kang
commited on
환율 tool 추가
Browse files
app.py
CHANGED
@@ -18,6 +18,42 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
23 |
"""A tool that fetches the current local time in a specified timezone.
|
@@ -55,7 +91,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
20 |
|
21 |
+
@tool
|
22 |
+
def convert_currency(amount: float, from_currency: str, to_currency: str) -> str:
|
23 |
+
"""
|
24 |
+
한 통화에서 다른 통화로 금액을 변환합니다. 통화 코드는 3자리 ISO 코드를 사용해야 합니다 (예: USD, EUR, KRW).
|
25 |
+
|
26 |
+
Args:
|
27 |
+
amount (float): 변환할 금액.
|
28 |
+
from_currency (str): 변환의 기준이 되는 통화의 3자리 코드.
|
29 |
+
to_currency (str): 변환할 대상 통화의 3자리 코드.
|
30 |
+
"""
|
31 |
+
# 통화 코드를 대문자로 통일하여 API 오류 가능성을 줄입니다.
|
32 |
+
from_currency = from_currency.upper()
|
33 |
+
to_currency = to_currency.upper()
|
34 |
+
|
35 |
+
# API 요청 URL
|
36 |
+
api_url = f"https://api.frankfurter.app/latest?amount={amount}&from={from_currency}&to={to_currency}"
|
37 |
+
|
38 |
+
try:
|
39 |
+
response = requests.get(api_url)
|
40 |
+
# 요청이 성공했는지 확인 (HTTP 상태 코드 200)
|
41 |
+
response.raise_for_status()
|
42 |
+
|
43 |
+
data = response.json()
|
44 |
+
|
45 |
+
# API 응답에서 변환된 금액 추출
|
46 |
+
converted_amount = data['rates'][to_currency]
|
47 |
+
|
48 |
+
return f"성공: {amount:,} {from_currency}는 현재 환율로 약 {converted_amount:,.2f} {to_currency} 입니다."
|
49 |
+
|
50 |
+
except requests.exceptions.HTTPError as http_err:
|
51 |
+
# API가 유효하지 않은 통화 코드 등의 오류를 반환했을 경우
|
52 |
+
return f"오류: 환율 정보를 가져오는 데 실패했습니다. 통화 코드('{from_currency}', '{to_currency}')가 올바른지 확인하세요. (에러: {http_err})"
|
53 |
+
except Exception as e:
|
54 |
+
# 네트워크 문제 등 기타 예외 처리
|
55 |
+
return f"오류: 환율 변환 중 예상치 못한 문제가 발생했습니다. (에러: {str(e)})"
|
56 |
+
|
57 |
@tool
|
58 |
def get_current_time_in_timezone(timezone: str) -> str:
|
59 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
91 |
|
92 |
agent = CodeAgent(
|
93 |
model=model,
|
94 |
+
tools=[final_answer, DuckDuckGoSearchTool(), get_current_time_in_timezone, convert_currency], ## add your tools here (don't remove final answer)
|
95 |
max_steps=6,
|
96 |
verbosity_level=1,
|
97 |
grammar=None,
|