|
| 1 | +import os |
| 2 | +from typing import Optional, Literal |
| 3 | +from dappier import Dappier |
| 4 | + |
| 5 | +# Initialize the Dappier client |
| 6 | +client = Dappier(api_key=os.getenv("DAPPIER_API_KEY")) |
| 7 | + |
| 8 | +# --- Functions for AI Models --- |
| 9 | + |
| 10 | + |
| 11 | +def real_time_web_search(query: str) -> str: |
| 12 | + """ |
| 13 | + Perform a real-time web search. Access the latest news, stock market data, weather, |
| 14 | + travel information, deals, and more using this AI model. Use when no stock ticker symbol |
| 15 | + is provided. |
| 16 | +
|
| 17 | + Args: |
| 18 | + query: The search query to retrieve real-time information. |
| 19 | +
|
| 20 | + Returns: |
| 21 | + A formatted string containing real-time search results. |
| 22 | + """ |
| 23 | + try: |
| 24 | + return client.search_real_time_data_string(query=query, ai_model_id="am_01j06ytn18ejftedz6dyhz2b15") |
| 25 | + except Exception as e: |
| 26 | + return f"Error: {str(e)}" |
| 27 | + |
| 28 | + |
| 29 | +def stock_market_data_search(query: str) -> str: |
| 30 | + """ |
| 31 | + Perform a real-time stock market data search. Retrieve real-time financial news, |
| 32 | + stock prices, and trade updates with AI-powered insights using this model. Use only when a |
| 33 | + stock ticker symbol is provided. |
| 34 | +
|
| 35 | + Args: |
| 36 | + query: The search query to retrieve real-time stock market information. |
| 37 | +
|
| 38 | + Returns: |
| 39 | + A formatted string containing real-time financial search results. |
| 40 | + """ |
| 41 | + try: |
| 42 | + return client.search_real_time_data_string(query=query, ai_model_id="am_01j749h8pbf7ns8r1bq9s2evrh") |
| 43 | + except Exception as e: |
| 44 | + return f"Error: {str(e)}" |
| 45 | + |
| 46 | + |
| 47 | +# --- Functions for Data Models --- |
| 48 | + |
| 49 | + |
| 50 | +def get_sports_news( |
| 51 | + query: str, |
| 52 | + similarity_top_k: int = 9, |
| 53 | + ref: Optional[str] = None, |
| 54 | + num_articles_ref: int = 0, |
| 55 | + search_algorithm: Literal["most_recent", "semantic", "most_recent_semantic", "trending"] = "most_recent", |
| 56 | +) -> str: |
| 57 | + """ |
| 58 | + Fetch AI-powered Sports News recommendations. Get real-time news, updates, and personalized |
| 59 | + content from top sports sources like Sportsnaut, Forever Blueshirts, Minnesota Sports Fan, |
| 60 | + LAFB Network, Bounding Into Sports, and Ringside Intel. |
| 61 | +
|
| 62 | + Args: |
| 63 | + query: The input string for sports-related content recommendations. |
| 64 | + similarity_top_k: Number of top similar articles to retrieve. |
| 65 | + ref: Optional site domain to prioritize recommendations. |
| 66 | + num_articles_ref: Minimum number of articles to return from the reference domain. |
| 67 | + search_algorithm: The search algorithm to use ('most_recent', 'semantic', 'most_recent_semantic', 'trending'). |
| 68 | +
|
| 69 | + Returns: |
| 70 | + A formatted string containing recommended sports articles. |
| 71 | + """ |
| 72 | + try: |
| 73 | + return client.get_ai_recommendations_string( |
| 74 | + query=query, |
| 75 | + data_model_id="dm_01j0pb465keqmatq9k83dthx34", |
| 76 | + similarity_top_k=similarity_top_k, |
| 77 | + ref=ref or "", |
| 78 | + num_articles_ref=num_articles_ref, |
| 79 | + search_algorithm=search_algorithm, |
| 80 | + ) |
| 81 | + except Exception as e: |
| 82 | + return f"Error: {str(e)}" |
| 83 | + |
| 84 | + |
| 85 | +def get_lifestyle_news( |
| 86 | + query: str, |
| 87 | + similarity_top_k: int = 9, |
| 88 | + ref: Optional[str] = None, |
| 89 | + num_articles_ref: int = 0, |
| 90 | + search_algorithm: Literal["most_recent", "semantic", "most_recent_semantic", "trending"] = "most_recent", |
| 91 | +) -> str: |
| 92 | + """ |
| 93 | + Fetch AI-powered Lifestyle News recommendations. Access current lifestyle updates, analysis, |
| 94 | + and insights from leading lifestyle publications like The Mix, Snipdaily, Nerdable |
| 95 | + and Familyproof. |
| 96 | +
|
| 97 | + Args: |
| 98 | + query: The input string for lifestyle-related content recommendations. |
| 99 | + similarity_top_k: Number of top similar articles to retrieve. |
| 100 | + ref: Optional site domain to prioritize recommendations. |
| 101 | + num_articles_ref: Minimum number of articles to return from the reference domain. |
| 102 | + search_algorithm: The search algorithm to use ('most_recent', 'semantic', 'most_recent_semantic', 'trending'). |
| 103 | +
|
| 104 | + Returns: |
| 105 | + A formatted string containing recommended lifestyle articles. |
| 106 | + """ |
| 107 | + try: |
| 108 | + return client.get_ai_recommendations_string( |
| 109 | + query=query, |
| 110 | + data_model_id="dm_01j0q82s4bfjmsqkhs3ywm3x6y", |
| 111 | + similarity_top_k=similarity_top_k, |
| 112 | + ref=ref or "", |
| 113 | + num_articles_ref=num_articles_ref, |
| 114 | + search_algorithm=search_algorithm, |
| 115 | + ) |
| 116 | + except Exception as e: |
| 117 | + return f"Error: {str(e)}" |
| 118 | + |
| 119 | + |
| 120 | +def get_iheartdogs_content( |
| 121 | + query: str, |
| 122 | + similarity_top_k: int = 9, |
| 123 | + ref: Optional[str] = None, |
| 124 | + num_articles_ref: int = 0, |
| 125 | + search_algorithm: Literal["most_recent", "semantic", "most_recent_semantic", "trending"] = "most_recent", |
| 126 | +) -> str: |
| 127 | + """ |
| 128 | + Fetch AI-powered iHeartDogs content recommendations. Tap into a dog care expert with access |
| 129 | + to thousands of articles covering pet health, behavior, grooming, and ownership from |
| 130 | + iHeartDogs.com. |
| 131 | +
|
| 132 | + Args: |
| 133 | + query: The input string for dog care-related content recommendations. |
| 134 | + similarity_top_k: Number of top similar articles to retrieve. |
| 135 | + ref: Optional site domain to prioritize recommendations. |
| 136 | + num_articles_ref: Minimum number of articles to return from the reference domain. |
| 137 | + search_algorithm: The search algorithm to use ('most_recent', 'semantic', 'most_recent_semantic', 'trending'). |
| 138 | +
|
| 139 | + Returns: |
| 140 | + A formatted string containing recommended dog-related articles. |
| 141 | + """ |
| 142 | + try: |
| 143 | + return client.get_ai_recommendations_string( |
| 144 | + query=query, |
| 145 | + data_model_id="dm_01j1sz8t3qe6v9g8ad102kvmqn", |
| 146 | + similarity_top_k=similarity_top_k, |
| 147 | + ref=ref or "", |
| 148 | + num_articles_ref=num_articles_ref, |
| 149 | + search_algorithm=search_algorithm, |
| 150 | + ) |
| 151 | + except Exception as e: |
| 152 | + return f"Error: {str(e)}" |
| 153 | + |
| 154 | + |
| 155 | +def get_iheartcats_content( |
| 156 | + query: str, |
| 157 | + similarity_top_k: int = 9, |
| 158 | + ref: Optional[str] = None, |
| 159 | + num_articles_ref: int = 0, |
| 160 | + search_algorithm: Literal["most_recent", "semantic", "most_recent_semantic", "trending"] = "most_recent", |
| 161 | +) -> str: |
| 162 | + """ |
| 163 | + Fetch AI-powered iHeartCats content recommendations. Utilize a cat care specialist that |
| 164 | + provides comprehensive content on cat health, behavior, and lifestyle from iHeartCats.com. |
| 165 | +
|
| 166 | + Args: |
| 167 | + query: The input string for cat care-related content recommendations. |
| 168 | + similarity_top_k: Number of top similar articles to retrieve. |
| 169 | + ref: Optional site domain to prioritize recommendations. |
| 170 | + num_articles_ref: Minimum number of articles to return from the reference domain. |
| 171 | + search_algorithm: The search algorithm to use ('most_recent', 'semantic', 'most_recent_semantic', 'trending'). |
| 172 | +
|
| 173 | + Returns: |
| 174 | + A formatted string containing recommended cat-related articles. |
| 175 | + """ |
| 176 | + try: |
| 177 | + return client.get_ai_recommendations_string( |
| 178 | + query=query, |
| 179 | + data_model_id="dm_01j1sza0h7ekhaecys2p3y0vmj", |
| 180 | + similarity_top_k=similarity_top_k, |
| 181 | + ref=ref or "", |
| 182 | + num_articles_ref=num_articles_ref, |
| 183 | + search_algorithm=search_algorithm, |
| 184 | + ) |
| 185 | + except Exception as e: |
| 186 | + return f"Error: {str(e)}" |
| 187 | + |
| 188 | + |
| 189 | +def get_greenmonster_guides( |
| 190 | + query: str, |
| 191 | + similarity_top_k: int = 9, |
| 192 | + ref: Optional[str] = None, |
| 193 | + num_articles_ref: int = 0, |
| 194 | + search_algorithm: Literal["most_recent", "semantic", "most_recent_semantic", "trending"] = "most_recent", |
| 195 | +) -> str: |
| 196 | + """ |
| 197 | + Fetch AI-powered GreenMonster guides and articles. Receive guidance for making conscious |
| 198 | + and compassionate choices benefiting people, animals, and the planet. |
| 199 | +
|
| 200 | + Args: |
| 201 | + query: The input string for eco-friendly and conscious lifestyle recommendations. |
| 202 | + similarity_top_k: Number of top similar articles to retrieve. |
| 203 | + ref: Optional site domain to prioritize recommendations. |
| 204 | + num_articles_ref: Minimum number of articles to return from the reference domain. |
| 205 | + search_algorithm: The search algorithm to use ('most_recent', 'semantic', 'most_recent_semantic', 'trending'). |
| 206 | +
|
| 207 | + Returns: |
| 208 | + A formatted string containing recommended eco-conscious articles. |
| 209 | + """ |
| 210 | + try: |
| 211 | + return client.get_ai_recommendations_string( |
| 212 | + query=query, |
| 213 | + data_model_id="dm_01j5xy9w5sf49bm6b1prm80m27", |
| 214 | + similarity_top_k=similarity_top_k, |
| 215 | + ref=ref or "", |
| 216 | + num_articles_ref=num_articles_ref, |
| 217 | + search_algorithm=search_algorithm, |
| 218 | + ) |
| 219 | + except Exception as e: |
| 220 | + return f"Error: {str(e)}" |
| 221 | + |
| 222 | + |
| 223 | +def get_wishtv_news( |
| 224 | + query: str, |
| 225 | + similarity_top_k: int = 9, |
| 226 | + ref: Optional[str] = None, |
| 227 | + num_articles_ref: int = 0, |
| 228 | + search_algorithm: Literal["most_recent", "semantic", "most_recent_semantic", "trending"] = "most_recent", |
| 229 | +) -> str: |
| 230 | + """ |
| 231 | + Fetch AI-powered WISH-TV news recommendations. Get recommendations covering sports, |
| 232 | + breaking news, politics, multicultural updates, Hispanic language content, entertainment, |
| 233 | + health, and education. |
| 234 | +
|
| 235 | + Args: |
| 236 | + query: The input string for general news recommendations. |
| 237 | + similarity_top_k: Number of top similar articles to retrieve. |
| 238 | + ref: Optional site domain to prioritize recommendations. |
| 239 | + num_articles_ref: Minimum number of articles to return from the reference domain. |
| 240 | + search_algorithm: The search algorithm to use ('most_recent', 'semantic', 'most_recent_semantic', 'trending'). |
| 241 | +
|
| 242 | + Returns: |
| 243 | + A formatted string containing recommended news articles. |
| 244 | + """ |
| 245 | + try: |
| 246 | + return client.get_ai_recommendations_string( |
| 247 | + query=query, |
| 248 | + data_model_id="dm_01jagy9nqaeer9hxx8z1sk1jx6", |
| 249 | + similarity_top_k=similarity_top_k, |
| 250 | + ref=ref or "", |
| 251 | + num_articles_ref=num_articles_ref, |
| 252 | + search_algorithm=search_algorithm, |
| 253 | + ) |
| 254 | + except Exception as e: |
| 255 | + return f"Error: {str(e)}" |
0 commit comments