Skip to content

Commit

Permalink
Merge branch 'main' into google-perspective
Browse files Browse the repository at this point in the history
Signed-off-by: Paillat <[email protected]>
  • Loading branch information
Paillat-dev authored Mar 13, 2024
2 parents 4e79f18 + 6461fff commit 41f846c
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 155 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ We support everything from **multi-modality image understanding**, **code interp

Featuring code execution and environment manipulation by [E2B](https://e2b.dev)

We are migrating towards using [QDRANT](https://qdrant.tech/) as our vector database backing, we are moving away from pinecone.
We are migrating towards using [QDRANT](https://qdrant.tech/) as our vector database backing, we are moving away from pinecone. Qdrant is an excellent vector database choice, and in fact the best one that we've tested and used so far.
<p align="center">
<img src="https://i.imgur.com/4g1tQ91.png" width="64px" height="64px" />
</p>

# Overview of Capabilities
![Overview of Features](https://i.imgur.com/BZdORTL.png)
Expand Down Expand Up @@ -122,8 +125,9 @@ These commands are grouped, so each group has a prefix, but you can easily tab c
- `/index discord_backup` - Use the last 3000 messages of every channel on your Discord server as an index. Needs both an admin and an index role.
- `/index chat user_index:<user_index> search_index:<search_index>` - Chat with your documents that you've indexed previously!

### DALL-E2 Commands
- `/dalle draw <prompt>` - Have DALL-E generate images based on a prompt.
### DALL-E Commands
- `/dalle draw <prompt>` - Have DALL-E 3 generate images based on a prompt.
- `/dalle draw_old <prompt>` - Have DALL-E 2 generate images based on a prompt.
- `/dalle optimize <image prompt text>` - Optimize a given prompt text for DALL-E image generation.

### System and Settings
Expand All @@ -132,8 +136,8 @@ These commands are grouped, so each group has a prefix, but you can easily tab c
- `/system usage` - Estimate current usage details (based on Davinci).
- `/system settings low_usage_mode True/False` - Turn low usage mode on and off. If on, it will use the curie-001 model, and if off, it will use the Davinci-003 model.
- `/system delete-conversation-threads` - Delete all threads related to this bot across all servers.
- `/system local-size` - Get the size of the local dalleimages folder.
- `/system clear-local` - Clear all the local dalleimages.
- `/system local-size` - Get the size of the local `/dalleimages` folder.
- `/system clear-local` - Delete all the contents of `/dalleimages`.

# Step-by-Step Guides for GPTDiscord
[**GPTDiscord Guides**](https://github.com/Kav-K/GPTDiscord/tree/main/detailed_guides)
Expand Down
15 changes: 10 additions & 5 deletions cogs/code_interpreter_service_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,16 @@ async def on_message(self, message):
)
await message.reply(
embed=response_embed,
view=CodeInterpreterDownloadArtifactsView(
message, self, self.sessions[message.channel.id], artifact_names
)
if artifacts_available
else None,
view=(
CodeInterpreterDownloadArtifactsView(
message,
self,
self.sessions[message.channel.id],
artifact_names,
)
if artifacts_available
else None
),
)

safe_remove_list(self.thread_awaiting_responses, message.channel.id)
Expand Down
32 changes: 20 additions & 12 deletions cogs/moderations_service_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ async def start_moderations_service(self, guild_id, alert_channel_id=None):
self.set_guild_moderated(guild_id)
moderations_channel = await self.check_and_launch_moderations(
guild_id,
Moderation.moderation_alerts_channel
if not alert_channel_id
else alert_channel_id,
(
Moderation.moderation_alerts_channel
if not alert_channel_id
else alert_channel_id
),
)
self.set_moderated_alert_channel(guild_id, moderations_channel.id)

Expand Down Expand Up @@ -291,9 +293,11 @@ async def config_command(
ephemeral=True,
embed=await self.build_moderation_settings_embed(
config_type,
self.get_or_set_warn_set(ctx.guild_id)
if config_type == "warn"
else self.get_or_set_delete_set(ctx.guild_id),
(
self.get_or_set_warn_set(ctx.guild_id)
if config_type == "warn"
else self.get_or_set_delete_set(ctx.guild_id)
),
),
)
return
Expand All @@ -319,16 +323,20 @@ async def config_command(

new_delete_set = ThresholdSet(
hate if hate else delete_set["hate"],
hate_threatening
if hate_threatening
else delete_set["hate/threatening"],
(
hate_threatening
if hate_threatening
else delete_set["hate/threatening"]
),
self_harm if self_harm else delete_set["self-harm"],
sexual if sexual else delete_set["sexual"],
sexual_minors if sexual_minors else delete_set["sexual/minors"],
violence if violence else delete_set["violence"],
violence_graphic
if violence_graphic
else delete_set["violence/graphic"],
(
violence_graphic
if violence_graphic
else delete_set["violence/graphic"]
),
)
self.set_delete_set(ctx.guild_id, new_delete_set)
await self.restart_moderations_service(ctx)
Expand Down
6 changes: 3 additions & 3 deletions cogs/search_service_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ async def paginate_embed(
for count, chunk in enumerate(response_text, start=1):
if not first:
page = discord.Embed(
title="Search Results"
if not original_link
else "Follow-up results",
title=(
"Search Results" if not original_link else "Follow-up results"
),
description=chunk,
url=original_link,
)
Expand Down
34 changes: 21 additions & 13 deletions cogs/text_service_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ def __init__(
assert self.CONVERSATION_DRAWING_ABILITY_EXTRACTION_SNIPPET is not None

except Exception:
self.CONVERSATION_STARTER_TEXT = (
self.CONVERSATION_STARTER_TEXT_MINIMAL
) = self.CONVERSATION_STARTER_TEXT_VISION = (
self.CONVERSATION_STARTER_TEXT = self.CONVERSATION_STARTER_TEXT_MINIMAL = (
self.CONVERSATION_STARTER_TEXT_VISION
) = (
"You are an artificial intelligence that is able to do anything, and answer any question,"
"I want you to be my personal assistant and help me with some tasks. "
"and I want you to make well-informed decisions using the data that you have been trained on, "
Expand Down Expand Up @@ -239,9 +239,9 @@ async def on_member_join(self, member):
welcome_message_response = await self.model.send_request(
query,
tokens=self.usage_service.count_tokens(query),
is_chatgpt_request=True
if "turbo" in str(self.model.model)
else False,
is_chatgpt_request=(
True if "turbo" in str(self.model.model) else False
),
)
welcome_message = str(welcome_message_response["choices"][0]["text"])
except Exception:
Expand Down Expand Up @@ -1404,10 +1404,16 @@ async def converse_command(
await TextService.encapsulated_send(
self,
target.id,
opener
if target.id not in self.conversation_threads or self.pinecone_service
else "".join(
[item.text for item in self.conversation_threads[target.id].history]
(
opener
if target.id not in self.conversation_threads
or self.pinecone_service
else "".join(
[
item.text
for item in self.conversation_threads[target.id].history
]
)
),
target_message,
overrides=overrides,
Expand Down Expand Up @@ -1597,9 +1603,11 @@ async def callback(self, interaction: discord.Interaction):
try:
id = await self.converser_cog.sharegpt_service.format_and_share(
self.converser_cog.full_conversation_history[self.conversation_id],
self.converser_cog.bot.user.default_avatar.url
if not self.converser_cog.bot.user.avatar
else self.converser_cog.bot.user.avatar.url,
(
self.converser_cog.bot.user.default_avatar.url
if not self.converser_cog.bot.user.avatar
else self.converser_cog.bot.user.avatar.url
),
)
url = f"https://shareg.pt/{id}"
await interaction.response.send_message(
Expand Down
6 changes: 3 additions & 3 deletions cogs/translation_service_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def build_translation_embed(
)
embed.set_footer(
text=f"Requested by {requestor.name}#{requestor.discriminator}",
icon_url=requestor.avatar.url
if requestor.avatar
else requestor.default_avatar.url,
icon_url=(
requestor.avatar.url if requestor.avatar else requestor.default_avatar.url
),
)

return embed
Expand Down
60 changes: 43 additions & 17 deletions detailed_guides/AI-SEARCH.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,100 @@ GOOGLE_SEARCH_API_KEY="...."
GOOGLE_SEARCH_ENGINE_ID="...."
```

You first need to create a programmable search engine and get the search engine ID: https://developers.google.com/custom-search/docs/tutorial/creatingcse
You first need to create a programmable search engine and get the search engine ID [here](https://developers.google.com/custom-search/docs/tutorial/creatingcse).

Then you can get the API key, click the "Get a key" button on this page: https://developers.google.com/custom-search/v1/introduction
Then you can get the API key, click the "Get a key" button [on this page](https://developers.google.com/custom-search/v1/introduction).

You can limit the max price that is charged for a single search request by setting `MAX_SEARCH_PRICE` in your `.env` file.


Step by Step Guide:
---


1\. Go to the [Programmable Search Engine docs](https://developers.google.com/custom-search/docs/tutorial/creatingcse) to get a Search engine ID
----------------------------------------------------------------------

1\. Go to the [Programmable Search Engine docs](https://developers.google.com/custom-search/docs/tutorial/creatingcse) to get a Search engine ID.
---

2\. Click on "Control Panel" under "Defining a Programmable Engine in Control Panel"
----------------------------------------
a. Click on "Control Panel" under "Defining a Programmable Engine in Control Panel"

Click to sign in(make a Google acct if you do not have one):
b. Click to sign in(make a Google account if you do not have one):

![image](https://user-images.githubusercontent.com/23362597/233266042-98098ed5-72b2-41b3-9495-1a9f4d7e1101.png)


3\. Register yourself a new account/Login to the Control Panel
2\. Register yourself a new account/Login to the Control Panel
-----------------------------------

After logging in, you will be redirected to the Control Panel to create a new search engine:

![image](https://user-images.githubusercontent.com/23362597/233266323-53232468-2590-4820-b55f-08c78529d752.png)


4\. Create a new search engine
3\. Create a new search engine
------------------------------

Fill in a name, select to "Search the entire web" and hit "Create":

![image](https://user-images.githubusercontent.com/23362597/233266738-b70f004d-4324-482e-a945-9b0193b60158.png)


5\. Copy your Search engine ID to your .env file
4\. Copy your Search engine ID to your .env file
--------------------------

![image](https://user-images.githubusercontent.com/23362597/233267123-ea25a3bb-6cdb-4d46-a893-846ea4933632.png)


6\. Go to [custom-search docs](https://developers.google.com/custom-search/v1/introduction) to get a Google search API key
5\. Go to [custom-search docs](https://developers.google.com/custom-search/v1/introduction) to get a Google search API key
-------------------------------------------------

Click "Get a Key":

![image](https://user-images.githubusercontent.com/23362597/233267659-f82621f4-1f0b-46bf-8994-be443dd79932.png)


7\. Name your project and agree to the Terms of Service
6\. Name your project and agree to the Terms of Service
------------------------------------

![image](https://user-images.githubusercontent.com/23362597/233267793-ca3c273d-ebc6-44a5-a49d-0d4c3223c992.png)


8\. Copy your Google search API key to your .env file
7\. Copy your Google search API key to your .env file
------------------------------------

![image](https://user-images.githubusercontent.com/23362597/233268067-5a6cfaf1-bec0-48b3-8add-70b218fb4264.png)


9\. Enable Cloud Vision API for image recognition
8\. Enable Cloud Vision API for image recognition
------------------------------------
a. Navigate to the Google Cloud API console [here](https://console.cloud.google.com/apis/api/vision.googleapis.com/).

b. Click on 'Create Project':

![image](https://github.com/Raecaug/GPTDiscord/assets/23362597/f128cc80-2a53-4578-9f4e-99791d7f8ffe)


c. Give it a name and create it:

![image](https://github.com/Raecaug/GPTDiscord/assets/23362597/35050805-f2ad-4489-8d8c-dacbd961c0b1)


d. Now, navigate to the API Library:

![image](https://github.com/Raecaug/GPTDiscord/assets/23362597/0eff23c1-09c1-4e65-a08a-a56af5515727)


e. Search for the 'Cloud Vision API' and enable it:

![image](https://github.com/Raecaug/GPTDiscord/assets/23362597/ef225dbe-4385-4263-b0aa-7100bbfed0e8)


9\. Enable Custom Search API for Google search
------------------------------------

https://console.cloud.google.com/apis/api/vision.googleapis.com/
You can follow [this link](https://console.cloud.google.com/apis/api/customsearch.googleapis.com/) to quickly jump to the page to enable the custom search API. You may need to first selet the project you created before:

![image](https://github.com/Raecaug/GPTDiscord/assets/23362597/875039dc-88b8-47a2-ad6e-4d39be26781d)

10\. Enable Custom Search API for Google search
![image](https://github.com/Raecaug/GPTDiscord/assets/23362597/3a0f4200-7319-4a2f-8fb1-9d85bffb387a)

https://console.cloud.google.com/apis/api/customsearch.googleapis.com/
23 changes: 17 additions & 6 deletions detailed_guides/CODE-INTERPRETER.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
# Code Interpreter
This bot supports a full fledged version of Code Interpreter, where code in various languages can be executed directly in discord. You can even install python and system packages. Python is the preferred language for code interpreter, although it will still work relatively nicely with other popular languages.
This bot supports a full fledged version of Code Interpreter, where code in various languages can be executed directly in Discord. You can even install Python and system packages. Python is the preferred language for code interpreter, although it will still work relatively nicely with other popular languages.

To get started with code interpreter, you need an E2B API key. You can find an E2B API key at https://e2b.dev/docs/getting-started/api-key
To get started with code interpreter, you need an E2B API key. You can find an E2B API key & more info on FoundryLabs [here](https://e2b.dev/docs/getting-started/api-key).
```env
E2B_API_KEY="...."
```

Like above, add the E2B API key to your `.env` file. E2B is a cloud-based isolated execution environment, so that you can run code safely and have a containerized environment to install packages and etc in.
Like above, add the E2B API key to your `.env` file. E2B is a cloud-based isolated execution environment, so that you can run code safely and have a containerized environment to install packages and execute code, etc in.

Afterwards, to use code interpreter, simply use `/code chat`.

When you begin a code interpreter instance, a new isolated environment to run your code is automatically created. Inside your chat, you can ask GPT to install python or system packages into this environment, and ask GPT to run any sort of python (and other language) code within it as well. Unlike ChatGPT's code interpreter / advanced data analysis, this also has access to the internet so you can work with code that uses the network as well.
When you begin a code interpreter instance, a new isolated environment to run your code is automatically created. Inside your chat, you can ask GPT to install Python or system packages into this environment, and ask GPT to run any sort of python (and other language) code within it as well. Unlike ChatGPT's code interpreter / advanced data analysis, this also has access to the internet so you can work with code that uses the network as well.

When ChatGPT executes code, sometimes it will create files (especially if you ask it to). If files are created, they can be downloaded from the "Download Artifacts" button that will pop up after the code is executed.

Sometimes, ChatGPT will create files that are not in the upstream `artifacts` folder. To remedy this, simply ask it to ensure all files it makes are within `artifacts`.
As per the E2B documentation, the free tier provides the following resources to a sandboxed code instance:

> - 2 vCPU
> - 512 MB RAM
> - 1 GB free disk storage
> - 24 hours max sandbox session length
Given that it is possible to maintain and use a thread over multiple days with GPTDiscord, exceeding the instance limits of your E2B API key will cause the thread to break and not reply. In this case, you will need to end & restart the thread to continue conversing.


When ChatGPT executes code, sometimes it will create files (especially if you ask it to within your instructions) in a folder called `artifacts`. If files are created, they can be downloaded from the "Download Artifacts" button that will pop up after the code is executed.

Sometimes, ChatGPT will create files that are not placed in the upstream `artifacts` folder. To remedy this, simply ask it to ensure all files it makes are within `artifacts`.
11 changes: 10 additions & 1 deletion detailed_guides/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,27 @@ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.9 get-pip.py
```

#### Create a Python Virtual Enviroment
```shell
pip install virtualenv
python3.9 -m venv venv
source venv/bin/activate
```


#### Install project dependencies
```
python3.9 -m pip install --ignore-installed PyYAML
python3.9 -m pip install torch==1.13.1+cpu torchvision==0.14.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
python3.9 -m pip install urllib3==1.26.7
python3.9 -m pip install git+https://github.com/openai/whisper.git
python3.9 -m pip install -r requirements.txt
python3.9 -m pip install .
```
#### Copy the sample.env file into a regular .env file. `DEBUG_GUILD` and the ID for `ALLOWED_GUILDS` can be found by right-clicking your server and choosing "Copy ID". Similarly, `DEBUG_CHANNEL` can be found by right-clicking your debug channel.
```shell
cp .env .env
cp sample.env .env
```

#### The command below is used to edit the .env file and to put in your API keys. You can right click within the editor after running this command to paste. When you are done editing, press CTRL + X, and then type Y, to save.
Expand Down
Loading

0 comments on commit 41f846c

Please sign in to comment.