Function calling is a new feature in OpenAI’s GPT-4-0613 and GPT-3.5 Turbo-0613 models. These AI models are trained to detect the need for function calling based on the user’s prompt and respond with a structured call request instead of regular text.
Function calling allows chatbots to interact with other systems, enabling the GPT models to respond to questions they otherwise could not, such as those requiring real-time information or data not included in their training set. In other words, function calling provides another way to teach AI models how to interact with the external world.
SAP BTP Destination is a cloud-based service that facilitates secure and reliable access to external APIs. It acts as a gateway between SAP Business Technology Platform (BTP) applications and external systems. By utilizing SAP BTP Destination, businesses can integrate various third-party services into their BTP landscape, fostering a connected and data-driven ecosystem.
Integrating OpenAI Function Calling with SAP BTP Destination empowers developers to execute external API calls directly from within their OpenAI functions. This integration eliminates the need for manual API calls and streamlines the process of accessing external data and services.
Before function calling, there were only two ways of augmenting the capabilities of a GPT language model:
Function calling adds a third way of extending the GPT capabilities by allowing it to ask us to run functions on its behalf. The model can then take the function’s result and build a human-readable response that fits seamlessly into the current conversation.
The introduction of function calling changes how we interact with the GPT API. Before these functions, the interaction was simple:
Image source : https://semaphoreci.com/blog/function-calling
With function calling, the sequence becomes more involved:
Image source : https://semaphoreci.com/blog/function-calling
Prerequisites
Before embarking on this integration journey, ensure you have the following prerequisites in place:
High-Level Flow of Execution
Create new destination with Internal SAP API or external API
Using the SAP BTP Destination API endpoint, you can make a call to get the results.
def get_top_credits(query: str = None, payee: str = None):
"""Retrieve top 10 payments (API key required)"""
base_url = destination["destinationConfiguration"]["URL"]
headers= {'Accept': 'application/json', 'Authorization': token["type"] + ' ' + token["value"],'cache-control': 'no-cache' }
if query is not None:
params['q'] = query
if payee is not None:
params['payee'] = payeeId
response = requests.get(base_url, params=params, headers=headers)
data = response.json()
if data['status'] == 'ok':
print(f"Processing {data['totalResults']}")
return json.dumps(data['payments'])
else:
print("Request failed with message:", data['message'])
return 'No payments found'
Integration Steps
Create an SAP BTP Destination:
Obtain the Destination ID:
Implement OpenAI Function:
https://platform.openai.com/docs/guides/function-calling
https://cookbook.openai.com/examples/how_to_call_functions_with_chat_models
Benefits of Integration
Conclusion
Integrating OpenAI Function Calling with SAP BTP Destination empowers developers to seamlessly execute external API calls from within their OpenAI functions. This integration enhances application capabilities, simplifies data access, and promotes a secure and centralized approach to external API management. By embracing these technologies, businesses can unlock new possibilities and drive innovation in today’s dynamic digital landscape.
Additional Considerations
Remember, continuous learning and exploration are key to unlocking the full potential of OpenAI and SAP BTP Destination. As you embark on this integration journey, stay curious, experiment with new approaches, and continuously refine your integration strategy.
Function calling is a powerful feature in OpenAI’s GPT models, enabling them to interact with external tools and APIs in a more deterministic and structured manner. This feature lays the groundwork for more dynamic and responsive AI applications capable of providing current information and executing tasks beyond what was previously possible.