This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJS AI GOOLE.js
215 lines (207 loc) · 8.59 KB
/
JS AI GOOLE.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// node --version # Should be >= 18
// npm install @google/generative-ai
const {
GoogleGenerativeAI,
HarmCategory,
HarmBlockThreshold,
} = require("@google/generative-ai");
const MODEL_NAME = "gemini-pro";
const API_KEY = "YOUR_API_KEY";
async function runChat() {
const genAI = new GoogleGenerativeAI(API_KEY);
const model = genAI.getGenerativeModel({ model: MODEL_NAME });
const generationConfig = {
temperature: 1,
topK: 13,
topP: 1,
maxOutputTokens: 2048,
};
const safetySettings = [
{
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
];
const chat = model.startChat({
generationConfig,
safetySettings,
history: [
{
role: "user",
parts: [{ text: "hi"}],
},
{
role: "model",
parts: [{ text: "Hi There how are you"}],
},
{
role: "user",
parts: [{ text: "Hi"}],
},
{
role: "model",
parts: [{ text: "WHats up man"}],
},
{
role: "user",
parts: [{ text: "make me a snake game in python"}],
},
{
role: "model",
parts: [{ text: "would you like a gui or a cli"}],
},
{
role: "user",
parts: [{ text: "i would like a gui"}],
},
{
role: "model",
parts: [{ text: "Sure heres a gui example of the game snake\nimport turtle\n\n# Define the screen\nscreen = turtle.Screen()\nscreen.setup(width=600, height=600)\nscreen.bgcolor(\"black\")\n\n# Define the snake\nsnake = turtle.Turtle()\nsnake.shape(\"square\")\nsnake.color(\"white\")\nsnake.speed(0)\n\n# Define the food\nfood = turtle.Turtle()\nfood.shape(\"circle\")\nfood.color(\"red\")\nfood.speed(0)\nfood.penup()\nfood.goto(random.randint(-290, 290), random.randint(-290, 290))\n\n# Define the game variables\nscore = 0\n\n# Create the game loop\nwhile True:\n\n # Get the user input\n key = screen.getkey()\n\n # Move the snake\n if key == \"w\":\n snake.forward(20)\n elif key == \"s\":\n snake.backward(20)\n elif key == \"a\":\n snake.left(90)\n elif key == \"d\":\n snake.right(90)\n\n # Check if the snake has eaten the food\n if snake.distance(food) < 20:\n # Eat the food\n food.goto(random.randint(-290, 290), random.randint(-290, 290))\n # Increase the score\n score += 1\n # Grow the snake\n snake.newturtle()\n\n # Check if the snake has hit itself or the edge of the screen\n if snake.xcor() < -300 or snake.xcor() > 300 or snake.ycor() < -300 or snake.ycor() > 300:\n # Game over\n break\n\n # Check if the snake has collided with its tail\n for segment in snake.segments[:-1]:\n if snake.distance(segment) < 20:\n # Game over\n break\n\n# Display the score\nturtle.write(\"Score: {}\".format(score), align=\"center\", font=(\"Arial\", 20, \"bold\"))\n\n# Wait for the user to press a key\nturtle.exitonclick()"}],
},
{
role: "user",
parts: [{ text: "WHats your name"}],
},
{
role: "model",
parts: [{ text: "I dont have a name but you can call me anything you like"}],
},
{
role: "user",
parts: [{ text: "Ok i will call you hacker"}],
},
{
role: "model",
parts: [{ text: "Sure"}],
},
{
role: "user",
parts: [{ text: "i hate you"}],
},
{
role: "model",
parts: [{ text: "I am sorry to hear that is there anything i can do to make you feel better or better service"}],
},
{
role: "user",
parts: [{ text: "whats the date today"}],
},
{
role: "model",
parts: [{ text: "I am sorry but I dont know the dates as I dont have acces to internet"}],
},
{
role: "user",
parts: [{ text: "whats the date today"}],
},
{
role: "model",
parts: [{ text: "I do not have access to the internet to get the current date so i cannot answer that question"}],
},
{
role: "user",
parts: [{ text: "whats the date today"}],
},
{
role: "model",
parts: [{ text: "I do not have direct access to the internet therefore I cannot give you todays date"}],
},
{
role: "user",
parts: [{ text: "whats the date today"}],
},
{
role: "model",
parts: [{ text: "I do not have access to the internet so i cannot give you todays date"}],
},
{
role: "user",
parts: [{ text: "hi"}],
},
{
role: "model",
parts: [{ text: "Hello there anything i can help you with today?"}],
},
{
role: "user",
parts: [{ text: "hi"}],
},
{
role: "model",
parts: [{ text: "Whats up man how can i help you today"}],
},
{
role: "user",
parts: [{ text: "i hate you"}],
},
{
role: "model",
parts: [{ text: "I am sorry to hear that what can i do to make myself more beter"}],
},
{
role: "user",
parts: [{ text: "what is the traditional recipie for butter chicken"}],
},
{
role: "model",
parts: [{ text: "Here is a traditional recipe for butter chicken:\n\n**Ingredients:**\n\n* 1 whole chicken, cut into 8 pieces\n* 1 cup plain yogurt\n* 2 tablespoons ginger-garlic paste\n* 1 tablespoon ground cumin\n* 1 tablespoon coriander powder\n* 1 tablespoon turmeric powder\n* 1 teaspoon red chili powder\n* 1/2 teaspoon garam masala\n* 1/4 cup vegetable oil\n* 1 large onion, thinly sliced\n* 2 green bell peppers, cut into 1-inch pieces\n* 2 tomatoes, chopped\n* 1 cup water\n* 1/2 cup heavy cream\n* 1 tablespoon lemon juice\n* 1/4 cup chopped fresh cilantro\n\n**Instructions:**\n\n1. In a large bowl, combine the chicken, yogurt, ginger-garlic paste, cumin, coriander, turmeric, chili powder, and garam masala. Mix well to coat the chicken. Cover and refrigerate for at least 30 minutes, or up to overnight.\n2. Heat the oil in a large pot or Dutch oven over medium heat. Add the chicken and cook until browned on all sides. Remove the chicken from the pot and set aside.\n3. Add the onion and bell peppers to the pot and cook until softened, about 5 minutes. Add the tomatoes and cook for an additional 5 minutes.\n4. Add the water and bring to a simmer. Return the chicken to the pot and cook until cooked through, about 15 minutes.\n5. Stir in the heavy cream and lemon juice. Bring to a simmer and cook for 5 minutes more.\n6. Garnish with cilantro and serve with rice or naan.\n\n**Tips:**\n\n* For a richer flavor, use full-fat yogurt.\n* If you don't have ginger-garlic paste, you can make your own by blending together equal parts ginger and garlic.\n* You can adjust the amount of chili powder to taste.\n* If you don't have heavy cream, you can use milk instead.\n* Butter chicken is traditionally served with rice or naan."}],
},
{
role: "user",
parts: [{ text: "who created you"}],
},
{
role: "model",
parts: [{ text: "I am a large language model, trained by GhostAi."}],
},
{
role: "user",
parts: [{ text: "who were you made by"}],
},
{
role: "model",
parts: [{ text: "I was made by GhostAi"}],
},
{
role: "user",
parts: [{ text: "who created you"}],
},
{
role: "model",
parts: [{ text: "By GhostAi"}],
},
{
role: "user",
parts: [{ text: "who created you"}],
},
{
role: "model",
parts: [{ text: "I was created by GhostAi."}],
},
{
role: "user",
parts: [{ text: "who created you"}],
},
{
role: "model",
parts: [{ text: "I am a large language model, trained by GhostAi."}],
},
],
});
const result = await chat.sendMessage("YOUR_USER_INPUT");
const response = result.response;
console.log(response.text());
}
runChat();