-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenwiki.py
72 lines (63 loc) · 1.7 KB
/
genwiki.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import google.generativeai as genai
import wikipediaapi
# Configure API Key
genai.configure(api_key="AIzaSyAB5TJt9oaOCxYHHHB_ElnTTOZeTeVQi2E")
# Create Wikipedia API object
wiki_wiki = wikipediaapi.Wikipedia(
language='en',
user_agent="YourAppName/1.0 (your.email@example.com)"
)
# Get the name of the politician from the environment variable
name = os.getenv('POLITICIAN_NAME')
def get_wikipedia_link(official_name):
page = wiki_wiki.page(official_name)
if page.exists():
return page.fullurl # Return the full URL of the Wikipedia page
else:
return f"No Wikipedia page found for {official_name}"
# Create the model configuration
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
generation_config=generation_config,
)
# Start the chat session
chat_session = model.start_chat(
history=[
{
"role": "user",
"parts": [
"Summarize this website",
],
},
{
"role": "model",
"parts": [
"Please provide me with the website address so I can summarize it for you. \n",
],
},
{
"role": "user",
"parts": [
get_wikipedia_link(name),
],
},
{
"role": "model",
"parts": [
"",
],
},
]
)
# Send the summary request
response = chat_session.send_message("Summarize the Wikipedia article into bullet points")
# Print the response
print(response.text)