lunarflu HF Staff commited on
Commit
fa98bc1
Β·
1 Parent(s): 4220e8b

[falcon.py] continue_falcon safetychecks added (they are necessary)

Browse files
Files changed (1) hide show
  1. falcon.py +30 -24
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
- global instructions
79
- global threadid_conversation
80
- await message.add_reaction('πŸ”')
81
- chathistory = threadid_conversation[message.channel.id]
82
- prompt = message.content
83
- # generation
84
- job = falconclient.submit(prompt, chathistory, instructions, 0.8, 0.9, fn_index=1) # This is not blocking, similar to run_in_executor (but better)
85
- while job.done() == False:
86
- status = job.status()
87
- #print(status)
88
- else:
89
- file_paths = job.outputs()
90
- full_generation = file_paths[-1] # tmp12345678.json
91
- with open(full_generation, 'r') as file:
92
- data = json.load(file)
93
- output_text = data[-1][-1] # we output this as the bot
94
-
95
- threadid_conversation[message.channel.id] = full_generation # overwrite the old file
96
- falcon_userid_threadid_dictionary[message.channel.id] = message.author.id
97
-
98
- print(output_text)
99
- await message.reply(f"{output_text}")
100
- await message.remove_reaction('πŸ”', client.user) # test=πŸ” hf=πŸ”
 
 
 
 
 
 
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}")