Structured Output
Athena can return structured output if you pass it the desired schema using chain.structured_parse()
:
1
Set up environment
1 !pip install -U athena-intelligence
1 import json 2 import pandas as pd 3 import os 4 5 ATHENA_API_KEY = os.environ["ATHENA_API_KEY"] 6 7 from athena import Model, Tools 8 from athena.client import AsyncAthena 9 10 athena = AsyncAthena( 11 api_key=ATHENA_API_KEY, 12 )
2
Set up a sample search query:
Write a search request and what you want Athena to do with search results.
1 message = await async_athena.tools.tool_first_workflow( 2 3 model=ToolModels.MISTRAL_LARGE_0224, 4 tool_name="tavily_search", 5 content="Summarize information on the topic", 6 tool_kwargs={"query": "AI advances in April 2024"}, 7 8 ) 9 display(Markdown(message.output_message))
1 Based on the search results, it appears that Generative AI (Gen AI) is a significant technological advancement that has the potential to add up to $4.4 trillion in economic value to the global economy. However, companies are finding it challenging to capture this value. Gen AI is particularly exciting in the business world and is being used in various sectors such as manufacturing and the entertainment industry. 2 3 Stanford University's 2024 AI Index has charted the meteoric rise of AI tools, and AI is now outperforming humans at basic tasks, necessitating new benchmarks. The power of Gen AI, combined with traditional AI, is expected to provide even more help in the future. 4 5 However, the use of Gen AI in the workplace is not without its challenges. Organizations must have a clear policy around Gen AI and be wary of 'shadow AI' - the unofficial use of AI in the workplace by employees without IT approval or oversight. 6 7 The Gartner Hype Cycle positions Gen AI at the 'Peak of Inflated Expectations,' on the cusp of a slide into the 'Trough of Disillusionment,' indicating a relatively underwhelming transition period. Despite this, many leaders expect substantial transformative impacts in the short term. 8 9 In terms of regulations, policymakers have been drawing up tough new regulations, with Biden’s executive order coming out in October and the European Union’s AI Act being finally agreed in December. 10 11 In conclusion, while Gen AI holds immense potential, it also presents challenges in terms of value capture, unofficial use, and regulations.
3
Use structured_parse() to return structured output
1 from athena import StructuredParseInParsingModel 2 structured_output = athena.chain.structured_parse( 3 text_input=message.output_message, 4 custom_type_dict={"news": {"news_item_1": "news_content_1", "news_item_2": "news_content_2"}}, 5 parsing_model=StructuredParseInParsingModel.MISTRAL_LARGE_0224, 6 ) 7 structured_output.result
1 {'news': {'news_item_1': 'Generative AI (Gen AI) is a significant technological advancement that has the potential to add up to $4.4 trillion in economic value to the global economy. However, companies are finding it challenging to capture this value. Gen AI is particularly exciting in the business world and is being used in various sectors such as manufacturing and the entertainment industry.', 2 'news_item_2': "Stanford University's 2024 AI Index has charted the meteoric rise of AI tools, and AI is now outperforming humans at basic tasks, necessitating new benchmarks. The power of Gen AI, combined with traditional AI, is expected to provide even more help in the future.", 3 'news_item_3': "However, the use of Gen AI in the workplace is not without its challenges. Organizations must have a clear policy around Gen AI and be wary of 'shadow AI' - the unofficial use of AI in the workplace by employees without IT approval or oversight.", 4 'news_item_4': "The Gartner Hype Cycle positions Gen AI at the 'Peak of Inflated Expectations,' on the cusp of a slide into the 'Trough of Disillusionment,' indicating a relatively underwhelming transition period. Despite this, many leaders expect substantial transformative impacts in the short term.", 5 'news_item_5': 'In terms of regulations, policymakers have been drawing up tough new regulations, with Biden’s executive order coming out in October and the European Union’s AI Act being finally agreed in December.', 6 'news_item_6': 'In conclusion, while Gen AI holds immense potential, it also presents challenges in terms of value capture, unofficial use, and regulations.'}}