Merge branch 'main' into gpt-index

Signed-off-by: Kaveen Kumarasinghe <k5kumara@uwaterloo.ca>
Kaveen Kumarasinghe 2 years ago committed by GitHub
commit cd8d0624a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -309,6 +309,9 @@ class Commands(discord.Cog, name="Commands"):
@discord.option(
name="prompt", description="The prompt to send to GPT3", required=True
)
@discord.option(
name="private", description="Will only be visible to you", required=False
)
@discord.option(
name="temperature",
description="Higher values means the model will take more risks",
@ -342,13 +345,20 @@ class Commands(discord.Cog, name="Commands"):
self,
ctx: discord.ApplicationContext,
prompt: str,
private: bool,
temperature: float,
top_p: float,
frequency_penalty: float,
presence_penalty: float,
):
await self.converser_cog.ask_command(
ctx, prompt, temperature, top_p, frequency_penalty, presence_penalty
ctx,
prompt,
private,
temperature,
top_p,
frequency_penalty,
presence_penalty,
)
@add_to_group("gpt")
@ -368,6 +378,9 @@ class Commands(discord.Cog, name="Commands"):
required=False,
default="",
)
@discord.option(
name="private", description="Will only be visible to you", required=False
)
@discord.option(
name="temperature",
description="Higher values means the model will take more risks",
@ -393,12 +406,13 @@ class Commands(discord.Cog, name="Commands"):
ctx: discord.ApplicationContext,
instruction: str,
text: str,
private: bool,
temperature: float,
top_p: float,
codex: bool,
):
await self.converser_cog.edit_command(
ctx, instruction, text, temperature, top_p, codex
ctx, instruction, text, private, temperature, top_p, codex
)
@add_to_group("gpt")
@ -430,6 +444,13 @@ class Commands(discord.Cog, name="Commands"):
required=False,
default=False,
)
@discord.option(
name="model",
description="Which model to use with the bot",
required=False,
default=False,
autocomplete=Settings_autocompleter.get_models,
)
@discord.option(
name="temperature",
description="Higher values means the model will take more risks",
@ -470,6 +491,7 @@ class Commands(discord.Cog, name="Commands"):
opener_file: str,
private: bool,
minimal: bool,
model: str,
temperature: float,
top_p: float,
frequency_penalty: float,
@ -481,6 +503,7 @@ class Commands(discord.Cog, name="Commands"):
opener_file,
private,
minimal,
model,
temperature,
top_p,
frequency_penalty,

@ -693,6 +693,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
self,
ctx: discord.ApplicationContext,
prompt: str,
private: bool,
temperature: float,
top_p: float,
frequency_penalty: float,
@ -720,7 +721,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
if not user_api_key:
return
await ctx.defer()
await ctx.defer(ephemeral=private)
overrides = Override(temperature, top_p, frequency_penalty, presence_penalty)
@ -741,6 +742,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
ctx: discord.ApplicationContext,
instruction: str,
text: str,
private: bool,
temperature: float,
top_p: float,
codex: bool,
@ -766,7 +768,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
if not user_api_key:
return
await ctx.defer()
await ctx.defer(ephemeral=private)
overrides = Override(temperature, top_p, 0, 0)
@ -801,6 +803,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
opener_file: str,
private: bool,
minimal: bool,
model: str,
temperature: float,
top_p: float,
frequency_penalty: float,
@ -814,6 +817,7 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
opener_file (str): A .txt or .json file which is appended before the opener
private (bool): If the thread should be private
minimal (bool): If a minimal starter should be used
model (str): The openai model that should be used
temperature (float): Sets the temperature override
top_p (float): Sets the top p override
frequency_penalty (float): Sets the frequency penalty override
@ -866,7 +870,9 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
)
self.conversation_threads[thread.id] = Thread(thread.id)
self.conversation_threads[thread.id].model = self.model.model
self.conversation_threads[thread.id].model = (
self.model.model if not model else model
)
# Set the overrides for the conversation
self.conversation_threads[thread.id].set_overrides(

@ -0,0 +1,58 @@
<img src="https://user-images.githubusercontent.com/39274208/216566367-e1311c9e-bbc1-42fe-9e09-69e9fb728133.png" width="300">
You can choose to host the docker contained on app service so you have less maintenance, and it is also cheaper than a VM.
As a student, you can get free Azure credits and you can get free Azure credits with you MSDN license if you work at a Microsoft partner.
The steps are also fairly straightforward.
To make it work on Azure App service follow the following steps:
<img src="https://user-images.githubusercontent.com/39274208/216566481-e06ccf0d-7346-438b-ab5a-7cd4ac6b08f5.png" width="150">
Creating the container:
1. Sign into Azure via portal.azure.com
2. Search "app services" and click on it
3. choose resource group, webapp name.
4. At "publish" choose: "docker container"
5. OS: linux
6. Region: whichever is closer to you
7. choose Basic B1 as app service plan. this will cost you around 10 dollar in credits
8. At the "docker tab "change image source" to "dockerhub"
9. At image, use the following: kaveenk/gpt3discord:latest_release
10. Go to "review and create" and create the container!
11. Wait a minute until it gets provisioned.
<img src="https://user-images.githubusercontent.com/39274208/216566567-a00bd5c1-1ab4-4250-a6d6-9ab9d872bd31.png" width="200">
Configurating the container:
App services makes it easy for you to add ENV files without using the CLI. We do this first
1. Go to "configuration" under "settings"
Enter the following env files as defined in the readme.md file in this repository:
The most important application settings are:
ADMIN_ROLES
ALLOWED_GUILDS (your discord server token! not to be confused with a channel token or bot token)
DALLE_ROLES
DEBUG_CHANNEL
DEBUG_GUILD
DISCORD_TOKEN
GPT_ROLES
OPENAI_TOKEN
HEALTH_SERVICE_ENABLED
<img src="https://user-images.githubusercontent.com/39274208/216571201-1f5f96e8-b2f9-4e45-8b29-89c2bc3be97e.png" width="200">
Health:
1. It's important to also add WEBSITES_PORT to the application settings, since we are using the port for the health check of the container. Use 8181.
2. Go to "Health check" under monitoring and enter the following value: /healthz
3. Of course, set health check to: "on"
4. Press save.
Last step: go to "deployment center" and turn off "continious deployment".
This will make sure we get the latest build from docker hub when we restart the container.
It's as easy as this. Of course, make sure to follow the other steps settings up the discord bot in the readme.md.
Hope this helps!

@ -86,6 +86,14 @@ class Settings_autocompleter:
await ctx.interaction.response.defer() # defer so the autocomplete in int values doesn't error but rather just says not found
return []
async def get_models(
ctx: discord.AutocompleteContext,
):
"""Gets all models"""
return [
value for value in Models.TEXT_MODELS if value.startswith(ctx.value.lower())
]
async def get_value_moderations(
ctx: discord.AutocompleteContext,
): # Behaves a bit weird if you go back and edit the parameter without typing in a new command

@ -78,7 +78,7 @@ class Models:
@staticmethod
def get_max_tokens(model: str) -> int:
return Models.TOKEN_MAPPING.get(model, 4024)
return Models.TOKEN_MAPPING.get(model, 2024)
class ImageSize:
@ -576,12 +576,18 @@ class Model:
self._prompt_min_length = value
SETTINGS_DB["prompt_min_length"] = value
def backoff_handler(details):
def backoff_handler_http(details):
print(
f"Backing off {details['wait']:0.1f} seconds after {details['tries']} tries calling function {details['target']} | "
f"{details['exception'].status}: {details['exception'].message}"
)
def backoff_handler_request(details):
print(
f"Backing off {details['wait']:0.1f} seconds after {details['tries']} tries calling function {details['target']} | "
f"{details['exception'].args[0]}"
)
async def valid_text_request(self, response):
try:
tokens_used = int(response["usage"]["total_tokens"])
@ -598,7 +604,7 @@ class Model:
factor=3,
base=5,
max_tries=4,
on_backoff=backoff_handler,
on_backoff=backoff_handler_http,
)
async def send_embedding_request(self, text, custom_api_key=None):
async with aiohttp.ClientSession(raise_for_status=True) as session:
@ -624,11 +630,11 @@ class Model:
@backoff.on_exception(
backoff.expo,
aiohttp.ClientResponseError,
ValueError,
factor=3,
base=5,
max_tries=6,
on_backoff=backoff_handler,
max_tries=4,
on_backoff=backoff_handler_request,
)
async def send_edit_request(
self,
@ -651,7 +657,7 @@ class Model:
)
print(f"Overrides -> temp:{temp_override}, top_p:{top_p_override}")
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(raise_for_status=False) as session:
payload = {
"model": Models.EDIT if codex is False else Models.CODE_EDIT,
"input": "" if text is None else text,
@ -676,7 +682,7 @@ class Model:
factor=3,
base=5,
max_tries=6,
on_backoff=backoff_handler,
on_backoff=backoff_handler_http,
)
async def send_moderations_request(self, text):
# Use aiohttp to send the above request:
@ -695,11 +701,11 @@ class Model:
@backoff.on_exception(
backoff.expo,
aiohttp.ClientResponseError,
ValueError,
factor=3,
base=5,
max_tries=4,
on_backoff=backoff_handler,
on_backoff=backoff_handler_request,
)
async def send_summary_request(self, prompt, custom_api_key=None):
"""
@ -718,7 +724,7 @@ class Model:
tokens = self.usage_service.count_tokens(summary_request_text)
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(raise_for_status=False) as session:
payload = {
"model": Models.DAVINCI,
"prompt": summary_request_text,
@ -746,11 +752,11 @@ class Model:
@backoff.on_exception(
backoff.expo,
aiohttp.ClientResponseError,
ValueError,
factor=3,
base=5,
max_tries=4,
on_backoff=backoff_handler,
on_backoff=backoff_handler_request,
)
async def send_request(
self,
@ -774,12 +780,16 @@ class Model:
f"Prompt must be greater than {self.prompt_min_length} characters, it is currently: {len(prompt)} characters"
)
if not max_tokens_override:
if model:
max_tokens_override = Models.get_max_tokens(model) - tokens
print(f"The prompt about to be sent is {prompt}")
print(
f"Overrides -> temp:{temp_override}, top_p:{top_p_override} frequency:{frequency_penalty_override}, presence:{presence_penalty_override}"
)
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(raise_for_status=False) as session:
payload = {
"model": self.model if model is None else model,
"prompt": prompt,
@ -787,7 +797,7 @@ class Model:
"temperature": self.temp if temp_override is None else temp_override,
"top_p": self.top_p if top_p_override is None else top_p_override,
"max_tokens": self.max_tokens - tokens
if not max_tokens_override
if max_tokens_override is None
else max_tokens_override,
"presence_penalty": self.presence_penalty
if presence_penalty_override is None
@ -839,7 +849,7 @@ class Model:
factor=3,
base=5,
max_tries=4,
on_backoff=backoff_handler,
on_backoff=backoff_handler_http,
)
async def send_image_request(
self, ctx, prompt, vary=None, custom_api_key=None

Loading…
Cancel
Save