|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import Any, Dict, List, Literal, Optional, Union |
| 4 | + |
| 5 | +from pydantic import BaseModel, ConfigDict, Field |
| 6 | +from typing_extensions import Annotated |
| 7 | + |
| 8 | +from asknews_sdk.dto.base import BaseSchema |
| 9 | +from asknews_sdk.dto.chat import WebSearchResult |
| 10 | +from asknews_sdk.dto.news import SearchResponseDictItem |
| 11 | + |
| 12 | + |
| 13 | +class DeepNewsSources(BaseModel): |
| 14 | + news: Annotated[List[SearchResponseDictItem], Field(title="News")] |
| 15 | + web: Annotated[List[WebSearchResult], Field(title="Web")] |
| 16 | + |
| 17 | + |
| 18 | +class CreateDeepNewsRequestMessage(BaseModel): |
| 19 | + role: Annotated[str, Field(title="Role")] |
| 20 | + content: Annotated[str, Field(title="Content")] |
| 21 | + name: Annotated[Optional[str], Field(None, title="Name")] |
| 22 | + function_call: Annotated[Optional[Dict[str, Any]], Field(None, title="Function Call")] |
| 23 | + |
| 24 | + |
| 25 | +class CreateDeepNewsResponseChoice(BaseModel): |
| 26 | + index: Annotated[int, Field(title="Index")] |
| 27 | + message: CreateDeepNewsRequestMessage |
| 28 | + finish_reason: Annotated[Optional[str], Field(None, title="Finish Reason")] |
| 29 | + |
| 30 | + |
| 31 | +class CreateDeepNewsResponseStreamChoice(BaseModel): |
| 32 | + index: Annotated[int, Field(title="Index")] |
| 33 | + delta: CreateDeepNewsRequestMessage |
| 34 | + finish_reason: Annotated[Optional[str], Field(None, title="Finish Reason")] |
| 35 | + |
| 36 | + |
| 37 | +class CreateDeepNewsResponseUsage(BaseModel): |
| 38 | + prompt_tokens: Annotated[int, Field(title="Prompt Tokens")] |
| 39 | + completion_tokens: Annotated[int, Field(title="Completion Tokens")] |
| 40 | + total_tokens: Annotated[int, Field(title="Total Tokens")] |
| 41 | + |
| 42 | + |
| 43 | +class CreateDeepNewsRequest(BaseSchema): |
| 44 | + model_config = ConfigDict( |
| 45 | + extra="allow", |
| 46 | + ) |
| 47 | + model: Annotated[Optional[str], Field("deepseek", title="Model")] |
| 48 | + messages: Annotated[List[CreateDeepNewsRequestMessage], Field(title="Messages")] |
| 49 | + temperature: Annotated[Optional[float], Field(0.9, title="Temperature")] |
| 50 | + top_p: Annotated[Optional[float], Field(1.0, title="Top P")] |
| 51 | + n: Annotated[Optional[int], Field(1, title="N")] |
| 52 | + stream: Annotated[Optional[bool], Field(False, title="Stream")] |
| 53 | + stop: Annotated[Optional[Union[str, List[str]]], Field(None, title="Stop")] |
| 54 | + max_tokens: Annotated[Optional[int], Field(9999, title="Max Tokens")] |
| 55 | + presence_penalty: Annotated[Optional[int], Field(0, title="Presence Penalty")] |
| 56 | + frequency_penalty: Annotated[Optional[int], Field(0, title="Frequency Penalty")] |
| 57 | + user: Annotated[Optional[str], Field(None, title="User")] |
| 58 | + inline_citations: Annotated[ |
| 59 | + Optional[Literal["markdown_link", "numbered", "none"]], |
| 60 | + Field("markdown_link", title="Type of inline citation formatting."), |
| 61 | + ] |
| 62 | + journalist_mode: Annotated[ |
| 63 | + Optional[bool], |
| 64 | + Field( |
| 65 | + True, |
| 66 | + title=( |
| 67 | + "Activate journalist mode, with improved alignment for making claims" |
| 68 | + "with supporting evidence. Improved journalistic style." |
| 69 | + ), |
| 70 | + ), |
| 71 | + ] |
| 72 | + asknews_watermark: Annotated[ |
| 73 | + Optional[bool], Field(True, title='Append "Generated by AskNews AI" watermark') |
| 74 | + ] |
| 75 | + append_references: Annotated[Optional[bool], Field(True, title="Append References or not")] |
| 76 | + conversational_awareness: Annotated[ |
| 77 | + Optional[bool], Field(False, title="Conversational Awareness") |
| 78 | + ] |
| 79 | + filter_params: Annotated[ |
| 80 | + Optional[Dict[str, Any]], |
| 81 | + Field(None, title="Any filter param available on the /news endpoint."), |
| 82 | + ] |
| 83 | + sources: Annotated[Optional[List[str]], Field(["asknews"], title="Sources")] |
| 84 | + search_depth: Annotated[Optional[int], Field(2, title="Search Depth")] |
| 85 | + max_depth: Annotated[Optional[int], Field(4, title="Max Depth")] |
| 86 | + |
| 87 | + |
| 88 | +class CreateDeepNewsResponse(BaseSchema): |
| 89 | + id: Annotated[str, Field(title="Id")] |
| 90 | + created: Annotated[int, Field(title="Created")] |
| 91 | + object: Annotated[Optional[str], Field("chat.completion", title="Object")] |
| 92 | + model: Annotated[Optional[str], Field("deepseek", title="Model")] |
| 93 | + usage: CreateDeepNewsResponseUsage |
| 94 | + choices: Annotated[List[CreateDeepNewsResponseChoice], Field(title="Choices")] |
| 95 | + sources: Annotated[DeepNewsSources, Field(title="Sources")] |
| 96 | + |
| 97 | + |
| 98 | +class CreateDeepNewsResponseStream(BaseSchema): |
| 99 | + __content_type__ = "text/event-stream" |
| 100 | + |
| 101 | + id: Annotated[str, Field(title="Id")] |
| 102 | + created: Annotated[int, Field(title="Created")] |
| 103 | + object: Annotated[Optional[str], Field("chat.completion.chunk", title="Object")] |
| 104 | + model: Annotated[Optional[str], Field("deepseek", title="Model")] |
| 105 | + usage: CreateDeepNewsResponseUsage |
| 106 | + choices: Annotated[List[CreateDeepNewsResponseStreamChoice], Field(title="Choices")] |
| 107 | + sources: Annotated[DeepNewsSources, Field(title="Sources")] |
0 commit comments