async def generate(cls, config: Model, query: str) -> str: """Generate text using the Neuro API.""" if cls.token is None: raise model.SecretNotFound( "neuro-token not found in secrets.json.") parameters = {"include_result": "true"} headers = {"Authorization": f"Bearer {cls.token}"} payload = { "modelId": config.identifier, "data": query, "input_kwargs": { "response_length": config.response_length, "remove_input": config.remove_input, "temperature": config.temperature, "repetition_penalty": config.repetition_penalty } } data = await cls.post("SyncPredict", params=parameters, json=payload, headers=headers) if data["state"] == "ERROR": # API returned HTTP 200 OK, but there's still an error. status = http.HTTPStatus.OK message = data["result"] raise exceptions.HTTPUnexpected(status, message) return data["result"][0]["generated_text"]
async def generate(cls, config: Model, query: str) -> str: """Generate text using the Hugging Face API.""" if cls.token is None: raise model.SecretNotFound( "hugging-token not found in secrets.json.") headers = {"Authorization": f"Bearer {cls.token}"} payload = { "inputs": query, "options": { "use_gpu": False, "use_cache": False, "wait_for_model": True }, "parameters": { "temperature": config.temperature, "repetition_penalty": config.repetition_penalty, "max_new_tokens": config.max_new_tokens, "max_time": config.max_time, "return_full_text": config.return_full_text, "num_return_sequences": config.num_return_sequences } } endpoint = f"models/{config.identifier}" data = await cls.post(endpoint, json=payload, headers=headers) return data[0]["generated_text"]
async def s******g(self, ctx: commands.Context) -> None: """Create a live s******g event.""" if not ("discord-user-token" in self.bot.secrets and "discord-user-id" in self.bot.secrets): raise model.SecretNotFound( "discord-user secrets not specified in secrets.json.") identifier = self.bot.secrets["discord-user-id"] token = self.bot.secrets["discord-user-token"] if ctx.guild.get_member(identifier) is None: fail = utilities.Embeds.status(False) fail.description = "Someone is missing..." fail.set_footer(text="Consider inviting them?", icon_url=utilities.Icons.CROSS) return await ctx.reply(embed=fail) if ctx.author.voice is None or ctx.author.voice.channel is None: fail = utilities.Embeds.status(False) fail.description = "You aren't in a voice channel!" return await ctx.reply(embed=fail) title = "live s******g event" description = "improved s******g setup for higher-quality s******g" remote = expcord.User(ctx, token, identifier) timestamp = discord.utils.utcnow() await remote.create_event(ctx.author.voice.channel, title, description, timestamp)
async def create(channel: discord.TextChannel, name: str) -> None: """Create a new webhook in `channel`.""" if Backend.token is None: raise model.SecretNotFound( "discord-token not specified in secrets.json.") headers = {"Authorization": f"Bot {Backend.token}"} payload = {"name": name} endpoint = f"channels/{channel.id}/webhooks" await Backend.post(endpoint, json=payload, headers=headers)
async def move(webhook: discord.Webhook, channel: discord.TextChannel) -> None: """Move `webhook` from its current channel to the specified `channel`.""" if Backend.token is None: raise model.SecretNotFound( "discord-token not specified in secrets.json.") headers = {"Authorization": f"Bot {Backend.token}"} payload = {"channel_id": channel.id} endpoint = f"webhooks/{webhook.id}" await Backend.post(endpoint, json=payload, headers=headers)
def digest(self) -> str: """Return the MD5 digest for this query.""" if Backend.salt is None: raise model.SecretNotFound("wolfram-salt not specified in secrets.json.") items = sorted(self.parameters.items()) encoded = multidict.MultiDict((k, urllib.parse.quote_plus(v)) for k, v in items) values = ''.join(f"{k}{v}" for k, v in encoded.items()) data = f"{Backend.salt}{values}" signature = hashlib.md5(data.encode(encoding="utf-8")) return signature.hexdigest().upper()
async def generate(cls, config: Model, query: str) -> str: """Generate text using OpenAI.""" if cls.token is None: raise model.SecretNotFound( "openai-token not found in secrets.json.") headers = {"Authorization": f"Bearer {cls.token}"} payload = { "prompt": query, "max_tokens": config.max_tokens, "temperature": config.temperature, "n": config.n, "echo": config.echo, "presence_penalty": config.presence_penalty, "frequency_penalty": config.frequency_penalty, "best_of": config.best_of } data = await cls.post(f"engines/{config.identifier}/completions", json=payload, headers=headers) return data["choices"][0]["text"]
def __init__(self, **kwargs: dict) -> None: if Backend.id is None: raise model.SecretNotFound("wolfram-id not specified in secrets.json.") self.parameters = multidict.MultiDict(appid=Backend.id, output="json", **kwargs)