Nástroje pro volání funkcí: Definice funkce

Working with the OpenAI Responses API

James Chapman

AI Curriculum Manager, DataCamp

Nástroje pro volání funkcí

 

  • Nástroje pro volání funkcí: LLM volají naprogramované funkce
    • Lze vytvořit téměř pro cokoliv!
  • convert_currency()
    • amount: částka
    • from_currency: zdrojová měna
    • to_currency: cílová měna

frankfurter.png

1 https://frankfurter.dev/
Working with the OpenAI Responses API

Nástroje pro volání funkcí

fct1.jpg

Working with the OpenAI Responses API

Nástroje pro volání funkcí

fct2.jpg

Working with the OpenAI Responses API

Nástroje pro volání funkcí

fct3.jpg

Working with the OpenAI Responses API

Nástroje pro volání funkcí

fct4.jpg

Working with the OpenAI Responses API

Nástroje pro volání funkcí

fct5.jpg

Working with the OpenAI Responses API

Nástroje pro volání funkcí

fct6.jpg

Working with the OpenAI Responses API
def convert_currency(amount, from_currency, to_currency):

url = f"https://api.frankfurter.dev/v1/latest?base={from_currency}&symbols={to_currency}"
try: response = requests.get(url) response.raise_for_status()
data = response.json() rate = data['rates'].get(to_currency)
if rate is None: return f"Could not find exchange rate for {from_currency} to {to_currency}"
converted_amount = amount * rate return f"{amount} {from_currency} = {converted_amount:.2f} {to_currency} (Rate: {rate})"
except requests.exceptions.RequestException as e: return f"Error converting currency: {str(e)}"
Working with the OpenAI Responses API

Naše funkce

print(convert_currency(100, "USD", "EUR"))
100 USD = 86.62 EUR (Rate: 0.86625)
Working with the OpenAI Responses API

Pojďme procvičovat!

Working with the OpenAI Responses API

Preparing Video For Download...