如何从ONEAI NLP API获取输出?Python新手技术求助
如何获取ONEAI API的处理输出(Python)
你的代码已经成功调用ONEAI Pipeline并生成了output对象,只需访问该对象的对应属性,就能获取各个技能的处理结果,具体实现如下:
完整示例代码
# pip install oneai import oneai oneai.api_key = "INSERT_API_KEY" text = 'Natural language processing (NLP) is a subfield of linguistics, computer science, and artificial intelligence concerned with the interactions between computers and human language, in particular how to program computers to process and analyze large amounts of natural language data. The goal is a computer capable of "understanding" the contents of documents, including the contextual nuances of the language within them. The technology can then accurately extract information and insights contained in the documents as well as categorize and organize the documents themselves. Challenges in natural language processing frequently involve speech recognition, natural language understanding, and natural language generation. Based on long-standing trends in the field, it is possible to extrapolate future directions of NLP. As of 2020, three trends among the topics of the long-standing series of CoNLL Shared Tasks can be observed: Interest on increasingly abstract, "cognitive" aspects of natural language, Increasing interest in multilinguality and Elimination of symbolic representations.' pipeline = oneai.Pipeline( steps=[ oneai.skills.Highlights(), oneai.skills.Topics(), oneai.skills.Summarize(), ] ) # 执行Pipeline得到输出对象 output = pipeline.run(text) # 获取并打印各个技能的结果 # 1. 高亮内容 print("=== 高亮片段 ===") for highlight in output.highlights: print(highlight.text) # 2. 提取的主题 print("\n=== 提取的主题 ===") for topic in output.topics: print(f"主题: {topic.topic}, 相关性评分: {topic.score}") # 3. 文本摘要 print("\n=== 文本摘要 ===") print(output.summary.text)
各技能结果的访问方式
- Highlights(高亮):通过
output.highlights获取,返回包含多个高亮片段的列表,每个片段的text属性对应高亮文本内容。 - Topics(主题):通过
output.topics获取,返回主题列表,每个主题对象包含topic(主题名称)、score(相关性评分)等字段。 - Summarize(摘要):通过
output.summary.text直接获取生成的摘要文本。
你可以根据需求,将这些结果存储到变量、写入文件或进行后续业务处理。
内容的提问来源于stack exchange,提问作者lior engel
相关产品推荐
相关产品推荐

