正文
此外,Responses API还带来了多项易用性改进,包括:
unified item-based design(简化了数据结构), simpler polymorphism(减少复杂性), intuitive streaming events(实时获取结果), 和SDK helpers,
例如 `response.output_text`,方便开发者轻松访问模型的文本输出。
Responses API希望轻松将OpenAI模型和内置工具集成到其应用中的开发者设计,无需处理多个API或外部供应商集成的复杂性。此外,该API还简化了在OpenAI平台上存储数据的过程,使开发者能够利用诸如追踪(tracing)和评估(evaluations)等功能来评估Agent的性能。
下面举例看看Responses API是如何和各种实用工具结合使用的。
网页搜索
开发者现在可以通过网络获取快速、最新的答案,并且这些答案会附有清晰且相关的信息来源引用。在Responses API中,当使用 gpt-4o 和 gpt-4o-mini 时,网页搜索作为一项工具可供调用,并且可以与其他工具或函数调用结合使用。
const response = await openai.responses.create({
model: "gpt-4o",
tools: [ { type: "web_search_preview" } ],
input: "What was a positive news story that happened today?",
});
console.log(response.output_text);
文件搜索
开发者现在可以使用经过改进的文件搜索工具,轻松地从大量文档中检索相关信息。该工具支持多种文件类型、查询优化、元数据过滤和自定义重排序,能够提供快速且准确的搜索结果。同样,通过 Responses API,只需几行代码即可完成集成。
const productDocs = await openai.vectorStores.create({
name: "Product Documentation",
file_ids: [file1.id, file2.id, file3.id],
});
const