How to get a limited list output in chatgpt function calling?

Hello,

I plan to write the following application: the application should receive a personalized text, such as a letter of motivation, CV, etc. and then be analyzed by chatgpt. I have ready-made lists, such as jobs ([computer scientist, data analyst, etc.]) and want to let chatgpt use the input text to select which job names might be interesting for the author of the text. Of course, for this I want to get a list data structure from chatGPT.

I chose chatgpt function calling. This function is also good if, for example, you use enum=[String1,String2] to give example strings from which chatgpt can select the answer. But as soon as you don’t want to return a string but rather a list, in my opinion there is no way to specify an enum.

That’s why I tried to implement this in python as follows:

def find_jobs(input_text, jobs_list):

openai.api_key = api_key

prompt = f"I search for which Jobs: {jobs_list} might interest the author of the text using the following input text: {input_text}. Select the 5 to 10 most suitable jobs and return them, nothing more and not less, that's important!"

functions = [
    {
        "name": "extract_BerufeFromText",
        "description": "Find 5 to 10 jobs that apply to this person.",
        "parameters": {
            "type": "object",
            "properties": {
                "Jobs": {
                    "type": "array",
                    "description": "5 to 10 jobs that apply to the person.",
                    "items": {
                        "type": "string"
                    }
                }
            },
            "required": ["jobs"]
        }
    }
]

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo-0613",
    temperature=0,
    messages=[
        {
            "role": "system",
            "content": "useful assistant that analyzes texts."
        },
        {
            "role": "user",
            "content": prompt
        }
    ],
    functions=functions,
    function_call={
        "name": functions[0]["name"]
    }
)

Jobs_str = response["choices"][0]["message"]["function_call"]["arguments"]
Jobs_dict = json.loads(arguments_str)
return Jobs_dict	

The problem is, chatGPT just always returns the entire job list, no matter which prompt I use. My question now is, is there a way to get the result I want? Maybe someone knows another method to implement this or maybe someone knows tricks for building better prompts, I would be grateful for any tips and suggestions.
In the long run the application should provide answers for not only the jobs of the input text but maybe also their hard skills etc. Maybe someone has suggestions on how I can implement it or why my prompt seems to be ignored.

I’m going to interpret the application as I understand it:

  • A resume, curriculum vitae, or cover letter is suppled by a user;
  • A list of career fields with job titles is supplied by the programmer;
  • The AI shall choose job titles that are most suitable and compelling to the job seeker.
    (alternate interpretation: - job listings, as might be found in a job board or job opening pages are the list)

The AI thus acts as a compatible job finder or a career counselor.

I’ll go right into tips.

Berufe is not translated.
The Jobs property is capitalized but its requirement is not.
The function description is a command to the AI, but should be a description of the function.

A system message is best when it follows an expected format, like “You are JobHunter, an AI career counselor that helps match user skills and interests to available job titles from a list. (add my own description from above)”

Then I suggest this form for user prompt:

// Job list:

jobs = [“plumber”, “pipefitter”, “prompt engineer”,…]

-–

// My CV and other career path and skill information

I have a long career in …

-–

// AI task

By analyzing my career documents, recommend the top 5 careers from the job list that suit me.

finally that function should illustrate why it is the correct one to be called for user input, regardless of any requirement set.

“Prints career lists to user interface in formatted output; required format for any lists of careers to be displayed to user”


Hope that gives ideas.

Thank you for your answer. I had slight translation mistakes, he main code is in german.
here is my new code with an example so you can try your idea:

import json
import openai

def JobList():
openai.api_key = api_key

prompt = f"""

        Job List:

        jobs = [“software developer”, “data analyst”, “prompt engineer”,"teacher", 
        "doctor"]

        My CV:

        'Name: John Smith
        Email: john.smith@example.com
        Phone: (123) 456-7890
        LinkedIn: linkedin.com/in/johnsmith

        Objective:
        Highly motivated software developer with a strong background in web 
        development and a passion for creating efficient, user-friendly 
        applications. Seeking an opportunity to contribute my skills and expertise 
        to a dynamic team.

        Education:
        - Bachelor of Science in Computer Science
        XYZ University
        Graduated: May 20XX

        Skills:
        - Programming Languages: Python, Java, JavaScript
        - Web Development: HTML, CSS, React, Node.js
        - Database Management: SQL, MongoDB
        - Version Control: Git
        - Problem Solving and Algorithm Development

        Experience:
        Software Developer Intern
        ABC Tech Solutions
        May 20XX - August 20XX
        - Assisted in the development of web-based applications using React and 
        Node.js
        - Collaborated with senior developers to design and implement new 
       features
        - Conducted code reviews and identified areas for optimization

        Projects:
        1. E-commerce Website
        - Developed a responsive e-commerce website using React and 
         integrated payment processing
        - Implemented user authentication and product catalog features

        2. Task Management App
        - Created a task management application with real-time updates using 
       Node.js and MongoDB
        - Designed a user-friendly interface for adding, editing, and completing 
       tasks

        Certifications:
        - Certified Full-Stack Developer (XYZ Institute)
        - AWS Certified Cloud Practitioner

        Languages:
        - English (Fluent)
        - Spanish (Intermediate)

        References available upon request.'


        AI task:

        By analyzing my career documents, recommend the top 2 careers from 
        the job list that suit me. It is import to limit the answer to 2 careers only!
          """

functions = [
    {
        "name": "extract_JobsFromText",
        "description": "Finds 2 jobs that apply to this person.",
        "parameters": {
            "type": "object",
            "properties": {
                "Jobs": {
                    "type": "array",
                    "description": "2 jobs that apply to the person.",
                    "items": {
                        "type": "string"
                    }
                }
            },
            "required": ["Jobs"]
        }
    }
]

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo-0613",
    temperature=0,
    messages=[
        {
            "role": "system",
            "content": "You are a JobHunter, an AI career counselor that helps 
             match user skills and interests to available job titles from a list."
        },
        {
            "role": "user",
            "content": prompt
        }
    ],
    functions=functions,
    function_call={
        "name": functions[0]["name"]
    }
)

Jobs_str = response["choices"][0]["message"]["function_call"]["arguments"]
Jobs_dict = json.loads(Jobs_str)
return Jobs_dict

print(JobList())

output: {‘Jobs’: [‘software developer’, ‘data analyst’, ‘prompt engineer’, ‘teacher’, ‘doctor’]}

again the answer is the wohle job list. I just cannot find a way to limit the job list output. It would be really helpful if you have another idea to limit the result or which of your aspects I haven’t implemented yet. Thanks a lot