Skip to content

Commit

Permalink
Added the System Prompt feature!
Browse files Browse the repository at this point in the history
  • Loading branch information
aledipa committed Mar 10, 2024
1 parent d96b284 commit fb6dd1a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
Binary file modified src/.DS_Store
Binary file not shown.
27 changes: 22 additions & 5 deletions src/FreeGPT4_Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def saveSettings(request, file):
data["keyword"] = request.form["keyword"]
data["provider"] = request.form["provider"]
data["tone"] = request.form["tone"]
data["system_prompt"] = request.form["system_prompt"]
file = request.files["cookie_file"]
#checks if the file is not empty
if file.filename != '':
Expand Down Expand Up @@ -95,6 +96,7 @@ def applySettings(file):
args.cookie_file = data["cookie_file"]
args.remove_sources = data["remove_sources"]
args.tone = data["tone"]
args.system_prompt = data["system_prompt"]
f.close()
return

Expand Down Expand Up @@ -125,12 +127,12 @@ async def index() -> str:
print("ici")
if question is None:
return "<p id='response'>Please enter a question</p>"
print("\nInput: " + question)
print("\nTone: " + tone)

# Gets the response from the bot
print(g4f.Provider.Bing.params) # supported args
print("COOKIES: " + str(len(args.cookie_file)))
print(PROVIDERS[args.provider].params) # supported args
print("\nCookies: " + str(len(args.cookie_file)))
print("\nInput: " + question)
print("\nTone: " + tone)
if (len(args.cookie_file) != 0):
try:
cookies = json.load(open(args.cookie_file)) # Loads the cookies from the file
Expand All @@ -146,7 +148,10 @@ async def index() -> str:
response = (
await PROVIDERS[args.provider].create_async(
model=args.model,
messages=[{"role": "user", "content": question,}],
messages=[
{"role": "system", "content": args.system_prompt},
{"role": "user", "content": question}
],
cookies=cookies,
auth=True,
tone=tone
Expand Down Expand Up @@ -296,6 +301,13 @@ async def save():
type=str,
help="Specify the model's tone if supported (Bing's default: Precise)",
)
parser.add_argument(
"--system-prompt",
action='store',
required=False,
type=str,
help="Use a system prompt to 'customize' the answers",
)
args = parser.parse_args()

# Loads the settings from the file
Expand Down Expand Up @@ -338,6 +350,11 @@ async def save():
data["tone"] = args.tone
else:
args.tone = data["tone"]

if (args.system_prompt != None):
data["system_prompt"] = args.system_prompt
else:
args.system_prompt = data["system_prompt"]

json.dump(data, f)
f.close()
Expand Down
12 changes: 1 addition & 11 deletions src/data/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
{
"password": "",
"file_input": "True",
"remove_sources": "True",
"port": "5500",
"model": "gpt-4",
"provider": "Bing",
"tone": "Precise",
"keyword": "text",
"cookie_file": "data/cookies.json"
}
{"password": "", "file_input": "True", "remove_sources": "True", "port": "5500", "model": "gpt-4", "provider": "You", "tone": "Precise", "keyword": "text", "cookie_file": "data/cookies.json", "system_prompt": "you're an asian guy named Chong helping tourists in your continent, from now on n ollow your role for every next question"}
4 changes: 4 additions & 0 deletions src/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ input::placeholder {
font-style: italic;
}

textarea::placeholder {
font-style: italic;
}

.inter {
font-family: 'Inter', sans-serif;
}
Expand Down
8 changes: 8 additions & 0 deletions src/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ <h2 class="title blue text-2xl">Server settings</h2>
</b>
</td>
</tr>
<tr>
<td class="py-1 fond-bold inter darkblue text-lg border-b border-slate-800">
<b>System Prompt:</b>
<b>
<textarea type="text" id="system_prompt" name="system_prompt" class="input outline-none py-1 px-2 my-2 rounded-lg inter w-full" placeholder="i.e. You're a virtual flight assistant, from now on follow your role for every answer." value="{{ data['system_prompt'] }}"></textarea>
</b>
</td>
</tr>
</table>
<!-- enter password to confirm -->
<div class="flex justify-start mt-12">
Expand Down
Binary file modified tests/.DS_Store
Binary file not shown.

0 comments on commit fb6dd1a

Please sign in to comment.