ksvmuralidhar commited on
Commit
f74ad3d
1 Parent(s): bafe5d3

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +16 -6
api.py CHANGED
@@ -121,13 +121,20 @@ class URLList(BaseModel):
121
  urls: List[str] = Field(..., description="List of URLs of news articles to generate summaries")
122
  key: str = Field(..., description="Authentication Key")
123
 
124
- class Summary(BaseModel):
125
  urls: List[str] = Field(..., description="List of URLs of news articles inputted by the user")
126
- scraped_texts: List[str] = Field(..., description="List of scraped text from input URLs")
127
- scrape_errors: List[str] = Field(..., description="List of errors raised during scraping. One item for corresponding URL")
128
  summaries: List[str] = Field(..., description="List of generated summaries of news articles")
129
- summarizer_error: str = Field(..., description="String specifying error raised during summary.")
130
-
 
 
 
 
 
 
 
131
 
132
  class NewsSummarizerAPIAuthenticationError(Exception):
133
  pass
@@ -138,7 +145,10 @@ def authenticate_key(api_key: str):
138
  raise NewsSummarizerAPIAuthenticationError("Authentication error: Invalid API key.")
139
 
140
 
141
- @app.post("/generate_summary/", response_model=List[Summary])
 
 
 
142
  async def read_items(q: URLList):
143
  try:
144
  logging.warning("Entering read_items()")
 
121
  urls: List[str] = Field(..., description="List of URLs of news articles to generate summaries")
122
  key: str = Field(..., description="Authentication Key")
123
 
124
+ class SuccessfulResponse(BaseModel):
125
  urls: List[str] = Field(..., description="List of URLs of news articles inputted by the user")
126
+ scraped_texts: List[str] = Field(..., description="List of scraped text from input URLs".)
127
+ scrape_errors: List[str] = Field("", description="List of errors raised during scraping. One item for corresponding URL.")
128
  summaries: List[str] = Field(..., description="List of generated summaries of news articles")
129
+ summarizer_error: str = Field("", description="String specifying error raised during summary.")
130
+
131
+ class AuthenticationError(BaseModel):
132
+ urls: List[str] = Field(..., description="List of URLs of news articles inputted by the user")
133
+ scraped_texts: List[str] = Field("", description="List of empty strings as authentication failed")
134
+ scrape_errors: List[str] = Field("", description="List of empty strings as authentication failed")
135
+ summaries: List[str] = Field("", description="List of empty strings as authentication failed")
136
+ summarizer_error: str = Field("Authentication error: Invalid API key.")
137
+
138
 
139
  class NewsSummarizerAPIAuthenticationError(Exception):
140
  pass
 
145
  raise NewsSummarizerAPIAuthenticationError("Authentication error: Invalid API key.")
146
 
147
 
148
+ @app.post("/generate_summary/", response_model=List[SuccessfulResponse],
149
+ responses={
150
+ 401: {"model": AuthenticationError, "description": "authentication Error"}
151
+ })
152
  async def read_items(q: URLList):
153
  try:
154
  logging.warning("Entering read_items()")