Large Language Models (LLMs) can call external functions during a conversation. What is the main benefit of this feature?
Think about how LLMs can get information they don't know internally.
Function calling lets LLMs request data or perform actions outside their training, like fetching current weather or database info, improving response accuracy.
Given the following Python simulation of an LLM calling a function, what is the printed output?
def get_temperature(city): return f"The temperature in {city} is 22°C." user_input = "What's the temperature in Paris?" # Simulate LLM detecting function call if "temperature" in user_input: city = user_input.split()[-1].strip('?') response = get_temperature(city) else: response = "I don't know." print(response)
Look at how the city name is extracted and passed to the function.
The code extracts 'Paris' from the input and calls get_temperature('Paris'), which returns the temperature string with 22°C.
You want to build a chatbot that uses function calling to fetch live stock prices. Which model type is best suited for this?
Consider which model can dynamically call external APIs for live data.
A large LLM with function calling and API integration can request live stock prices dynamically, making it the best choice.
When using an LLM with function calling, how does increasing the temperature hyperparameter affect the function call behavior?
Think about how temperature affects randomness in LLM outputs.
Higher temperature increases randomness, so the LLM might call functions more freely, sometimes unnecessarily.
Consider this snippet where an LLM is supposed to call a function to get current time, but it never executes the function. What is the likely cause?
def get_current_time(): from datetime import datetime return datetime.now().strftime('%H:%M:%S') llm_response = '{"function_call": {"name": "get_current_time"}}' # Code to parse and execute function call import json response_dict = json.loads(llm_response) if response_dict.get('function_call'): func_name = response_dict['function_call']['name'] if func_name == 'get_current_time': result = get_current_time() else: result = None else: result = None print(result)
Check if the function is called or just referenced.
The code assigns the function object to result without calling it (missing parentheses), so printing result shows the function object, not the time string.