Hello everyone,
I’m currently working on a project where I use the OpenAI API to call specific functions. However, I’m running into a problem: Even though my Python code doesn’t show any errors, I always get back the same values from the API that I gave as input. I’m not sure what I’m doing wrong and would appreciate any help or insight.
This is what my Python code looks like, actually super simple:
import openai
import json
openai.api_key = "xx"
job_title_A = "Praktikum Finance - Corporate Controlling (m/w/d)"
job_title_B = "(Senior) Medical Director, TB & Infectious Diseases (Berlin)"
job_title_function = [
{
'name': 'extract_information_from_job_title',
'description': 'You are an expert at analyzing job titles. Your job is to filter out the pure job title. Make sure that no information such as location, gender, type of employment, seniority level or other additional information is included when returning the job title.',
'parameters': {
'type': 'object',
'properties': {
'job_title': {
'type': 'string',
'description': 'You are an expert at analyzing job titles. Your job is to filter out the pure job title. Make sure that no information such as location, gender, type of employment, seniority level or other additional information is included when returning the job title.'
}
}
}
}
]
job_titles = [job_title_A,job_title_B]
for sample in job_titles:
response = openai.ChatCompletion.create(
model = 'gpt-3.5-turbo',
messages = [{'role': 'user', 'content': sample}],
functions = job_title_function,
function_call = 'auto'
)
# Loading the response as a JSON object
json_response = json.loads(response['choices'][0]['message']['function_call']['arguments'])
print(json_response)
json_response - output:
{'job_title': 'Praktikum Finance - Corporate Controlling (m/w/d)'}
{'job_title': '(Senior) Medical Director, TB & Infectious Diseases (Berlin)'}
As you can see, the output values are the same as the input values. I’ve tried a lot and just can’t find the error.
Here is the entire response:
print(response)
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1700082538,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"function_call": {
"name": "extract_information_from_job_title",
"arguments": "{\n \"job_title\": \"Praktikum Finance - Corporate Controlling (m/w/d)\"\n}"
}
},
"finish_reason": "function_call"
}
],
"usage": {
"prompt_tokens": 158,
"completion_tokens": 31,
"total_tokens": 189
}
}
Thanks for any help!
UPDATE:
Goal:
I would like to prepare job titles so that only the pure title / description is returned.
Here are examples:
Job title unadjusted:
job_title_1 = "(Senior) HR Partner / (Senior) Personalreferent (m/w/d)"
job_title_2 = "Business Development Manager, OEM (San Francisco Bay Area, Pacific Northwest)"
job_title_3 = "3) Field Service Specialist (Maryland)"
job_title_4 = "Director, Head of R&D Gdansk (Enzymes)"
job_title_5 = "Praktikum Finance - Corporate Controlling (m/w/d)"
job_title_6 = "Senior Medical Director, TB & Infectious Diseases"
Job title cleaned up:
job_title_1 = "HR Partner / Personalreferent"
job_title_2 = "Business Development Manager, OEM"
job_title_3 = "Field Service Specialist"
job_title_4 = "Head of R&D Gdansk (Enzymes)"
job_title_5 = "Finance - Corporate Controlling"
job_title_6 = "Medical Director, TB & Infectious Diseases"
This means that I want to filter out all information that is not directly related to the job description. This could be, for example, the following:
- Location [berlin, munich…]
- Seniority [senior, mid…]
- Gender [(m/f/d)…]
- Employment type [internship, full-time, part-time…]
- Special characters / numbers [3,–, #…]
- and so forth…
If I do this in the chat on the website, it works somewhat. Terms like “internship” and “senior” are still included, but some things have been edited correctly.
(It’s not mega prompt either, but it works 100% better than via the API in my script)