Extracting structured data from text

Developing AI Systems with the OpenAI API

Francesca Donadoni

Curriculum Manager, DataCamp

Implementing function calling

 

"We are currently seeking a highly skilled Data Scientist to join our innovative team at the company's headquarters in San Francisco, CA. In this role, you will have the opportunity to work on complex data analysis and modeling projects that drive our strategic decisions. Requirements: Minimum 3 years of experience in data science with Python and AWS, Azure or GCP."

 

from openai import OpenAI

client = OpenAI(api_key="ENTER YOUR KEY 
                HERE")

response= client.chat.completions.create(
    model="gpt-4o-mini",
    messages=messages,

tools=function_definition,
)
Developing AI Systems with the OpenAI API

Setting up function calling

 

function_definition = [{

'type': 'function',
'function': {
'name': 'extract_job_info', 'description': 'Get the job information from the body of the input text', 'parameters': { ...
}
}]
Developing AI Systems with the OpenAI API

Setting up function calling

function_definition = [{
        'type': 'function',
        'function': {
          'name': 'extract_job_info',
          'description': 'Get the job information from the body of the input text',

'parameters': {'type': 'object', 'properties': 'job': {'type': 'string', 'description': 'Job title'}, 'location': {'type': 'string', 'description': 'Office location'}, ... }
}]
Developing AI Systems with the OpenAI API

Response

 

response= client.chat.completions.create(
    model="gpt-4o-mini",
    messages=messages,
    tools=function_definition
)

print(response.choices[0].message.tool_calls[0].function.arguments)
{"job":"Data Scientist","location":"San Francisco, CA"}
Developing AI Systems with the OpenAI API

Let's practice!

Developing AI Systems with the OpenAI API

Preparing Video For Download...