Skip to content

Commit

Permalink
feature: global system prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
DevEmperor committed Jun 20, 2024
1 parent e2f24e9 commit e802b22
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,19 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) return;

Intent intent;
String systemQuery = sp.getString("net.devemperor.wristassist.global_system_query", "");
if (systemQuery.isEmpty()) systemQuery = null;
if (requestCode == 1337) {
intent = new Intent(this, ChatActivity.class);
intent.putExtra("net.devemperor.wristassist.query", data.getStringExtra("net.devemperor.wristassist.input.content"));
intent.putExtra("net.devemperor.wristassist.system_query", systemQuery);
startActivity(intent);
}
if (requestCode == 1338) {
intent = new Intent(this, ChatActivity.class);
intent.putExtra("net.devemperor.wristassist.query", data.getStringExtra("net.devemperor.wristassist.input.content2"));
intent.putExtra("net.devemperor.wristassist.system_query", data.getStringExtra("net.devemperor.wristassist.input.content"));
systemQuery = (systemQuery == null ? "" : systemQuery + "\n") + data.getStringExtra("net.devemperor.wristassist.input.content");
intent.putExtra("net.devemperor.wristassist.system_query", systemQuery);
startActivity(intent);
}
if (requestCode == 1340) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
if (chatModelPreference != null) chatModelPreference.setSummaryProvider(preference -> chatModelPreference.getEntry());
if (customServerPreference.isChecked()) chatModelPreference.setEnabled(false);

Preference globalSystemQueryPreference = findPreference("net.devemperor.wristassist.global_system_query");
if (globalSystemQueryPreference != null) {
globalSystemQueryPreference.setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(getContext(), InputActivity.class);
intent.putExtra("net.devemperor.wristassist.input.title", getString(R.string.wristassist_define_global_system_prompt));
intent.putExtra("net.devemperor.wristassist.input.hint", getString(R.string.wristassist_system_prompt));
if (!sp.getString("net.devemperor.wristassist.global_system_query", "").isEmpty()) {
intent.putExtra("net.devemperor.wristassist.input.content", sp.getString("net.devemperor.wristassist.global_system_query", ""));
}
startActivityForResult(intent, 1338);
return true;
});
}

ListPreference ttsPreference = findPreference("net.devemperor.wristassist.tts");
if (ttsPreference != null) {
new TextToSpeech(getContext(), status -> {
Expand Down Expand Up @@ -144,6 +158,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
} else if (resultCode == Activity.RESULT_CANCELED && requestCode == 1337) {
customServerPreference.setChecked(false);
chatModelPreference.setEnabled(true);
} else if (resultCode == Activity.RESULT_OK && requestCode == 1338) {
String systemQuery = data.getStringExtra("net.devemperor.wristassist.input.content");
sp.edit().putString("net.devemperor.wristassist.global_system_query", systemQuery).apply();
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values-de-rDE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@
<string name="changelog_md_27">### Version 3.0.1 \n#### Wichtiger Hinweis: Änderungen an der OpenAI-API-Abrechnung \nOpenAI aktualisiert die Art und Weise, wie dein OpenAI-API-Konto ab **8. März 2024** abgerechnet wird. Anstatt eine Rechnung am Ende des Monats zu erhalten, musst du **Guthaben im Voraus erwerben**, um die API zu nutzen. <u>Klicke einfach auf die Schaltfläche "OK", um Guthaben zu deinem Konto hinzuzufügen.</u> Andernfalls werden API-Anfragen für WristAssist vorübergehend fehlschlagen, bis Guthaben erworben wird. \n</string>
<string name="changelog_md_28">### Version 3.0.2 \n#### Mehrere Fehlerbehebungen und Design Änderungen \n</string>
<string name="changelog_md_29">### Version 3.0.3 \n#### Neues GPT-4 Omni-Modell \nOpenAI hat ein neues Flaggschiff-Modell eingeführt, das Audio, Vision und Text in Echtzeit verarbeiten kann. Unterstützung für andere Eingabemethoden als Text wird in Zukunft verfügbar sein. Dieses Modell ist nur halb so teuer wie "GPT-4 Turbo" und kann in den Einstellungen ausgewählt werden. \n</string>
<string name="wristassist_global_system_query">Globale System Anweisung</string>
<string name="wristassist_define_global_system_prompt">Lege eine globale System Anweisung fest</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,6 @@
<string name="changelog_md_27">### Version 3.0.1 \n#### Important notice: Changes to your OpenAI API billing \nOpenAI is updating how they bill for your OpenAI API account starting **March 8, 2024**. Instead of receiving a bill at the end of the month, you will need to **pre-purchase credits** to use the API. <u>Just click the okay button to add credits to your account.</u> Otherwise, API requests will temporarily fail for WristAssist until credits are purchased. \n</string>
<string name="changelog_md_28">### Version 3.0.2 \n#### Several bugfixes and design changes \n</string>
<string name="changelog_md_29">### Version 3.0.3 \n#### New GPT-4 Omni model \nOpenAI introduced a new flagship model, that can reason across audio, vision, and text in real time. Support for input method other than text will be available in the future. You can switch to this model, which is only half the price as "GPT-4 Turbo", in the settings. \n</string>
<string name="wristassist_global_system_query">Global system query</string>
<string name="wristassist_define_global_system_prompt">Define global system prompt</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/xml/fragment_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
app:entryValues="@array/models_chat_values"
app:dialogTitle=" "/>

<Preference
app:key="net.devemperor.wristassist.global_system_query"
app:title="@string/wristassist_global_system_query"/>

<SeekBarPreference
app:key="net.devemperor.wristassist.font_size"
app:title="@string/wristassist_font_size"
Expand Down

0 comments on commit e802b22

Please sign in to comment.