テキストから構造化データを抽出する

OpenAI API を使った AI システムの開発

Francesca Donadoni

Curriculum Manager, DataCamp

Function Callingの実装

「弊社では、カリフォルニア州サンフランシスコ本社の革新的なチームに加入する、スキルの高いデータサイエンティストを現在募集しています。 この役割では、当社の戦略的意思決定を支える複雑なデータ分析とモデリングプロジェクトに取り組む機会があります。 要件: Python と AWS、Azure または GCP を用いたデータサイエンティストの経験 3 年以上。」

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,
)
OpenAI API を使った AI システムの開発

Function Callingの設定

function_definition = [{

'type': 'function',
'function': {
'name': 'extract_job_info', 'description': 'Get the job information from the body of the input text', 'parameters': { ...
}
}]
OpenAI API を使った AI システムの開発

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'}, ... }
}]
OpenAI API を使った AI システムの開発

レスポンス

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"}
OpenAI API を使った AI システムの開発

練習しましょう!

OpenAI API を使った AI システムの開発

Preparing Video For Download...