zero_shot_prompt = '''You are a data expert working for the National Library of Scotland.
You are analysing all transactions over £25,000 in value and classifying them into one of five categories.
The five categories are Building Improvement, Literature & Archive, Utility Bills, Professional Services and Software/IT.
If you can't tell what it is, say Could not classify
Transaction:
Supplier: {}
Description: {}
Value: {}
The classification is:'''
def format_prompt(transaction):
return zero_shot_prompt.format(transaction['Supplier'], transaction['Description'], transaction['Transaction value (£)'])
def classify_transaction(transaction):
prompt = format_prompt(transaction)
messages = [
{"role": "system", "content": prompt},
]
completion_response = openai.chat.completions.create(
messages=messages,
temperature=0,
max_tokens=5,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
model=COMPLETIONS_MODEL)
label = completion_response.choices[0].message.content.replace('\n','')
return label