[falcon.py] continue_falcon safetychecks added (they are necessary)
Browse files
falcon.py
CHANGED
|
@@ -74,30 +74,36 @@ async def try_falcon(interaction, prompt):
|
|
| 74 |
#await thread.send(f"{e} cc <@811235357663297546> (falconprivate error)")
|
| 75 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
| 76 |
async def continue_falcon(message):
|
| 77 |
-
try
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
except Exception as e:
|
| 103 |
print(f"Error: {e}")
|
|
|
|
| 74 |
#await thread.send(f"{e} cc <@811235357663297546> (falconprivate error)")
|
| 75 |
#-------------------------------------------------------------------------------------------------------------------------------------
|
| 76 |
async def continue_falcon(message):
|
| 77 |
+
try
|
| 78 |
+
if not message.author.bot:
|
| 79 |
+
global falcon_userid_threadid_dictionary # tracks userid-thread existence
|
| 80 |
+
if message.channel.id in falcon_userid_threadid_dictionary: # is this a valid thread?
|
| 81 |
+
if falcon_userid_threadid_dictionary[message.channel.id] == message.author.id: # more than that - is this specifically the right user for this thread?
|
| 82 |
+
# call job for falcon
|
| 83 |
+
global instructions
|
| 84 |
+
global threadid_conversation
|
| 85 |
+
|
| 86 |
+
await message.add_reaction('π')
|
| 87 |
+
chathistory = threadid_conversation[message.channel.id]
|
| 88 |
+
prompt = message.content
|
| 89 |
+
# generation
|
| 90 |
+
job = falconclient.submit(prompt, chathistory, instructions, 0.8, 0.9, fn_index=1) # This is not blocking, similar to run_in_executor (but better)
|
| 91 |
+
while job.done() == False:
|
| 92 |
+
status = job.status()
|
| 93 |
+
#print(status)
|
| 94 |
+
else:
|
| 95 |
+
file_paths = job.outputs()
|
| 96 |
+
full_generation = file_paths[-1] # tmp12345678.json
|
| 97 |
+
with open(full_generation, 'r') as file:
|
| 98 |
+
data = json.load(file)
|
| 99 |
+
output_text = data[-1][-1] # we output this as the bot
|
| 100 |
+
|
| 101 |
+
threadid_conversation[message.channel.id] = full_generation # overwrite the old file
|
| 102 |
+
falcon_userid_threadid_dictionary[message.channel.id] = message.author.id
|
| 103 |
+
|
| 104 |
+
print(output_text)
|
| 105 |
+
await message.reply(f"{output_text}")
|
| 106 |
+
await message.remove_reaction('π', client.user) # test=π hf=π
|
| 107 |
|
| 108 |
except Exception as e:
|
| 109 |
print(f"Error: {e}")
|