Spaces:
Paused
Paused
Update bot_main.py
Browse files- bot_main.py +13 -7
bot_main.py
CHANGED
|
@@ -147,6 +147,7 @@ def generate_content1(topic):
|
|
| 147 |
"____,我看妳只是在逃避吧!",
|
| 148 |
"這樣___還有什麼意義嗎?"
|
| 149 |
]
|
|
|
|
| 150 |
base = random.sample(base, 1)
|
| 151 |
|
| 152 |
prompt = f"""
|
|
@@ -156,14 +157,17 @@ def generate_content1(topic):
|
|
| 156 |
請根據這個主題[{topic}]來造類似於上面的句子,要負面一點
|
| 157 |
給我一個句子就好
|
| 158 |
"""
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
-
|
| 165 |
-
for candidate in response.candidates:
|
| 166 |
-
ans = [part.text for part in candidate.content.parts]
|
| 167 |
|
| 168 |
return ans[0] if len(ans) > 0 else None
|
| 169 |
|
|
@@ -171,7 +175,9 @@ def generate_content1(topic):
|
|
| 171 |
async def create_bad_message(topic, n=10):
|
| 172 |
result = []
|
| 173 |
for i in range(n):
|
|
|
|
| 174 |
result = generate_content1(topic)
|
|
|
|
| 175 |
if result is not None:
|
| 176 |
return result
|
| 177 |
return "為什麼要演奏春日影?"
|
|
|
|
| 147 |
"____,我看妳只是在逃避吧!",
|
| 148 |
"這樣___還有什麼意義嗎?"
|
| 149 |
]
|
| 150 |
+
|
| 151 |
base = random.sample(base, 1)
|
| 152 |
|
| 153 |
prompt = f"""
|
|
|
|
| 157 |
請根據這個主題[{topic}]來造類似於上面的句子,要負面一點
|
| 158 |
給我一個句子就好
|
| 159 |
"""
|
| 160 |
+
try:
|
| 161 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 162 |
+
response = model.generate_content(prompt)
|
| 163 |
+
|
| 164 |
+
# Assuming response.candidates is iterable and contains a 'content' attribute
|
| 165 |
+
for candidate in response.candidates:
|
| 166 |
+
ans = [part.text for part in candidate.content.parts]
|
| 167 |
+
except error:
|
| 168 |
+
ans=[]
|
| 169 |
|
| 170 |
+
|
|
|
|
|
|
|
| 171 |
|
| 172 |
return ans[0] if len(ans) > 0 else None
|
| 173 |
|
|
|
|
| 175 |
async def create_bad_message(topic, n=10):
|
| 176 |
result = []
|
| 177 |
for i in range(n):
|
| 178 |
+
print("gen",i)
|
| 179 |
result = generate_content1(topic)
|
| 180 |
+
print("end_gen",i)
|
| 181 |
if result is not None:
|
| 182 |
return result
|
| 183 |
return "為什麼要演奏春日影?"
|