Skip to content

Commit

Permalink
delete api keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Fer14 committed Aug 17, 2024
1 parent e7e83ca commit 31d212c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 105 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

## Android App

This the open source code for the dreamXplainer Android App, previously on Play Store. Written in Flutter and using the openai api. Also integrates with adsense ads engine.
This the open source code for the dreamXplainer Android App, previously on Play Store. Written in Flutter and using the openai api. Also integrates with adsense ads engine. It uses Firebase to handle users login and sign ins.

<p float="center">
<img src="./screenshots/1.png" width="200" />
Expand All @@ -27,7 +27,7 @@ This the open source code for the dreamXplainer Android App, previously on Play

## Open source

We decided to open source the project since we were not going to continue it. We deleted all api keys and tokens but you can put yours and it should work.
We decided to open source the project since we were not going to continue it. We deleted all api keys and tokens but you can put yours and it should work.

## Instalation

Expand Down
54 changes: 23 additions & 31 deletions flutter_code/lib/ads/ad_mob_service.dart
Original file line number Diff line number Diff line change
@@ -1,56 +1,48 @@


import 'dart:io';

import 'package:google_mobile_ads/google_mobile_ads.dart';

class AdMobService{
class AdMobService {
static String? get bannerAdUnitId {
if(Platform.isAndroid){
return 'ca-app-pub-7027299532858015/2193794122';
}else if (Platform.isIOS){
return 'ca-app-pub-7027299532858015/2193794122';
if (Platform.isAndroid) {
return 'yourAdsToken';
} else if (Platform.isIOS) {
return 'yourAdsToken';
}
return null;
}

static String? get bannerAdUnitId2 {
if(Platform.isAndroid){
return 'ca-app-pub-7027299532858015/9513132515';
}else if (Platform.isIOS){
return 'ca-app-pub-7027299532858015/2193794122';
if (Platform.isAndroid) {
return 'yourAdsToken';
} else if (Platform.isIOS) {
return 'yourAdsToken';
}
return null;
}


static final BannerAdListener bannerListener = BannerAdListener(
onAdLoaded: (ad) => print('Ad loaded'),
onAdFailedToLoad: (ad,error) {
ad.dispose();
print("error to load ad: ${error}");
}
);


onAdLoaded: (ad) => print('Ad loaded'),
onAdFailedToLoad: (ad, error) {
ad.dispose();
print("error to load ad: ${error}");
});

static String? get interstitialAdUnitId {
if(Platform.isAndroid){
return 'ca-app-pub-7027299532858015/5412652706';
}else if (Platform.isIOS){
return 'ca-app-pub-7027299532858015/5412652706';
if (Platform.isAndroid) {
return 'yourAdsToken';
} else if (Platform.isIOS) {
return 'yourAdsToken';
}
return null;
}

static String? get reardedAdUnitId {
if(Platform.isAndroid){
return 'ca-app-pub-7027299532858015/6859759457';
}else if (Platform.isIOS){
return 'ca-app-pub-7027299532858015/6859759457';
if (Platform.isAndroid) {
return 'yourAdsToken';
} else if (Platform.isIOS) {
return 'yourAdsToken';
}
return null;
}


}
}
141 changes: 70 additions & 71 deletions flutter_code/lib/provider/answer_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'dart:convert';
import '../utils/global_vars.dart';

class AnswerProvider extends ChangeNotifier {

int _rewardScore = GlobalVars.score_state;
int get rewardScore => _rewardScore;

Expand All @@ -18,16 +17,21 @@ class AnswerProvider extends ChangeNotifier {

Future<void> addReward() async {
await Future.delayed(Duration(seconds: 1));
final doc = FirebaseFirestore.instance.collection('user-coins').doc(GlobalVars.email);
final doc = FirebaseFirestore.instance
.collection('user-coins')
.doc(GlobalVars.email);
await doc.update({
'coins': FieldValue.increment(1),
});
_rewardScore++;
notifyListeners();
}

Future<void> subReward() async {
print("subReward");
final doc = FirebaseFirestore.instance.collection('user-coins').doc(GlobalVars.email);
final doc = FirebaseFirestore.instance
.collection('user-coins')
.doc(GlobalVars.email);
await doc.update({
'coins': FieldValue.increment(-1),
});
Expand Down Expand Up @@ -55,32 +59,39 @@ class AnswerProvider extends ChangeNotifier {
notifyListeners();
}


Map<String, String> tagwords_en = {
'Funny':'be very funny, introducing new crazy characters',
'Romantic': 'be very romantic, introducing love and relationships in your story',
'Funny': 'be very funny, introducing new crazy characters',
'Romantic':
'be very romantic, introducing love and relationships in your story',
'Horror': 'be very scary, introducing scary characters and jumpscares',
'Sad': 'be very sad, negative, disheartened and disastrous story',
'Serious':'be extremely rigurous, the sotry needs to be real, without crazy stuff',
'Fantasy':'be very fantasy, introducing new fantasy characters',
'Tarantino':'be very dramatic, related with blood, deaths and violence, and lots of blood',
'Action':'contain plenty of action, with many fights and explosions',
'Erotic':'be extremely sexual and filthy, containing porn scenes and hot sentences',
'Serious':
'be extremely rigurous, the sotry needs to be real, without crazy stuff',
'Fantasy': 'be very fantasy, introducing new fantasy characters',
'Tarantino':
'be very dramatic, related with blood, deaths and violence, and lots of blood',
'Action': 'contain plenty of action, with many fights and explosions',
'Erotic':
'be extremely sexual and filthy, containing porn scenes and hot sentences',
};

Map<String, String> tagwords_es = {
'Divertido': 'ser muy divertido, introducir nuevos personajes locos',
'Romántico': 'ser muy romántico, introducir el amor y las relaciones amorosas en tu historia',
'Romántico':
'ser muy romántico, introducir el amor y las relaciones amorosas en tu historia',
'Horror': 'ser muy aterrador, introducir personajes aterradores y sustos',
'Triste': 'ser muy triste, negativo, descorazonador y desastroso',
'Serio': 'ser extremadamente riguroso, la historia debe ser real, sin cosas locas',
'Fantasía': 'ser muy fantasioso, introduciendo nuevos personajes de fantasía',
'Tarantino': 'ser muy dramático, relacionado con sangre, muertes y violencia, y mucha sangre',
'Serio':
'ser extremadamente riguroso, la historia debe ser real, sin cosas locas',
'Fantasía':
'ser muy fantasioso, introduciendo nuevos personajes de fantasía',
'Tarantino':
'ser muy dramático, relacionado con sangre, muertes y violencia, y mucha sangre',
'Acción': 'contener mucha acción, con muchas peleas y explosiones',
'Erótico': 'ser extremadamente sexual y sucio, contener escenas pornográficas y frases picantes',
'Erótico':
'ser extremadamente sexual y sucio, contener escenas pornográficas y frases picantes',
};


Future<void> callGPT(String text, String tag, locale) async {
_dreamanswer = text;
subReward();
Expand All @@ -91,14 +102,11 @@ class AnswerProvider extends ChangeNotifier {
addReward();
}
notifyListeners();
}

}

String API_KEY = "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";
String API_KEY = "yourApiKey";

Future<void> GPT(String text, string_tag, locale) async {


_explanationError = false;
_explanationAnswer = null;

Expand All @@ -107,75 +115,66 @@ class AnswerProvider extends ChangeNotifier {

String prompt = "";

if(locale.toString() == "es"){
if (locale.toString() == "es") {
String? tag = tagwords_es[string_tag];

String prompt1_es = "Te voy a escribir un sueño que yo tuve anoche y tienes que inventarte una historia que continúe con el sueño y una explicación del sueño. Tu respuesta debe tener 2 párrafos. \n En el primer párrafo, explica por qué soñé con esa cosa, qué significa y qué debo esperar en mi vida según este sueño. Puedes hacer conjeturas y especular sobre lo que quieras. Intenta $tag. El párrafo tiene que ser corto. Evita hablar en primera persona. \n En el segundo párrafo, continua el sueño de forma natural, utilizando la segunda persona. Tienes que ser creativo y la historia tiene que $tag. El párrafo tiene que ser corto. No introduzcas el párrafo con frases como: 'Continuando el sueño...', ni 'Te despiertas en...'. \n El sueño que tuve anoche fue: ";
String prompt1_es =
"Te voy a escribir un sueño que yo tuve anoche y tienes que inventarte una historia que continúe con el sueño y una explicación del sueño. Tu respuesta debe tener 2 párrafos. \n En el primer párrafo, explica por qué soñé con esa cosa, qué significa y qué debo esperar en mi vida según este sueño. Puedes hacer conjeturas y especular sobre lo que quieras. Intenta $tag. El párrafo tiene que ser corto. Evita hablar en primera persona. \n En el segundo párrafo, continua el sueño de forma natural, utilizando la segunda persona. Tienes que ser creativo y la historia tiene que $tag. El párrafo tiene que ser corto. No introduzcas el párrafo con frases como: 'Continuando el sueño...', ni 'Te despiertas en...'. \n El sueño que tuve anoche fue: ";
String prompt2_es = "\n La interpretación que se te ocurre es: \n ";
prompt = prompt1_es + "\n $text" + prompt2_es;
}
else{

} else {
String? tag = tagwords_en[string_tag];

String prompt1_es = "You will be given a dream that I had last night and you have to come up with a story that fulfills the dream and an explanation. Your answer has to be 2 paragraphs long.\n In the first paragraph, you will answer why I dreamt of that thing, what does it signify and what should I expect next in my life according to this dream. You can make guesses and speculate about whatever you want. Try to $tag. This paragraph will be 2 or 3 sentences long.\n In the second paragraph, you will complete what happened after the dream as if I had not woken up. You have to be creative and the story has to $tag. Use the past tense. Avoid talking in first person. This paragraph will be 2 sentences long. \n The story in the dream I had last night was: ";
String prompt1_es =
"You will be given a dream that I had last night and you have to come up with a story that fulfills the dream and an explanation. Your answer has to be 2 paragraphs long.\n In the first paragraph, you will answer why I dreamt of that thing, what does it signify and what should I expect next in my life according to this dream. You can make guesses and speculate about whatever you want. Try to $tag. This paragraph will be 2 or 3 sentences long.\n In the second paragraph, you will complete what happened after the dream as if I had not woken up. You have to be creative and the story has to $tag. Use the past tense. Avoid talking in first person. This paragraph will be 2 sentences long. \n The story in the dream I had last night was: ";
String prompt2_es = "\n The interpretation you come up with is: \n ";
prompt = prompt1_es + "\n $text" + prompt2_es;
}


//await Future.delayed(Duration(seconds: 1));
/* _explanationAnswer =
"Answer explanation from GPT-3........................aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
_explanationError = false;*/


var url = Uri.parse('https://api.openai.com/v1/chat/completions');

var headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer $API_KEY'
};

var data = {
'model': 'gpt-3.5-turbo',
'messages': [
{'role': 'user', 'content': '$prompt'}
]
};

try{
var response = await http.post(url, headers: headers, body: json.encode(data));
Map map = json.decode(response.body);
String answer = map["choices"][0]['message']['content'];
// split answer into 2 parts
List<String> lines = answer.split('\n');
if(locale.toString() == "es"){

final bytes = lines[0].codeUnits;
_explanationAnswer = Utf8Decoder().convert(bytes);

final bytes2 = lines[2].codeUnits;
_storyAnswer = Utf8Decoder().convert(bytes2);

print("decoded:");
print(_explanationAnswer);

}
else {
_explanationAnswer= lines[0];
_storyAnswer= lines[2];
}

}catch(e){
_explanationError = true;
_storyError = true;
}

'Authorization': 'Bearer $API_KEY'
};

var data = {
'model': 'gpt-3.5-turbo',
'messages': [
{'role': 'user', 'content': '$prompt'}
]
};

try {
var response =
await http.post(url, headers: headers, body: json.encode(data));
Map map = json.decode(response.body);
String answer = map["choices"][0]['message']['content'];
// split answer into 2 parts
List<String> lines = answer.split('\n');
if (locale.toString() == "es") {
final bytes = lines[0].codeUnits;
_explanationAnswer = Utf8Decoder().convert(bytes);

final bytes2 = lines[2].codeUnits;
_storyAnswer = Utf8Decoder().convert(bytes2);

print("decoded:");
print(_explanationAnswer);
} else {
_explanationAnswer = lines[0];
_storyAnswer = lines[2];
}
} catch (e) {
_explanationError = true;
_storyError = true;
}

notifyListeners();
}



}
2 changes: 1 addition & 1 deletion openai_api/prueba_openai_api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"outputs": [],
"source": [
"# Global variables:\n",
"API_KEY = \"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\"\n",
"API_KEY = \"yourApiKey\"\n",
"# openai.api_key = os.getenv(API_KEY)\n",
"openai.api_key = API_KEY"
]
Expand Down

0 comments on commit 31d212c

Please sign in to comment.