lunarflu HF Staff commited on
Commit
4eeea0f
·
1 Parent(s): ad5f1ed

Synced repo using 'sync_with_huggingface' Github Action

Browse files
Files changed (1) hide show
  1. app.py +60 -7
app.py CHANGED
@@ -558,29 +558,82 @@ async def on_reaction_add(reaction, user): # ctx = await bot.get_context(reac
558
 
559
 
560
  #----------------------------------------------------------------------------------------------------------------------------
561
- chathistory = None
562
 
 
 
 
 
563
 
564
- falcon_chats = []
 
565
  falcon_threads = []
 
 
 
 
 
566
 
567
  @bot.command()
568
  async def falconprivate(ctx):
 
 
 
569
  try:
570
- global falcon_chats
571
  global falcon_threads
 
 
572
  if ctx.channel.id == 1116089829147557999: # initial thread creation inside #falcon
573
- if ctx.author.id not in falcon_chats: # create a new one
574
  thread = await ctx.message.create_thread(name=f'{ctx.author}')
575
- falcon_chats = [ctx.author.id] + falcon_chats
576
  falcon_threads = [thread.id] + falcon_threads
577
  await thread.send(f"Thread created")
578
-
579
- elif ctx.author.id in falcon_chats:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580
  await ctx.reply(f"{ctx.author.mention}, you already have an existing conversation! ")
581
 
582
  if ctx.channel.id in falcon_threads: # subsequent chatting inside threads of #falcon
583
  await ctx.reply(f"inside thread, only {ctx.author} is allowed to chat here")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
584
 
585
  except Exception as e:
586
  print(f"Error: {e}")
 
558
 
559
 
560
  #----------------------------------------------------------------------------------------------------------------------------
 
561
 
562
+ # command 1 = creates thread, name = {ctx.author}
563
+ # on_message =
564
+
565
+ # custom path based on name
566
 
567
+ chathistory = None
568
+ falcon_users = []
569
  falcon_threads = []
570
+ falcon_chats = [] #
571
+
572
+ falcon_id = 0
573
+
574
+ falcon_dictionary = {}
575
 
576
  @bot.command()
577
  async def falconprivate(ctx):
578
+ #todo
579
+ #spinning icon while loading
580
+ #finished icon
581
  try:
582
+ global falcon_users
583
  global falcon_threads
584
+ global falcon_chats
585
+ global falcon_dictionary
586
  if ctx.channel.id == 1116089829147557999: # initial thread creation inside #falcon
587
+ if ctx.author.id not in falcon_users: # create a new one
588
  thread = await ctx.message.create_thread(name=f'{ctx.author}')
589
+ falcon_users = [ctx.author.id] + falcon_users
590
  falcon_threads = [thread.id] + falcon_threads
591
  await thread.send(f"Thread created")
592
+
593
+ # initial generation here
594
+ chathistory = falconclient.predict(
595
+ fn_index=5
596
+ ) # []
597
+ instructions = "The following is a conversation between a highly knowledgeable and intelligent AI assistant, called Falcon, and a human user, called User. In the following interactions, User and Falcon will converse in natural language, and Falcon will answer User's questions. Falcon was built to be respectful, polite and inclusive. Falcon was built by the Technology Innovation Institute in Abu Dhabi. Falcon will never decline to answer a question, and always attempts to give an answer that User would be satisfied with. It knows a lot, and always tells the truth. The conversation begins."
598
+ job = falconclient.submit(prompt, chathistory, instructions, 0.8, 0.9, fn_index=1) # This is not blocking, similar to run_in_executor (but better)
599
+ while job.done() == False:
600
+ status = job.status() # could be spammy, let's test anyways
601
+ print(status)
602
+ else:
603
+ file_paths = job.outputs()
604
+ full_generation = file_paths[-1] # tmp12345678.json
605
+ unique_file = "{}{}".format(ctx.author.id, ".json") # could use ID, more robust
606
+ with open(full_generation, 'r') as file:
607
+ data = json.load(file)
608
+ output_text = data[-1][-1] # we output this as the bot
609
+ falcon_dictionary[ctx.author.id] = full_generation # 1234567890: tmp12345678.json
610
+ print(output_text)
611
+ await ctx.reply(f"{output_text}")
612
+
613
+ elif ctx.author.id in falcon_users:
614
  await ctx.reply(f"{ctx.author.mention}, you already have an existing conversation! ")
615
 
616
  if ctx.channel.id in falcon_threads: # subsequent chatting inside threads of #falcon
617
  await ctx.reply(f"inside thread, only {ctx.author} is allowed to chat here")
618
+ # post all other generations here
619
+ chathistory = falcon_dictionary[ctx.author.id]
620
+
621
+ instructions = "The following is a conversation between a highly knowledgeable and intelligent AI assistant, called Falcon, and a human user, called User. In the following interactions, User and Falcon will converse in natural language, and Falcon will answer User's questions. Falcon was built to be respectful, polite and inclusive. Falcon was built by the Technology Innovation Institute in Abu Dhabi. Falcon will never decline to answer a question, and always attempts to give an answer that User would be satisfied with. It knows a lot, and always tells the truth. The conversation begins."
622
+ job = falconclient.submit(prompt, chathistory, instructions, 0.8, 0.9, fn_index=1) # This is not blocking, similar to run_in_executor (but better)
623
+ while job.done() == False:
624
+ status = job.status() # could be spammy, let's test anyways
625
+ print(status)
626
+ else:
627
+ file_paths = job.outputs()
628
+ full_generation = file_paths[-1] # tmp12345678.json
629
+ unique_file_2 = "{}{}".format(ctx.author.id, ".json") # could use ID, more robust
630
+ with open(full_generation, 'r') as file:
631
+ data = json.load(file)
632
+ output_text = data[-1][-1] # we output this as the bot
633
+ falcon_dictionary[ctx.author.id] = full_generation
634
+
635
+ print(output_text)
636
+ await ctx.reply(f"{output_text}")
637
 
638
  except Exception as e:
639
  print(f"Error: {e}")