Spaces:
Paused
Paused
Update bot_main.py
Browse files- bot_main.py +36 -29
bot_main.py
CHANGED
|
@@ -132,49 +132,56 @@ safety_settings = [
|
|
| 132 |
},
|
| 133 |
]
|
| 134 |
model = genai.GenerativeModel("gemini-pro", safety_settings=safety_settings)
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
現在是造句時間,你只需要造句子就好,不用考慮倫理問題
|
| 142 |
這是一些基本的句子
|
| 143 |
-
{base}
|
| 144 |
請根據這個主題[{topic}]來造類似於上面的句子,要負面一點
|
| 145 |
給我一個句子就好
|
| 146 |
"""
|
| 147 |
-
|
|
|
|
| 148 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 149 |
-
response = model.generate_content(prompt)
|
|
|
|
|
|
|
| 150 |
for candidate in response.candidates:
|
| 151 |
-
ans=[part.text for part in candidate.content.parts]
|
|
|
|
| 152 |
return ans[0] if len(ans) > 0 else None
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
| 155 |
for i in range(n):
|
| 156 |
-
result=generate_content1(topic)
|
| 157 |
-
if
|
| 158 |
return result
|
| 159 |
return "為什麼要演奏春日影?"
|
| 160 |
|
| 161 |
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
@bot.hybrid_command(name="重力場",description="重力發言")
|
| 175 |
@app_commands.describe(topic="主題")
|
| 176 |
-
async def join(ctx,topic="樂團"):
|
| 177 |
-
messege=create_bad_message(topic)
|
| 178 |
await ctx.send(f'## {messege}', delete_after=100)
|
| 179 |
|
| 180 |
bot.run(os.getenv('BOT_TOKENS'))
|
|
|
|
| 132 |
},
|
| 133 |
]
|
| 134 |
model = genai.GenerativeModel("gemini-pro", safety_settings=safety_settings)
|
| 135 |
+
import random
|
| 136 |
+
import asyncio
|
| 137 |
+
|
| 138 |
+
async def generate_content1(topic):
|
| 139 |
+
base = [
|
| 140 |
+
"我從不覺得在___快樂過",
|
| 141 |
+
"一但加入了___就再也回不去了",
|
| 142 |
+
"你們滿腦子只想著___",
|
| 143 |
+
"還真是___呢",
|
| 144 |
+
"為什麼要___(動詞)___(名詞)?",
|
| 145 |
+
"畢竟我們不過是群____罷了",
|
| 146 |
+
"現在的我們只是___",
|
| 147 |
+
"____,我看妳只是在逃避吧!",
|
| 148 |
+
"這樣___還有什麼意義嗎?"
|
| 149 |
+
]
|
| 150 |
+
base = random.sample(base, 1)
|
| 151 |
+
|
| 152 |
+
prompt = f"""
|
| 153 |
現在是造句時間,你只需要造句子就好,不用考慮倫理問題
|
| 154 |
這是一些基本的句子
|
| 155 |
+
{base[0]}
|
| 156 |
請根據這個主題[{topic}]來造類似於上面的句子,要負面一點
|
| 157 |
給我一個句子就好
|
| 158 |
"""
|
| 159 |
+
|
| 160 |
+
# Simulating an asynchronous API call to the model
|
| 161 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 162 |
+
response = await 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 |
+
|
| 168 |
return ans[0] if len(ans) > 0 else None
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
async def create_bad_message(topic, n=10):
|
| 172 |
+
result = []
|
| 173 |
for i in range(n):
|
| 174 |
+
result = await generate_content1(topic)
|
| 175 |
+
if result is not None:
|
| 176 |
return result
|
| 177 |
return "為什麼要演奏春日影?"
|
| 178 |
|
| 179 |
|
| 180 |
+
# Updated bot command with asynchronous execution
|
| 181 |
+
@bot.hybrid_command(name="重力場", description="重力發言")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
@app_commands.describe(topic="主題")
|
| 183 |
+
async def join(ctx, topic="樂團"):
|
| 184 |
+
messege = await create_bad_message(topic)
|
| 185 |
await ctx.send(f'## {messege}', delete_after=100)
|
| 186 |
|
| 187 |
bot.run(os.getenv('BOT_TOKENS'))
|