How to make openai assistant more robust to ambigious function calls

I’m working with two functions that sometimes run into issues. One function fetches coin prices from a third-party API, and the other performs Google searches. I’m looking for ways to make these function calls more robust. Here are the details of the two functions:

Coin Price Retrieval Function

This function retrieves historical data for a specific cryptocurrency.

get_coin_historical_data_by_id_desc = {
    "name": "get_coin_historical_data_by_id",
    "description": "Get historical data of a specific date related to cryptocurrency page based on a particular coin ID",
    "parameters": {
        "type": "object",
        "properties": {
            "coin_id": {
                "type": "string",
                "description": "Unique ID for the coin"
            },
            "date": {
                "type": "string",
                "description": "Date in Format: dd-mm-yyyy"
            }
        },
        "required": ["coin_id", "date"]
    }
}

Google Search Function

This function gets the most recent and relevant data from the web like when was the most recent bitcoin halving but is not used for price information.

search_online_desc = {
    "name": "search_online",
    "description": "Get the most recent and latest data from the web; do not use this tool to get price information",
    "parameters": {
        "type": "object",
        "properties": {
            "question": {
                "type": "string",
                "description": "Question asked by the user"
            }
        },
        "required": ["question"]
    }
}

type or paste code here

Does anyone have suggestions or best practices for making these API calls more reliable? Any advice on error handling, retries, or any other techniques would be greatly appreciated. Thanks in advance!

Robust is somewhat ambiguous, ranging from “fault tolerant” to “high quality” or “fully-featured” in interpretation.

However, in getting crypto exchange rates, not only could you use more natural language than “coin” and also tell the AI what the return is going to look like, but you can also constrain the AI strings to only those that the tool supports by using “enum”.

Here is my instructing an AI I made to improve tools and functions:

get_crypto_historical_data_by_id_desc = {
    "name": "get_crypto_historical_data_by_id",
    "description": ( "This function retrieves historical exchange rate data for a specific cryptocurrency on a specified date. \n"
                   "The return is an object containing the date, cryptocurrency symbol, opening price, highest price, lowest price, closing price, and volume. \n"
                   "This function is useful when you need to analyze the price movement of a cryptocurrency on a specific date."),
    "parameters": {
        "type": "object",
        "properties": {
            "crypto_id": {
                "type": "string",
                "enum": ["BTC", "ETH", "XRP", "LTC"],
                "description": ("The unique identifier for the cryptocurrency.\n"
                               "BTC: Bitcoin - The first and most well-known cryptocurrency.\n"
                               "ETH: Ethereum - A cryptocurrency known for its smart contract functionality.\n"
                               "XRP: Ripple - A digital payment protocol and its associated cryptocurrency.\n"
                               "LTC: Litecoin - A peer-to-peer cryptocurrency often considered the silver to Bitcoin's gold.")
            },
            "date": {
                "type": "string",
                "description": "The date for which historical data is required, in the format: dd-mm-yyyy"
            }
        },
        "required": ["crypto_id", "date"]
    }
}

This version of the tool provides a more detailed description of the function and its return value, uses more natural language for the property names, and includes an enum list for the crypto_id property.

The multi-line descriptions within parenthesis use Python’s implicit line continuation to make a single string. The API receives the linefeed escape character and sends the AI a multi-line description.

A web search API (which Google doesn’t have) will only return short descriptions from web pages. That may allow the AI to answer some questions from what are mere hints. You also should return well-described error codes to the AI in lieu of search result empty failures or letting your code crash, so AI can decide if it is worth re-sending functions in a different way or reporting the error to the user. There’s also dates that might error; the description of crypto might give a date range of data also.

1 Like