I want to use Function parameters in my Prompt

Hi, I want to create a function that generates a request to GPT based on given parameters. However, I did not get the given parameters in the placeholders in the message e.g. {process_type}.
For example, if I pass the type ‘Order to Cash’ and the industry ‘Automotive’ i get the following response:

{
"process_type": "Quality Control",
"industry": "Manufacturing",
"compliance": TRUE,
"description": "The Quality Control process in the Manu...."
}

I would like to see the passed parameters here.

I have implemented the request as follows (Note the placeholders in the message, which are identified by the characters “{” / “}”):

def generate_description(process_type, industry, compliance):
    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[
            {
                "role": "user",
                "content": "Generate a description for a '{process_type}' process in the '{industry}' industry that is {'compliant' if {compliance} else 'not compliant'} with ISO9001:2015. return a JSON output.",
            },
        ],
        response_format={"type": "json_object"},
    )

    #print(response)
    response_dict = json.loads(response.choices[0].message.content)
    return response_dict

Do you have any ideas on how I can pass the parameters as a prompt?

After some trial and error, I came to the following conclusion:
Variables must be in brackets, without inverted commas.
If you want to use brackets, you have to write them twice.

With the following code, I was able to make my query dynamic:

def generate_description(process_type, industry, compliance):
    if compliance:
        status = "compliant"
    else:
        status = "not compliant"

    prompt = f"""
    Generate a textual business process description for a {process_type} process in the {industry} industry that is {status} with ISO9001:2015. Return it as JSON output in the style: 'process_type= {process_type}', 'industry={industry}', 'compliance={compliance}', 'description',

    An example Output for the Parameters process_type' = 'Order to cash' , industry='Automotive, compliance='TRUE' looks like the following:
    {{
    "process_type": "Order to cash",
    "industry": "Automotive",
    "compliance": TRUE,
    "description": "1. Order Placement: \\n   a. Customer selects vehicle or parts via a website, at a dealership, or through a direct sales team. \\n   b. Sales representative reviews the order requirements and confirms availability. \\n   c. Customer provides payment information and delivery details. \\n   d. Order is logged into the ERP system with a unique order number for tracking. \\n2. Credit Approval: \\n   a. Credit department reviews customer's credit history and payment terms. \\n   b. Credit approval is documented, signed off, and stored in the ERP system. \\n3. Order Fulfillment: \\n   a. Production planning schedules the assembly based on order specifics and inventory availability. \\n   b. Quality assurance conducts checks at various stages of production to ensure compliance with specifications. \\n   c. Final inspection is performed, and a quality certificate is issued for the vehicle or parts. \\n4. Shipping and Delivery: \\n   a. Logistics department arranges appropriate transportation based on the delivery location and customer requirements. \\n   b. Shipping documents are prepared, including bill of lading, shipping invoice, and export documentation if applicable. \\n   c. Vehicle or parts are delivered to the customer, and delivery confirmation is recorded in the ERP system. \\n5. Invoicing: \\n   a. Finance department generates an invoice based on the delivery and contract terms. \\n   b. Invoice is sent to the customer electronically or by mail. \\n   c. Payment terms, typically 30 days, are enforced, with follow-ups for overdue accounts. \\n6. Payment Collection: \\n   a. Payments are processed through bank transfers, credit cards, or checks. \\n   b. Payment receipts are recorded, and the ERP system is updated. \\n7. Customer Service and Feedback: \\n   a. Customer service is available for inquiries, complaints, or returns. \\n   b. Feedback is solicited through surveys or direct contact. \\n   c. Feedback is analyzed, and improvements are proposed and tracked for future implementation."
    }}
    
    Please note that the data should be read by a JSON parser later.
    """
    response = client.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "user", "content": prompt},
        ],
        response_format={"type": "json_object"},
    )

1 Like

If you are using a docstring (the triple-quotes), you’ll not need to double-escape (and thus send) \\n. There also can be no indent that you don’t actually want sent.

You might actually take a look at the function calling API docs if you want an actual function the AI uses to reply to the user instead of just formatted output.