從文字擷取結構化資料

使用 OpenAI API 開發 AI 系統

Francesca Donadoni

Curriculum Manager, DataCamp

實作函式呼叫

 

「我們正在尋找一位資深的 Data Scientist,加入位於 San Francisco, CA 的公司總部。你將參與複雜的資料分析與建模專案,支援公司的策略決策。 需求條件:至少 3 年以 Python 與 AWS、Azure 或 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,
)
使用 OpenAI API 開發 AI 系統

設定函式呼叫

 

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_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...