· 4 years ago · Aug 25, 2021, 03:28 AM
1import json
2import os
3import time
4import npu
5import discord
6from discord.ext import commands
7from discord_slash import SlashCommand, SlashContext
8from discord_slash.utils.manage_commands import create_option, create_choice
9
10
11npu.api('REDACTED', deployed=False) # Change API_TOKEN with your personal API token
12# description = "A bot that uses GPT-J to generate text based off a prompt."
13model_id = '60ca2a1e54f6ecb69867c72c'
14text = ['When I visit Bath I will']
15
16client = discord.Client()
17
18
19@client.event
20async def on_ready():
21 print('We have logged in as {0.user}'.format(client))
22 return
23
24
25@client.event
26async def on_message(message):
27 if message.author == client.user:
28 return
29
30 if message.content.startswith('~'):
31 try:
32 kwargs = {
33 'temp': 0.6,
34 'top_p': 0.92,
35 'response_length': 34, # how many response tokens to generate [Int]
36 'remove_input': True, # whether to return your input (Default: False) [Bool]
37 # all params from the transformers library `generate` function are supported
38 }
39 await message.channel.send("Request Received. Processing!")
40 text = message.content
41 text1 = text.replace("~", "")
42 text = [text1]
43 output = npu.predict(model_id, text, kwargs).get_result()[0]
44 for key, value in output.items():
45 print(key, value)
46 # await message.channel.send("```" + text1 + "```")
47 await message.channel.send("```|| " + text1 + " || " + output['generated_text'] + "```")
48 return
49 except Exception as e:
50 print(e)
51 return