Extrahera strukturerad data från text

Utveckla AI-system med OpenAI API

Francesca Donadoni

Curriculum Manager, DataCamp

Implementera function calling

 

"Vi söker en erfaren Data Scientist till vårt innovativa team vid företagets huvudkontor i San Francisco, CA. I den här rollen arbetar du med komplexa dataanalys- och modelleringsprojekt som styr våra strategiska beslut. Krav: Minst 3 års erfarenhet av datavetenskap med Python och AWS, Azure eller 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,
)
Utveckla AI-system med OpenAI API

Konfigurera function calling

 

function_definition = [{

'type': 'function',
'function': {
'name': 'extract_job_info', 'description': 'Get the job information from the body of the input text', 'parameters': { ...
}
}]
Utveckla AI-system med OpenAI API

Konfigurera 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'}, ... }
}]
Utveckla AI-system med OpenAI API

Svar

 

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"}
Utveckla AI-system med OpenAI API

Nu kör vi en övning!

Utveckla AI-system med OpenAI API

Preparing Video For Download...