Using openAI's response in my own code

Hi all,

My second post here and I’ve been playing with OpenAI for just a day or two, so apologies if this is a dumb question or has already been answered - I searched for it but couldn’t find what I needed.

I have a virtual assistant character in a tool used by a FinTech client of mine. Users of the tool can chat to the assistant aloud and she will respond accordingly. I’d like to use OpenAI to make sense of my user’s answers which come in natural language.

My first challenge is to get the answer to a question like

“When will you want to start withdrawing money from your investment fund?”

and turn it into a date

The user can answer pretty much anything. For example

“Next week”, “When I turn 55”, “When my wife retires”, “when it’s worth twice what I put in”, “On Friday” etc. etc.

In my tests, any of the models returns excellent responses to these phrases, but how can I USE those responses in my code? I mean, how can I turn the model’s response into a date I can use?

Am I even making any sense !?

Hi @georgewoofmoo,

I think the answer may depend on what programming language your app is using.

For example, if you are using PHP, you could use the strtotime function. eg:

$date = strototime('next week');

Will give you a valid date in PHP, or false if the date cannot be determined from the input.

Other programming languages will likely have similar functions.

That may end up being simpler than trying to use an OpenAI prompt to convert the phrase to a date.

If the conversion fails, you can then ask the user to clarify/reword the answer.

I hope that helps,


Thanks @james.collins, I’m actually doing something similar to that already - albeit in JavaScript. The tool does “know” certain things about the user already though, like their birthday, spouse’s and dependents’ birthdays and the user’s retirement age, so being able to convert things like “2 years after I retire” would be extremely powerful (and cool af, of course!).

I’ve had some success with longer prompts so I guess I’ll keep working through.