|
5 | 5 | CreateChatCompletionRequest, |
6 | 6 | CreateChatCompletionResponse, |
7 | 7 | CreateChatCompletionResponseStream, |
| 8 | + ForecastResponse, |
8 | 9 | HeadlineQuestionsResponse, |
9 | 10 | ListModelResponse, |
10 | 11 | ) |
@@ -145,6 +146,36 @@ def get_headline_questions( |
145 | 146 | ) |
146 | 147 | return HeadlineQuestionsResponse.model_validate(response.content) |
147 | 148 |
|
| 149 | + def get_forecast( |
| 150 | + self, |
| 151 | + query: str, |
| 152 | + lookback: int = 7, |
| 153 | + articles_per_day: int = 1, |
| 154 | + method: Literal["nl", "kw", "both"] = "kw", |
| 155 | + model: Literal["gpt-4o"] = "gpt-4o", |
| 156 | + *, |
| 157 | + http_headers: Optional[Dict] = None, |
| 158 | + ) -> ForecastResponse: |
| 159 | + """ |
| 160 | + Get an expert forecast, complete with full sources |
| 161 | + and reasoning. |
| 162 | +
|
| 163 | + https://docs.asknews.app/en/reference#get-/v1/chat/forecast |
| 164 | + """ |
| 165 | + response = self.client.request( |
| 166 | + method="GET", |
| 167 | + endpoint="/v1/chat/forecast", |
| 168 | + headers=http_headers, |
| 169 | + query={ |
| 170 | + "query": query, |
| 171 | + "lookback": lookback, |
| 172 | + "articles_per_day": articles_per_day, |
| 173 | + "method": method, |
| 174 | + "model": model, |
| 175 | + }, |
| 176 | + ) |
| 177 | + return ForecastResponse.model_validate(response.content) |
| 178 | + |
148 | 179 |
|
149 | 180 | class AsyncChatAPI(BaseAPI): |
150 | 181 | """ |
@@ -280,3 +311,33 @@ async def get_headline_questions( |
280 | 311 | query={"queries": queries}, |
281 | 312 | ) |
282 | 313 | return HeadlineQuestionsResponse.model_validate(response.content) |
| 314 | + |
| 315 | + async def get_forecast( |
| 316 | + self, |
| 317 | + query: str, |
| 318 | + lookback: int = 7, |
| 319 | + articles_per_day: int = 1, |
| 320 | + method: Literal["nl", "kw", "both"] = "kw", |
| 321 | + model: Literal["gpt-4o"] = "gpt-4o", |
| 322 | + *, |
| 323 | + http_headers: Optional[Dict] = None, |
| 324 | + ) -> ForecastResponse: |
| 325 | + """ |
| 326 | + Get an expert forecast, complete with full sources |
| 327 | + and reasoning. |
| 328 | +
|
| 329 | + https://docs.asknews.app/en/reference#get-/v1/chat/forecast |
| 330 | + """ |
| 331 | + response = await self.client.request( |
| 332 | + method="GET", |
| 333 | + endpoint="/v1/chat/forecast", |
| 334 | + headers=http_headers, |
| 335 | + query={ |
| 336 | + "query": query, |
| 337 | + "lookback": lookback, |
| 338 | + "articles_per_day": articles_per_day, |
| 339 | + "method": method, |
| 340 | + "model": model, |
| 341 | + }, |
| 342 | + ) |
| 343 | + return ForecastResponse.model_validate(response.content) |
0 commit comments