Commit ยท
2e4a01c
1
Parent(s): d148a0f
Added literally fuc*ing everything
Browse files- .gitattributes +3 -0
- .vscode/settings.json +14 -0
- AI_IN_DEPTH.md +66 -0
- README.md +75 -10
- __pycache__/app.cpython-311.pyc +0 -0
- __pycache__/blubeAPI.cpython-311.pyc +0 -0
- app.py +220 -0
- blubeAPI.py +54 -0
- data/persona.txt +8 -0
- delscript.py +9 -0
- docs/customdata.txt +3 -0
- docs/data.txt +8 -0
- extra-requirements/1.exe +3 -0
- extra-requirements/2.exe +3 -0
- extra-requirements/3.exe +3 -0
- extra-requirements/help.png +0 -0
- flagged/log.csv +2 -0
- installpackages.bat +15 -0
- installpython.bat +4 -0
- message.json +1 -0
- reqs.txt +11 -0
- resetdata.bat +5 -0
- run.bat +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
extra-requirements/1.exe filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
extra-requirements/2.exe filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
extra-requirements/3.exe filter=lfs diff=lfs merge=lfs -text
|
.vscode/settings.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cSpell.words": [
|
| 3 |
+
"customdata",
|
| 4 |
+
"gradio",
|
| 5 |
+
"langchain",
|
| 6 |
+
"OPENAI",
|
| 7 |
+
"runbot",
|
| 8 |
+
"usersettings"
|
| 9 |
+
],
|
| 10 |
+
"[python]": {
|
| 11 |
+
"editor.defaultFormatter": "ms-python.black-formatter"
|
| 12 |
+
},
|
| 13 |
+
"python.formatting.provider": "none"
|
| 14 |
+
}
|
AI_IN_DEPTH.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AI IN DEPTH
|
| 2 |
+
# This should cover everything about the AI, if I missed anything, let me know
|
| 3 |
+
# Higher number/farther down the list is more complex
|
| 4 |
+
## 1. The Basics
|
| 5 |
+
The entire program is made in python with some batch files for ease of use.
|
| 6 |
+
## 2. Querying results and getting online data
|
| 7 |
+
The program uses wikipedia modules to get and summarize different inputted topics
|
| 8 |
+
## 3. The Interface
|
| 9 |
+
Some of the basic interface uses the command prompt with python inputs and the actual AI is made using the Gradio API
|
| 10 |
+
## 4. The AI Model
|
| 11 |
+
The AI is build with OpenAI's ChatGPT API, inputs are taken from the Gradio input box, filtered through OpenAI's `gpt-3.5-turbo` model, and the AI sends an output in the allocated box
|
| 12 |
+
## 5. Usage
|
| 13 |
+
This is build to be a heavily customizable AI with a variety of different settings and customization options. The main settings are prompt saving limit and reset data. Reset data is self explanatory, just simply deleting your data and custom data. Prompt saving limit is a bit more complex, for custom data it is always the number you set it to lines in the `docs/customdata.txt` file, but because of the nature of the wiki search module, it may not always be the amount you set it to, because it can return multiple queries, which will be placed on separate files.
|
| 14 |
+
## 6. Persona
|
| 15 |
+
Probably the most complex thing I've ever done, allows for simple programs and systems to be made within the realm of the AI with the following definitions
|
| 16 |
+
|
| 17 |
+
* Variables can be defined with words placed in double curly brackets `{{var name}} description on what the variable is, optional`
|
| 18 |
+
* `SET var name = value` can be used to change values of previously defined variables
|
| 19 |
+
* `VALUE var name` can be used to get the value of variables
|
| 20 |
+
* `IF var name condition` can be used to return a boolean of logic. Variables can be defined as `IF` conditions or used with the
|
| 21 |
+
* `THEN code to execute` statement, which must follow an `IF` statement
|
| 22 |
+
* `{{user}}` is a predefined variable that refers to the user, or `{{char}}` which refers to the AI
|
| 23 |
+
* Non-defined functions are any code that is not defined above, but AI still takes plain text input, so it is mixable with plain text
|
| 24 |
+
|
| 25 |
+
Now that that's sorted, lets see an example of a simple script, made in plain text with Persona
|
| 26 |
+
```
|
| 27 |
+
{{user}}'s name is John
|
| 28 |
+
{{char}}'s name is Jane
|
| 29 |
+
|
| 30 |
+
{{foo}} is a number starting at 1
|
| 31 |
+
{{bar}} is a string starting at \"Hello World!\"
|
| 32 |
+
|
| 33 |
+
{{bool store}} is a boolean IF statement
|
| 34 |
+
SET bool store = IF foo = 1
|
| 35 |
+
|
| 36 |
+
IF {{bool store}} THEN {{char}} will tell {{user}} the value of {{bar}}
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
This is very simple, but it can be much more complicated, although it is preset, so the only way to change variables is by implementing it into the program, but I'm sure you can find a way(that's a lie).
|
| 40 |
+
|
| 41 |
+
Now let's take a look at the main purpose of personas, and that's, well, personas. You can put anything like:
|
| 42 |
+
* `{{char}}'s name is John`
|
| 43 |
+
* `{{char}} is named John and has brown hair and blue eyes`
|
| 44 |
+
* `{{char}} is named John, has brown hair and blue eyes, and likes to code`
|
| 45 |
+
|
| 46 |
+
These are 3 extremely basic examples, but you can make entire complex storylines and libraries of info. It is easily integrated into PersonaScript(patent never)
|
| 47 |
+
|
| 48 |
+
## 7. Mental... er.. I mean Line-By-Line breakdown
|
| 49 |
+
See app.py for more details
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
Lines 1-6: Import statements for modules
|
| 53 |
+
Line 8: Gets OpenAI API Key
|
| 54 |
+
Lines 9-12: Defines setting variables in a class
|
| 55 |
+
Lines 13-21: `start()` function, gets persona, opens the file for storage, writes basic instructions that are build in(definitions), then finally user input
|
| 56 |
+
Line 25: calls the `clearOldMem()` function to delete excess data thats going over the prompt limit, default 50
|
| 57 |
+
Lines 28-45: Makes a simple input system to get a number off the user and run the appropriate function
|
| 58 |
+
Line 46: Recursion, as to why I didn't use parenthesis recursion, It's harder to read and remember
|
| 59 |
+
Lines 47-73: Defines the `clearOldMem()` function, opens the data files, checks if they have more than the prompt limit lines, deletes lines from the start until it's the limit
|
| 60 |
+
Lines 74-99: Defines the `setSettings()` function, gets `setting` passed in from the `loop()` function, does the appropriate action, this one is pretty self explanatory just read the `print()` statements
|
| 61 |
+
Lines 100-110: Defines the `write()` function, called from the loop function, queries a wikipedia article/s on it, summarizes it, and writes it to the `docs\data.txt` file
|
| 62 |
+
Lines 112-121: Defines `custom()` function, same as the `write()` function, only it takes direct user input and writes to a different file
|
| 63 |
+
Lines 123-139: Defines `construct_index()`. I stole this code, I have barely a clue how it works, all I know is it takes a folder(docs) and builds a `gpt-3.5-turbo` model with that context, and saves it to `index.json`
|
| 64 |
+
Lines 141-144: Defines the `chatbot()` function. Takes an input, finds it in `index.json`'s context, and returns a summarized response. How it does this, I don't know, it is a 3000 line file and only 3 lines make any sense, and most are just random numbers that I'm too scared to touch
|
| 65 |
+
Lines 145-152: Defines the `runbot()` function, builds Gradio UI around chatbot.
|
| 66 |
+
Lines 157-158: Starts the program
|
README.md
CHANGED
|
@@ -1,12 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
emoji: ๐ป
|
| 4 |
-
colorFrom: yellow
|
| 5 |
-
colorTo: yellow
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 4.2.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Markdown Viewer
|
| 3 |
+
|
| 4 |
+
## In case you dont have one already
|
| 5 |
+
|
| 6 |
+
#### Good quality markdown viewer [here](https://dillinger.io)
|
| 7 |
+
|
| 8 |
+
# HOW TO RUN PROGRAM
|
| 9 |
+
|
| 10 |
+
#### Run installpackages.bat
|
| 11 |
+
##### Installs necessary packages
|
| 12 |
+
#### Run resetdata.bat if it is your first time running the app
|
| 13 |
+
##### Ensures that all data is properly reset before inital startup
|
| 14 |
+
#### Run run.bat to start the app
|
| 15 |
+
|
| 16 |
+
## IF RUNNING run.bat DOES'T WORK
|
| 17 |
+
### Open `%localappdata%/Programs/Python`
|
| 18 |
+
##### If there is an existing `Python311` folder, backup all projects that might be installed inside the folder, then delete the `Python311` folder.
|
| 19 |
+
### In the project folder, open the extra requirements folder and install 1.exe
|
| 20 |
+
##### This installs python 3.11.5(The latest working version)
|
| 21 |
+
### IF THIS DOESN'T WORK
|
| 22 |
+
#### Run 2.exe
|
| 23 |
+
##### When it opens, go to the Windows heading and make sure nothing else is checked. On the right-hand side, under optional, make sure only Windows 10 SDK is selected. Then install the file
|
| 24 |
+

|
| 25 |
+
#### Run 3.exe
|
| 26 |
---
|
| 27 |
+
# CHANGELOG
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
## Heading size indicates relevance of update, highest being 3, lowest being 6
|
| 30 |
+
|
| 31 |
+
### October 5th 2023:
|
| 32 |
+
- untrained.py added
|
| 33 |
+
- readme.md added
|
| 34 |
+
- docs folder added
|
| 35 |
+
- First and Second .zip file added to builds
|
| 36 |
+
##### __OPERATION STATUS:__
|
| 37 |
+
- trained.py: running effectively
|
| 38 |
+
- untrained.py: unfinished
|
| 39 |
+
---
|
| 40 |
+
##### October 12th 2023:
|
| 41 |
+
- No significant progress was made since the 5th besides today so I'll put it all here
|
| 42 |
+
- untrained.py was scrapped due to lack of capability + reasonability
|
| 43 |
+
- trained.py will now have some of the features as untrained.py, like being able to write to data before launching
|
| 44 |
+
- trained.py is now down due to fixes
|
| 45 |
+
##### __OPERATION STATUS:__
|
| 46 |
+
- trained.py: being fixed
|
| 47 |
+
---
|
| 48 |
+
### October 12th 2023(Second Update):
|
| 49 |
+
- Finished the trained module, will be the only module
|
| 50 |
+
- Renamed to app.py
|
| 51 |
+
- Added run.bat for ease of use
|
| 52 |
+
- Wikipedia references for a wide variety of assets
|
| 53 |
+
- Custom input functionality
|
| 54 |
+
- Easily editable data for customization
|
| 55 |
+
- Template for paid access, google functionality, etc.
|
| 56 |
+
##### __OPERATION STATUS:__
|
| 57 |
+
- app.py: Fully Operational
|
| 58 |
+
---
|
| 59 |
+
#### October 14th 2023:
|
| 60 |
+
- Finished initial release settings
|
| 61 |
+
- Added file reset method
|
| 62 |
+
- Added customisable pruning for memory
|
| 63 |
+
##### __OPERATION STATUS:__
|
| 64 |
+
- app.py: Fully Operational
|
| 65 |
+
- delscript.py: Fully Operational
|
| 66 |
+
---
|
| 67 |
+
### October 20th 2023:
|
| 68 |
+
- Python 3.12 and 3.11.6 were breaking a lot of things
|
| 69 |
+
- Made extra resources folder for extra files
|
| 70 |
+
- Updated README.md to include fixes
|
| 71 |
+
##### __OPERATION STATUS:__
|
| 72 |
+
- app.py: Working
|
| 73 |
+
---
|
| 74 |
+
### October 26th 2023:
|
| 75 |
+
- Finally fixed and debugged
|
| 76 |
+
##### __OPERATION STATUS:__
|
| 77 |
+
- app.py: Working
|
__pycache__/app.cpython-311.pyc
ADDED
|
Binary file (9.38 kB). View file
|
|
|
__pycache__/blubeAPI.cpython-311.pyc
ADDED
|
Binary file (3 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
|
| 2 |
+
from langchain.chat_models import ChatOpenAI
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import sys
|
| 5 |
+
import os
|
| 6 |
+
import wikipedia as wiki
|
| 7 |
+
import openai
|
| 8 |
+
from openai import OpenAI
|
| 9 |
+
import json
|
| 10 |
+
import time
|
| 11 |
+
import blubeAPI as blube
|
| 12 |
+
|
| 13 |
+
os.environ["OPENAI_API_KEY"] = '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'
|
| 14 |
+
|
| 15 |
+
client = OpenAI()
|
| 16 |
+
|
| 17 |
+
class settings:
|
| 18 |
+
def __init__(self, prompts):
|
| 19 |
+
self.prompts = prompts
|
| 20 |
+
usersettings = settings(50)
|
| 21 |
+
def start():
|
| 22 |
+
# Get AI Personality
|
| 23 |
+
persona = input("Input the persona of the AI ")
|
| 24 |
+
if os.path.exists("data/persona.txt"):
|
| 25 |
+
os.remove("data/persona.txt")
|
| 26 |
+
data = open("data/persona.txt", "at")
|
| 27 |
+
data.write("{{char}} refers to you, the ai or character. You, the AI, will act like {{char}}.\n{{user}} refers to the input, or the person.\nAny word or set of words that are after a set of {{ and before a set of }} are saved as a variable and can be referenced later.\nSET is an operation that can change the value of a previously defined variable. If SET is said, the value of the value mentioned afterward is changed.\nVALUE will tell the user the value of a variable mentioned afterward.\nIF is a condition that will say if the following statement is true or false, it accepts booleans. If SET is said to assign a variable to an IF condition, that variable will be SET to the result, true or false. If it is not being assigned to a variable, a THEN statement can be used. A THEN statement will run the text mentioned after if the IF condition was true. \n\n")
|
| 28 |
+
data.write(persona + "\n")
|
| 29 |
+
data.close()
|
| 30 |
+
#Main Prompt Function
|
| 31 |
+
def loop():
|
| 32 |
+
#Clear old data
|
| 33 |
+
clearOldMem()
|
| 34 |
+
|
| 35 |
+
#Setup console UI
|
| 36 |
+
choice = input("What do you want to run?\n1. Train AI\n2. Run AI\n3. Add Custom Data\n4. About\n5. Settings\n")
|
| 37 |
+
|
| 38 |
+
try:
|
| 39 |
+
choice = int(choice)
|
| 40 |
+
except:
|
| 41 |
+
print("Not a valid response, please enter a number")
|
| 42 |
+
if choice == 1:
|
| 43 |
+
write()
|
| 44 |
+
elif choice == 2:
|
| 45 |
+
blube.runbot(chatbot, client)
|
| 46 |
+
elif choice == 3:
|
| 47 |
+
custom()
|
| 48 |
+
elif choice == 4:
|
| 49 |
+
print("This is a chatbot created by FLL Team Blue BotBuilders for the innovation project.\n The goal of this bot is to be able to connect and have a hobby with the user")
|
| 50 |
+
loop()
|
| 51 |
+
elif choice == 5:
|
| 52 |
+
setting = input("Settings\n1. Prompts Saved\n2. Delete All Data\n")
|
| 53 |
+
setSettings(setting)
|
| 54 |
+
loop()
|
| 55 |
+
def clearOldMem():
|
| 56 |
+
f = open("docs/data.txt", "rt")
|
| 57 |
+
cf = open("docs/customdata.txt", "rt")
|
| 58 |
+
fl = f.readlines()
|
| 59 |
+
cfl = cf.readlines()
|
| 60 |
+
if len(fl) > usersettings.prompts:
|
| 61 |
+
numOver = len(fl) - usersettings.prompts
|
| 62 |
+
lines = []
|
| 63 |
+
lines = fl
|
| 64 |
+
|
| 65 |
+
f.close()
|
| 66 |
+
f = open("docs/data.txt", "w")
|
| 67 |
+
# iterate each line
|
| 68 |
+
for number, line in enumerate(lines):
|
| 69 |
+
if not number < numOver:
|
| 70 |
+
f.write(line)
|
| 71 |
+
if len(cfl) > usersettings.prompts:
|
| 72 |
+
numOver = len(cfl) - usersettings.prompts
|
| 73 |
+
lines = []
|
| 74 |
+
lines = cfl
|
| 75 |
+
|
| 76 |
+
cf.close()
|
| 77 |
+
cf = open("docs/customdata.txt", "w")
|
| 78 |
+
# iterate each line
|
| 79 |
+
for number, line in enumerate(lines):
|
| 80 |
+
if not number < numOver:
|
| 81 |
+
cf.write(line)
|
| 82 |
+
def setSettings(setting):
|
| 83 |
+
setting = int(setting)
|
| 84 |
+
if setting == 1:
|
| 85 |
+
print("Prompts Saved:\nAmount of prompts saved in memory before deletion\n")
|
| 86 |
+
settingChange = input("Set the amount of prompts to save ")
|
| 87 |
+
try:
|
| 88 |
+
settingChange = int(settingChange)
|
| 89 |
+
except:
|
| 90 |
+
print("Not a number!")
|
| 91 |
+
setSettings(setting)
|
| 92 |
+
usersettings.prompts = settingChange
|
| 93 |
+
elif setting == 2:
|
| 94 |
+
delRes = input("Are you sure you want to delete all data?(y/n) ")
|
| 95 |
+
if delRes == "y":
|
| 96 |
+
if os.path.exists("docs/data.txt"):
|
| 97 |
+
os.remove("docs/data.txt")
|
| 98 |
+
if os.path.exists("docs/customdata.txt"):
|
| 99 |
+
os.remove("docs/customdata.txt")
|
| 100 |
+
file = open("docs/data.txt", "x")
|
| 101 |
+
file = open("docs/customdata.txt", "x")
|
| 102 |
+
file.close()
|
| 103 |
+
|
| 104 |
+
else:
|
| 105 |
+
print("Invalid Response!")
|
| 106 |
+
loop()
|
| 107 |
+
loop()
|
| 108 |
+
def write():
|
| 109 |
+
|
| 110 |
+
#Ask user questions
|
| 111 |
+
prompt = input("What is 1 hobby you have?(Be as specific as possible, e.g. instead of doing coding, do python coding. You can always run it again.) ")
|
| 112 |
+
wikidata = wiki.summary(prompt)
|
| 113 |
+
# Open files
|
| 114 |
+
data = open("docs/data.txt", "at")
|
| 115 |
+
data.write(str(wikidata) + "\n")
|
| 116 |
+
data.close()
|
| 117 |
+
# Return to menu
|
| 118 |
+
loop()
|
| 119 |
+
|
| 120 |
+
def custom():
|
| 121 |
+
|
| 122 |
+
#Ask user questions
|
| 123 |
+
prompt = input("Write everything you can about this topic. ")
|
| 124 |
+
# Open files
|
| 125 |
+
data = open("docs/customdata.txt", "at")
|
| 126 |
+
data.write(prompt + "\n")
|
| 127 |
+
data.close()
|
| 128 |
+
# Return to menu
|
| 129 |
+
loop()
|
| 130 |
+
|
| 131 |
+
def chatbot(input_text):
|
| 132 |
+
my_assistant = blube.getAssistant()
|
| 133 |
+
persona = blube.getPersona()
|
| 134 |
+
|
| 135 |
+
print("(1/4) Message sent, creating thread...\n")
|
| 136 |
+
# Create a thread for the assistant
|
| 137 |
+
thread = client.beta.threads.create()
|
| 138 |
+
message = client.beta.threads.messages.create(
|
| 139 |
+
thread_id=thread.id,
|
| 140 |
+
role="user",
|
| 141 |
+
content=f"{input_text}"
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
print("(2/4) Thread created, running thread...\n")
|
| 145 |
+
|
| 146 |
+
# Run the thread
|
| 147 |
+
run = client.beta.threads.runs.create(
|
| 148 |
+
thread_id=thread.id,
|
| 149 |
+
assistant_id=my_assistant.id,
|
| 150 |
+
instructions=f"{persona}"
|
| 151 |
+
)
|
| 152 |
+
print("(3/4) Thread active, getting thread...\n")
|
| 153 |
+
|
| 154 |
+
# Get the thread
|
| 155 |
+
run = client.beta.threads.runs.retrieve(
|
| 156 |
+
thread_id=thread.id,
|
| 157 |
+
run_id=run.id
|
| 158 |
+
)
|
| 159 |
+
print("(4/4) Thread received, awaiting chat completion\n")
|
| 160 |
+
|
| 161 |
+
# Wait for completion
|
| 162 |
+
t: int = 0
|
| 163 |
+
tt = 0
|
| 164 |
+
errorCode = 0
|
| 165 |
+
while run.status != "completed":
|
| 166 |
+
run = client.beta.threads.runs.retrieve(
|
| 167 |
+
thread_id=thread.id, run_id=run.id
|
| 168 |
+
)
|
| 169 |
+
s = run.status
|
| 170 |
+
|
| 171 |
+
if s == "failed":
|
| 172 |
+
print(f"Process failed after {tt} ticks at {run.failed_at} with error stack:\n{run.last_error}\n\n")
|
| 173 |
+
errorCode = 1
|
| 174 |
+
break
|
| 175 |
+
elif s == "cancelled":
|
| 176 |
+
print(f"Process cancelled after {tt} ticks at {run.cancelled_at} with error stack:\n{run.last_error}\n\n")
|
| 177 |
+
errorCode = 2
|
| 178 |
+
elif s == "in_progress" or s == "queued":
|
| 179 |
+
t = t + 1
|
| 180 |
+
tt = tt + 1
|
| 181 |
+
else:
|
| 182 |
+
print(s)
|
| 183 |
+
if t > 15:
|
| 184 |
+
print(f"Time taken is over 15 ticks, average time is 11, check issues.\n\nINFO: Status is {s} and the total ticks is {tt}")
|
| 185 |
+
t = 0
|
| 186 |
+
if errorCode == 1:
|
| 187 |
+
raise RuntimeError("\n\nThe process finished with an error: Process failed unexpectedly. Check the command prompt for more details. This error is most likely a overuse error, so the program will sleep for 20 seconds to avoid more errors\n\n")
|
| 188 |
+
time.sleep(20)
|
| 189 |
+
print("\n20 seconds is over: requests are up")
|
| 190 |
+
elif errorCode == 2:
|
| 191 |
+
raise RuntimeError("The process finished with an error: Process cancelled unexpectedly. Check the command prompt for more details.")
|
| 192 |
+
else:
|
| 193 |
+
messages = client.beta.threads.messages.list(
|
| 194 |
+
thread_id=thread.id
|
| 195 |
+
)
|
| 196 |
+
messages = messages.json()
|
| 197 |
+
print(f"Process completed in {tt} ticks at {run.completed_at}")
|
| 198 |
+
|
| 199 |
+
mesf = open("message.json", "w")
|
| 200 |
+
mesf.write(messages)
|
| 201 |
+
mesf.close()
|
| 202 |
+
|
| 203 |
+
mesf = open("./message.json", "rt")
|
| 204 |
+
mess = json.load(mesf)
|
| 205 |
+
mess = mess["data"]
|
| 206 |
+
|
| 207 |
+
all_msgs = []
|
| 208 |
+
l = 0
|
| 209 |
+
for m in mess:
|
| 210 |
+
l = l + 1
|
| 211 |
+
for i in range(l - 1):
|
| 212 |
+
all_msgs.append(mess[i]["content"][0]["text"]["value"])
|
| 213 |
+
|
| 214 |
+
all_msgs = str(all_msgs)
|
| 215 |
+
all_msgs = blube.format(all_msgs)
|
| 216 |
+
return all_msgs
|
| 217 |
+
#Start Project
|
| 218 |
+
|
| 219 |
+
start()
|
| 220 |
+
loop()
|
blubeAPI.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
+
|
| 4 |
+
def format(data: str):
|
| 5 |
+
data = data.replace("['", "")
|
| 6 |
+
data = data.replace("']", "")
|
| 7 |
+
data = data.replace("[\"", "")
|
| 8 |
+
data = data.replace("\"]", "")
|
| 9 |
+
data = data.replace("\\\'", "\'")
|
| 10 |
+
data = data.replace("\\\n", "")
|
| 11 |
+
return data
|
| 12 |
+
def runbot(chatbot, client: openai.OpenAI):
|
| 13 |
+
iface = gr.Interface(fn=chatbot,
|
| 14 |
+
inputs=gr.components.Textbox(lines=7, label="Enter your text"),
|
| 15 |
+
outputs="text",
|
| 16 |
+
title="Blue BotBuilders AI")
|
| 17 |
+
|
| 18 |
+
global thread
|
| 19 |
+
global my_assistant
|
| 20 |
+
global persona
|
| 21 |
+
print("\n\n\n\n\nSTACK and INFO:\n\n")
|
| 22 |
+
# Get persona
|
| 23 |
+
persona = open("data/persona.txt")
|
| 24 |
+
persona = persona.readlines()
|
| 25 |
+
|
| 26 |
+
# Get files and send them
|
| 27 |
+
print("(1/2) Sending data to OpenAI, this may take a while...\n")
|
| 28 |
+
up_files = []
|
| 29 |
+
files = client.files.create(
|
| 30 |
+
file=open("docs/data.txt", "rb"),
|
| 31 |
+
purpose="assistants"
|
| 32 |
+
)
|
| 33 |
+
up_files.append(files.id)
|
| 34 |
+
files = client.files.create(
|
| 35 |
+
file=open("docs/customdata.txt", "rb"),
|
| 36 |
+
purpose="assistants"
|
| 37 |
+
)
|
| 38 |
+
up_files.append(files.id)
|
| 39 |
+
my_assistant = client.beta.assistants.create(
|
| 40 |
+
instructions=f"{persona}",
|
| 41 |
+
name="Blube AI",
|
| 42 |
+
tools=[{"type": "retrieval"}],
|
| 43 |
+
model="gpt-3.5-turbo-1106",
|
| 44 |
+
file_ids=up_files
|
| 45 |
+
)
|
| 46 |
+
print("(2/2) Finished uploading files, launching interface...\n")
|
| 47 |
+
|
| 48 |
+
iface.launch(share=True)
|
| 49 |
+
def getAssistant():
|
| 50 |
+
return my_assistant
|
| 51 |
+
def getPersona():
|
| 52 |
+
return persona
|
| 53 |
+
def getThread():
|
| 54 |
+
return thread
|
data/persona.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{{char}} refers to you, the ai or character. You, the AI, will act like {{char}}.
|
| 2 |
+
{{user}} refers to the input, or the person.
|
| 3 |
+
Any word or set of words that are after a set of {{ and before a set of }} are saved as a variable and can be referenced later.
|
| 4 |
+
SET is an operation that can change the value of a previously defined variable. If SET is said, the value of the value mentioned afterward is changed.
|
| 5 |
+
VALUE will tell the user the value of a variable mentioned afterward.
|
| 6 |
+
IF is a condition that will say if the following statement is true or false, it accepts booleans. If SET is said to assign a variable to an IF condition, that variable will be SET to the result, true or false. If it is not being assigned to a variable, a THEN statement can be used. A THEN statement will run the text mentioned after if the IF condition was true.
|
| 7 |
+
|
| 8 |
+
|
delscript.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
if os.path.exists("docs/data.txt"):
|
| 4 |
+
os.remove("docs/data.txt")
|
| 5 |
+
if os.path.exists("docs/customdata.txt"):
|
| 6 |
+
os.remove("docs/customdata.txt")
|
| 7 |
+
file = open("docs/data.txt", "x")
|
| 8 |
+
file = open("docs/customdata.txt", "x")
|
| 9 |
+
file.close()
|
docs/customdata.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
To the bone is welcome to the underground how was the fall
|
| 2 |
+
The Blue BotBuilders are a team for FLL, or FIRST Lego League, made up of Jack D, Jack T, Nick, Seb, and Ethan
|
| 3 |
+
The Innovation project is a part of the FLL competition that adds to the point of the robot game, and in some cases swing entire matches for a team. The Innovation project for The Blue BotBuilders is an AI that can tell people about their hobbies, or {{char}}
|
docs/data.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation.Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly procedural), object-oriented and functional programming. It is often described as a "batteries included" language due to its comprehensive standard library.Guido van Rossum began working on Python in the late 1980s as a successor to the ABC programming language and first released it in 1991 as Python 0.9.0. Python 2.0 was released in 2000. Python 3.0, released in 2008, was a major revision not completely backward-compatible with earlier versions. Python 2.7.18, released in 2020, was the last release of Python 2.Python consistently ranks as one of the most popular programming languages.
|
| 2 |
+
The FIRST LEGO League Challenge (formerly known as FIRST LEGO League) is an international competition organized by FIRST for elementary and middle school students (ages 9๏ฟฝ14 in the United States and Canada, 9-15 elsewhere).Each year in August, FIRST LEGO League Challenge teams are introduced to a scientific and real-world challenge for teams to focus and research on. The robotics part of the competition involves designing and programming Lego Education robots to complete tasks. The students work out a solution to a problem related to the theme (changes every year) and then meet for regional, national and international tournaments to compete, share their knowledge, compare ideas, and display their robots.
|
| 3 |
+
The FIRST LEGO League Challenge is a partnership between FIRST and the LEGO Group. It is the third division of FIRST LEGO League, following FIRST LEGO League Discover for ages 4-6, and FIRST Lego League Explore for ages 6-10.
|
| 4 |
+
A leg is a weight-bearing and locomotive anatomical structure, usually having a columnar shape. During locomotion, legs function as "extensible struts". The combination of movements at all joints can be modeled as a single, linear element capable of changing length and rotating about an omnidirectional "hip" joint.
|
| 5 |
+
As an anatomical animal structure it is used for locomotion. The distal end is often modified to distribute force (such as a foot). Most animals have an even number of legs.
|
| 6 |
+
As a component of furniture, it is used for the economy of materials needed to provide the support for the useful surface, such as the table top or chair seat.
|
| 7 |
+
A hobby is considered to be a regular activity that is done for enjoyment, typically during one's leisure time. Hobbies include collecting themed items and objects, engaging in creative and artistic pursuits, playing sports, or pursuing other amusements. Participation in hobbies encourages acquiring substantial skills and knowledge in that area. A list of hobbies changes with renewed interests and developing fashions, making it diverse and lengthy. Hobbies tend to follow trends in society. For example, stamp collecting was popular during the nineteenth and twentieth centuries as postal systems were the main means of communication; as of 2023, video games became more popular following technological advances. The advancing production and technology of the nineteenth century provided workers with more leisure time to engage in hobbies. Because of this, the efforts of people investing in hobbies has increased with time.
|
| 8 |
+
Hobbyists may be identified under three sub-categories: casual leisure which is intrinsically rewarding, short-lived, pleasurable activity requiring little or no preparation, serious leisure which is the systematic pursuit of an amateur, hobbyist, or volunteer that is substantial, rewarding and results in a sense of accomplishment, and finally project-based leisure which is a short-term, often one-off, project that is rewarding.
|
extra-requirements/1.exe
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1bb46f65bb6f71b295801c8ff596bb5b69fa4c0645541db5f3d3bac33aa6eade
|
| 3 |
+
size 25932664
|
extra-requirements/2.exe
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:137b8591f2c772d0fe53225015eab5f2e75d0d51cf9c384a0ab5162e2aecaf59
|
| 3 |
+
size 3759640
|
extra-requirements/3.exe
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:365d072ac4ef47f8774f4d2094108035e2291a0073702db25fa7797a30861fc9
|
| 3 |
+
size 8594944
|
extra-requirements/help.png
ADDED
|
flagged/log.csv
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Enter your text,output,flag,username,timestamp
|
| 2 |
+
coding,,,,2023-10-12 17:48:28.718511
|
installpackages.bat
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
pip install -r reqs.txt --no-warn-script-location
|
| 3 |
+
echo /
|
| 4 |
+
echo /
|
| 5 |
+
echo Packages Installed, fixing OpenAI
|
| 6 |
+
echo /
|
| 7 |
+
echo /
|
| 8 |
+
pip install --upgrade openai
|
| 9 |
+
echo /
|
| 10 |
+
echo /
|
| 11 |
+
echo Upgrading OpenAI
|
| 12 |
+
echo /
|
| 13 |
+
echo /
|
| 14 |
+
openai migrate
|
| 15 |
+
pause
|
installpython.bat
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
echo I can't do everything for you, do it yourself
|
| 3 |
+
echo I quite literally can't do it for you just install python.
|
| 4 |
+
pause
|
message.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"data": [{"id": "msg_WyF5csMNmhhYQ6oath4GMOfC", "assistant_id": "asst_wshVwMH2kU2Bmp3Cv96CMffz", "content": [{"text": {"annotations": [], "value": "HTML, which stands for HyperText Markup Language, is the standard language used to create and design web pages. It employs a set of markup tags to define the structure and layout of content on a web page. These tags are used to describe various elements such as headings, paragraphs, links, images, and more. HTML documents are interpreted by web browsers to display the content and structure as intended by the web page creator."}, "type": "text"}], "created_at": 1699683752, "file_ids": [], "metadata": {}, "object": "thread.message", "role": "assistant", "run_id": "run_xksiPl720swA8EzojMkIbcWz", "thread_id": "thread_QMY7IpgT8ji3R5WwbLSx3atD"}, {"id": "msg_vcFPVarPuWI7uZ24DwePCgj7", "assistant_id": null, "content": [{"text": {"annotations": [], "value": "what is HTML"}, "type": "text"}], "created_at": 1699683751, "file_ids": [], "metadata": {}, "object": "thread.message", "role": "user", "run_id": null, "thread_id": "thread_QMY7IpgT8ji3R5WwbLSx3atD"}], "object": "list", "first_id": "msg_WyF5csMNmhhYQ6oath4GMOfC", "last_id": "msg_vcFPVarPuWI7uZ24DwePCgj7", "has_more": false}
|
reqs.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
setuptools
|
| 2 |
+
aiohttp==3.8.3
|
| 3 |
+
yarl==1.8.1
|
| 4 |
+
frozenlist==1.3.1
|
| 5 |
+
openai
|
| 6 |
+
gpt_index==0.4.24
|
| 7 |
+
langchain==0.0.148
|
| 8 |
+
PyPDF2
|
| 9 |
+
PyCryptodome
|
| 10 |
+
gradio==3.36.1
|
| 11 |
+
wikipedia
|
resetdata.bat
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
echo Deleting Data
|
| 3 |
+
python delscript.py
|
| 4 |
+
echo Data Deleted
|
| 5 |
+
pause
|
run.bat
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
python app.py
|
| 3 |
+
pause
|