-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
32 lines (27 loc) · 1 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import httpx
import asyncio
async def fetch_wikipedia_article(article_name):
"""
Fetch the first paragraph of a Wikipedia article from the FastAPI server.
Args:
article_name (str): The name of the Wikipedia article.
Returns:
dict: The JSON response from the FastAPI server containing the title and paragraph.
"""
print(f"fetching article: {article_name}")
url = f"http://127.0.0.1:8000/article/{article_name}"
async with httpx.AsyncClient() as client:
response = await client.get(url)
print(f"received response with status code: {response.status_code}")
if response.status_code == 200:
print("success! parsing response")
return response.json()
else:
print("error: Article not found.")
return {"error": "Article not found"}
async def main():
article_name = "Never_Gonna_Give_You_Up"
result = await fetch_wikipedia_article(article_name)
print(result)
if __name__ == "__main__":
asyncio.run(main())