使用 OpenAI API 构建 AI 系统
Francesca Donadoni
Curriculum Manager, DataCamp
"我们正在寻求一位高技能的数据科学家,加入位于加州旧金山总部的创新团队。你将参与复杂的数据分析与建模项目,驱动公司的战略决策。 要求:至少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,)
function_definition = [{'type': 'function','function': {'name': 'extract_job_info', 'description': '从输入文本正文提取职位信息', 'parameters': { ...}}]
function_definition = [{ 'type': 'function', 'function': { 'name': 'extract_job_info', 'description': '从输入文本正文提取职位信息','parameters': {'type': 'object', 'properties': 'job': {'type': 'string', 'description': '职位名称'}, 'location': {'type': 'string', 'description': '办公地点'}, ... }}]
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 系统