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


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.



Source link

Leave a Comment