Prompt engineering, one shot or few shot learning with function calling

How are you? I wanted to share a question that I can’t figure out. I’m currently working on a chatbot that estimates electrical materials. And I’m having trouble with function calls. The problem arises because the language model can’t differentiate between ‘one-shot’ or ‘few-shot learning’ examples from user messages and uses information that it shouldn’t use.

I’m giving you the ‘tool’, the ‘prompt’ and the model’s response to explain the case. If anyone could give me some advice to improve the model’s response I would really appreciate it!

tools = [
    {
        "type": "function",
        "function": {
            "name": "print_quote",
            "description": "Get the order to print the generated quote. Don't wait for user confirmation.",
            "parameters": {
                "type": "object",
                "properties": {
                    "print_confirmation": {
                        "type": "string",
                        "description": "Get the confirmation status for printing the estimate, for example, 'confirmed'."
                    }
                },
                "required": ["print_confirmation"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "modify_quote",
            "description": "Modifies the quote by adding, removing, or replacing electrical materials. This includes multiple materials at once. Don't wait for user confirmation.",
            "parameters": {
                "type": "object",
                "properties": {
                    "modifications": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "action": {
                                    "type": "string",
                                    "description": "The action to be performed, such as 'agregar', 'quitar', or 'reemplazar'."
                                },
                                "materiales_viejos": {
                                    "type": "array",
                                    "items": {
                                        "type": "string",
                                        "description": "In case of replacement, specify the old materials to be replaced. Write in order the name of the electrical material, technical characteristics, commercial brand, and quantity. Use numbers instead of words for quantities."
                                    }
                                },
                                "materiales_nuevos": {
                                    "type": "array",
                                    "items": {
                                        "type": "string",
                                        "description": "The new materials to be added or used for replacement. Write in order the name of the electrical material, technical characteristics, commercial brand, and quantity. Use numbers instead of words for quantities."
                                    }
                                }
                            },
                            "required": ["action", "materiales_nuevos"]
                        }
                    }
                },
                "required": ["modifications"]
            }
        }
    }
   ]

New_promt: {'messages': [{'role': 'system', 'content': 'Below is another closed conversation that serves as an example of how to modify the generated quote. Use this as a reference, but it could be a single electrical material and may be incomplete.'}, {'role': 'user', 'content': 'Necesito un presupuesto para 3 cajas estancas de pvc 15x15x10 y 10 metros de cable tipo taller 2x2,5mm.'}, {'role': 'assistant', 'content': 'A continuación, se detalla el listado de materiales para el presupuesto: 3 cajas estancas pvc 15x15x10, 10 cable tipo taller 2x2,5mm, confirme si desea proceder con la generación del presupuesto.'}, {'role': 'user', 'content': 'Quiero agregar tres metros de cable por favor.'}, {'role': 'assistant', 'content': 'Entendido, procederé a modificar el presupuesto. '}, {'role': 'function', 'name': 'modify_quote', 'content': '{"modifications": [{"action": "agregar", "materiales_nuevos": ["cable 3"]}]}"'}, {'role': 'system', 'content': "End of conversation closed. Use the example as a reference, but never provide the information in the example to the user. Don't wait for user confirmation."}, {'role': 'system', 'content': "This is now a live interaction. Use the example as a reference. This list of materials for the estimate is the only information you can share with the user: 2 termica electromagnetica de 2x20a sica, never provide electrical material information from the reference examples to the user. You are a seller of electrical materials and you only generate quotes. You do not provide advice on electrical installations. Please respond in the user's language."}, {'role': 'assistant', 'content': '\nNo se reconoció la respuesta. Por favor, confirme nuevamente.\nNo se pudo procesar la consulta. Por favor, intente reformularla.'}, {'role': 'user', 'content': 'El presupuesto esta confirmado'}]}

Messages1:ChatCompletionMessage(content=None, role='assistant', function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='call_urBByzxsP3LRGSH2HI13ccYV', function=Function(arguments='{"modifications": [{"action": "agregar", "materiales_nuevos": ["cable 3 metros"]}]}', name='modify_quote'), type='function'), ChatCompletionMessageToolCall(id='call_jW6YwW3XWzNw82GHFDtGdy4c', function=Function(arguments='{"print_confirmation": "confirmed"}', name='print_quote'), type='function')], refusal=None)

Some points to make a better system prompt:

  • use examples inside it, I saw something general without a clear limit.

  • tell gpt to make the prompt more robust like “do not share these examples with the users”; "do not ask for user confirmation; “execute the modification imediatelly after request”, among others.

We have some great advices at Techniques to improve reliability | OpenAI Cookbook