Generate an audience segment based on description

Hello Everone,
We are trying to generate a segmentation criteria using the Openai API. Our goal is to receive a precise formatted criteria from OpenAI where the input will be a descriptive representation of the segment.
For e.g.
Input => All the people whose city is New York City and age ranges within 30 and 40 years
Output => age >= 30 and age <=40; city = New York City

Has anyone encountered such scenario. We thought of model finetuning. Is that the right way to go? Any thoughts or guidance is highly appreciated.

In my experience, since your format is somewhat specific, while the segment and criteria may vary, is to use samples to instruct the LLM. GPT should be able to do it easily. Any specific instruction regarding the generation should be passed as a part of the prompt and the samples should take care of the formatting for you as well as how to handle a variety of situations.

Here is a sample function calling implementation of your use case.

A quick and dirty function definition:

{
        name: 'get_inquiry', 
        description: 'Extract criteria from user text', 
        parameters: {
            type: 'object', 
            properties: {
                inquiries: {
                    type: 'array',
                    items: {
                        type: 'object',
                        properties: {
                            city: {
                                type: 'string', 
                                description: 'Place or city, e.g. New York City'
                            },
                            criteria: {
                                type: 'string',
                                description: 'Criteria, e.g. age, gender',
                                enum: [
                                    'age',
                                    'gender'
                                ]
                            },
                            condition: {
                                type: 'string',
                                description: 'Condition of criteria, e.g. =, >, >=, <=, <',
                                enum: [
                                    '=',
                                    '>',
                                    '>=',
                                    '<=',
                                    '<'
                                ]
                            }
                        }
                    }
                }
            }, 
            required: ['inquiries']
        }
    }

Using your input:
All the people whose city is New York City and age ranges within 30 and 40 years

Response is:

{
  role: 'assistant',
  content: null,
  function_call: {
    name: 'get_inquiry',
    arguments: '{\n' +
      '  "inquiries": [\n' +
      '    {\n' +
      '      "city": "New York City",\n' +
      '      "criteria": "age",\n' +
      '      "condition": ">=",\n' +
      '      "value": 30\n' +
      '    },\n' +
      '    {\n' +
      '      "city": "New York City",\n' +
      '      "criteria": "age",\n' +
      '      "condition": "<=",\n' +
      '      "value": 40\n' +
      '    }\n' +
      '  ]\n' +
      '}'
  }
}

@supershaneski , since my development will be done with Azure OpenAI and unfortunately Azure is still not supporting function_call, I am afraid I cannot use it :frowning_face:
But thank you for the alternative path :clap:

Hello @udm17 , if I understood your approach correctly, you are talking about: Few shot learning, every time I will pass a sample query and result set along with my actual “user supplied input” and ask the model to generate the result in the example result way. Please let me know if I understood it correctly.

If yes, I played around this idea in the chatgpt window actually. Problems I could think of:
a. My example set provided could be not enough or too brief to support “user supplied input”
b. My prompt will consume some tokens and might (just might) impact the generated answer.

It appears there is a schema for a newer “api version” on Azure for functions.

You can review that code and see this supports functions.

Attempt to specify in your API call. I don’t know if this will take redeployment, if it rolled out and ready to go, but at worst you can try.

First verify your implementation of api-version works right by specifying 2023-06-01-preview, and then upgrading that to 2023-07-01-preview.

openai.api_type = "azure"
openai.api_version = "2023-06-01-preview"

Found, as of two weeks ago

Azure now supports function calling in API version 2023-07-01-preview on these models:

  • gpt-4-0613
  • gpt-4-32k-0613

Unfortunately not in gpt-3.5-turbo-0613 yet

Yeah, you got that right. However, there are a few other things I would advise as well:

The behaviour in chatgpt window and the API can be very different because they are different in the backend. I would suggest you use the playground instead as that would be exactly how an API would respond.
Other than that, yes, your token consumption might increase but as long as the prompt is not reaching the limits, should not impact the generation

1 Like