-
Notifications
You must be signed in to change notification settings - Fork 0
/
details_extractor.py
50 lines (47 loc) · 1.75 KB
/
details_extractor.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
import pprint
import time
import google.generativeai as palm
from google.generativeai.types import safety_types
from prompt import get_prompt
palm.configure(api_key='AIzaSyCtuUpyWk6S5e-eDb1gJvCL7V6wd7Lc_P0')
def details_extractor(article):
models = [m for m in palm.list_models() if 'generateText' in m.supported_generation_methods]
model = models[0].name
print(model)
prompt = get_prompt(article)
completion = palm.generate_text(
model=model,
prompt=prompt,
temperature=0,
max_output_tokens=1500,
safety_settings=[
{
"category": safety_types.HarmCategory.HARM_CATEGORY_DEROGATORY,
"threshold": safety_types.HarmBlockThreshold.BLOCK_NONE
},
{
"category": safety_types.HarmCategory.HARM_CATEGORY_VIOLENCE,
"threshold": safety_types.HarmBlockThreshold.BLOCK_NONE,
},
{
"category": safety_types.HarmCategory.HARM_CATEGORY_TOXICITY,
"threshold": safety_types.HarmBlockThreshold.BLOCK_NONE,
},
{
"category": safety_types.HarmCategory.HARM_CATEGORY_SEXUAL,
"threshold": safety_types.HarmBlockThreshold.BLOCK_NONE,
},
{
"category": safety_types.HarmCategory.HARM_CATEGORY_DANGEROUS,
"threshold": safety_types.HarmBlockThreshold.BLOCK_NONE,
},
{
"category": safety_types.HarmCategory.HARM_CATEGORY_MEDICAL,
"threshold": safety_types.HarmBlockThreshold.BLOCK_NONE,
}
]
)
print(completion.result)
time.sleep(0.1)
return completion.result;
# AIzaSyCDJ28lMyK7UbSUNUN_KeMTZa-rzd0GiWU