Skip to content

Commit a01d8f7

Browse files
committed
Added new ai
1 parent 9cdcf39 commit a01d8f7

File tree

3 files changed

+131
-118
lines changed

3 files changed

+131
-118
lines changed

Screens/CodePage.js

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {useToast} from 'react-native-toast-notifications';
1616
import axios from 'axios';
1717
import ResultDiaplay from '../Components/Global/ReaultDiaplay';
1818
import Apikey from '../Apikey';
19+
import {GetGeminiProResponse} from "../AiApi";
1920

2021
export const CodePage = ({navigation}) => {
2122
const windowWidth = Dimensions.get('window').width;
@@ -44,44 +45,21 @@ export const CodePage = ({navigation}) => {
4445
});
4546
} else {
4647
setloading(true);
47-
let config = {
48-
method: 'post',
49-
maxBodyLength: Infinity,
50-
url:
51-
'https://generativelanguage.googleapis.com/v1beta2/models/chat-bison-001:generateMessage?key=' +
52-
Apikey,
53-
headers: {
54-
'Content-Type': 'application/json',
55-
},
56-
data: JSON.stringify({
57-
prompt: {
58-
messages: [
59-
{
60-
content: `generate Code for ${input} in ${input1}`,
61-
},
62-
],
63-
},
64-
}),
65-
};
66-
axios
67-
.request(config)
68-
.then(r => {
69-
setCode(r.data.candidates[0].content);
70-
setloading(false);
71-
})
72-
.catch(e => {
73-
setloading(false);
74-
if (e.message === 'Network Error') {
75-
toast.show('No Internet 😟', {
76-
type: 'danger',
77-
placement: 'top',
78-
duration: 3000,
79-
offset: 30,
80-
animationType: 'zoom-in',
81-
});
82-
}
83-
console.log(e.message);
84-
});
48+
try {
49+
const response = await GetGeminiProResponse([], `generate Code for ${input} in ${input1}`)
50+
setCode(response);
51+
}catch (e) {
52+
if (e.message === 'Network Error') {
53+
toast.show('No Internet 😟', {
54+
type: 'danger',
55+
placement: 'top',
56+
duration: 3000,
57+
offset: 30,
58+
animationType: 'zoom-in',
59+
});
60+
}
61+
}
62+
setloading(false);
8563
}
8664
}
8765
return (

Screens/EsseyPage.js

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {useToast} from 'react-native-toast-notifications';
1616
import axios from 'axios';
1717
import ResultDiaplay from '../Components/Global/ReaultDiaplay';
1818
import Apikey from '../Apikey';
19+
import {GetGeminiProResponse} from "../AiApi";
1920

2021
export const EsseyPage = ({navigation}) => {
2122
const windowWidth = Dimensions.get('window').width;
@@ -34,44 +35,60 @@ export const EsseyPage = ({navigation}) => {
3435
});
3536
} else {
3637
setloading(true);
37-
let config = {
38-
method: 'post',
39-
maxBodyLength: Infinity,
40-
url:
41-
'https://generativelanguage.googleapis.com/v1beta2/models/chat-bison-001:generateMessage?key=' +
42-
Apikey,
43-
headers: {
44-
'Content-Type': 'application/json',
45-
},
46-
data: JSON.stringify({
47-
prompt: {
48-
messages: [
49-
{
50-
content: `generate a detialed essey on topic ${input}`,
51-
},
52-
],
53-
},
54-
}),
55-
};
56-
axios
57-
.request(config)
58-
.then(r => {
59-
setResult(r.data.candidates[0].content);
60-
setloading(false);
61-
})
62-
.catch(e => {
63-
setloading(false);
64-
if (e.message === 'Network Error') {
65-
toast.show('No Internet 😟', {
66-
type: 'danger',
67-
placement: 'top',
68-
duration: 3000,
69-
offset: 30,
70-
animationType: 'zoom-in',
71-
});
72-
}
73-
console.log(e.message);
74-
});
38+
try {
39+
const response = await GetGeminiProResponse([], `generate a detialed essey on topic ${input}`)
40+
setResult(response);
41+
}catch (e) {
42+
if (e.message === 'Network Error') {
43+
toast.show('No Internet 😟', {
44+
type: 'danger',
45+
placement: 'top',
46+
duration: 3000,
47+
offset: 30,
48+
animationType: 'zoom-in',
49+
});
50+
}
51+
}
52+
setloading(false);
53+
// setloading(true);
54+
// let config = {
55+
// method: 'post',
56+
// maxBodyLength: Infinity,
57+
// url:
58+
// 'https://generativelanguage.googleapis.com/v1beta2/models/chat-bison-001:generateMessage?key=' +
59+
// Apikey,
60+
// headers: {
61+
// 'Content-Type': 'application/json',
62+
// },
63+
// data: JSON.stringify({
64+
// prompt: {
65+
// messages: [
66+
// {
67+
// content: `generate a detialed essey on topic ${input}`,
68+
// },
69+
// ],
70+
// },
71+
// }),
72+
// };
73+
// axios
74+
// .request(config)
75+
// .then(r => {
76+
// setResult(r.data.candidates[0].content);
77+
// setloading(false);
78+
// })
79+
// .catch(e => {
80+
// setloading(false);
81+
// if (e.message === 'Network Error') {
82+
// toast.show('No Internet 😟', {
83+
// type: 'danger',
84+
// placement: 'top',
85+
// duration: 3000,
86+
// offset: 30,
87+
// animationType: 'zoom-in',
88+
// });
89+
// }
90+
// console.log(e.message);
91+
// });
7592
}
7693
}
7794
return (

Screens/MailPage.js

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/* eslint-disable react/react-in-jsx-scope */
2-
/* eslint-disable react-native/no-inline-styles */
1+
32
import {
43
Image,
54
ScrollView,
@@ -16,6 +15,8 @@ import {useToast} from 'react-native-toast-notifications';
1615
import axios from 'axios';
1716
import ResultDisplay from '../Components/Global/ReaultDiaplay';
1817
import Apikey from '../Apikey';
18+
import {GetGeminiProResponse} from "../AiApi";
19+
import toast from "react-native-toast-notifications/src/toast";
1920

2021
export const MailPage = ({navigation}) => {
2122
const width = Dimensions.get('window').width;
@@ -51,46 +52,63 @@ export const MailPage = ({navigation}) => {
5152
animationType: 'zoom-in',
5253
});
5354
} else {
54-
setloading(true);
55-
let config = {
56-
method: 'post',
57-
maxBodyLength: Infinity,
58-
url:
59-
'https://generativelanguage.googleapis.com/v1beta2/models/chat-bison-001:generateMessage?key=' +
60-
Apikey,
61-
headers: {
62-
'Content-Type': 'application/json',
63-
},
64-
data: JSON.stringify({
65-
prompt: {
66-
messages: [
67-
{
68-
content: `compose an email from ${valueName} to ${valueTo} in subject of ${valueSubject} in a proper format`,
69-
},
70-
],
71-
},
72-
}),
73-
};
74-
axios
75-
.request(config)
76-
.then(r => {
77-
setemail(r.data.candidates[0].content);
78-
setloading(false);
79-
})
80-
.catch(e => {
81-
setloading(false);
82-
if (e.message === 'Network Error') {
83-
Toast.show('No Internet 😟', {
84-
type: 'danger',
85-
placement: 'top',
86-
duration: 2000,
87-
offset: 30,
88-
animationType: 'zoom-in',
89-
});
90-
return;
91-
}
92-
console.log(e.message);
93-
});
55+
setloading(true);
56+
try {
57+
const response = await GetGeminiProResponse([], `compose an email from ${valueName} to ${valueTo} in subject of ${valueSubject} in a proper format with no extra thing just the email`)
58+
setemail(response);
59+
}catch (e) {
60+
console.log(e)
61+
if (e.message === 'Network Error') {
62+
Toast.show('No Internet 😟', {
63+
type: 'danger',
64+
placement: 'top',
65+
duration: 3000,
66+
offset: 30,
67+
animationType: 'zoom-in',
68+
});
69+
}
70+
}
71+
setloading(false);
72+
// setloading(true);
73+
// let config = {
74+
// method: 'post',
75+
// maxBodyLength: Infinity,
76+
// url:
77+
// 'https://generativelanguage.googleapis.com/v1beta2/models/chat-bison-001:generateMessage?key=' +
78+
// Apikey,
79+
// headers: {
80+
// 'Content-Type': 'application/json',
81+
// },
82+
// data: JSON.stringify({
83+
// prompt: {
84+
// messages: [
85+
// {
86+
// content: `compose an email from ${valueName} to ${valueTo} in subject of ${valueSubject} in a proper format`,
87+
// },
88+
// ],
89+
// },
90+
// }),
91+
// };
92+
// axios
93+
// .request(config)
94+
// .then(r => {
95+
// setemail(r.data.candidates[0].content);
96+
// setloading(false);
97+
// })
98+
// .catch(e => {
99+
// setloading(false);
100+
// if (e.message === 'Network Error') {
101+
// Toast.show('No Internet 😟', {
102+
// type: 'danger',
103+
// placement: 'top',
104+
// duration: 2000,
105+
// offset: 30,
106+
// animationType: 'zoom-in',
107+
// });
108+
// return;
109+
// }
110+
// console.log(e.message);
111+
// });
94112
}
95113
}
96114
return (

0 commit comments

Comments
 (0)