-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grzegorz Tańczyk
committed
Jul 9, 2024
1 parent
a292d5a
commit 0bbe390
Showing
6 changed files
with
85 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,9 @@ | ||
# React + TypeScript + Vite | ||
# Nukes | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
This is a simple React application that simulates a nuclear war game. | ||
|
||
Currently, two official plugins are available: | ||
To run the game locally: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
export default { | ||
// other rules... | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
project: ['./tsconfig.json', './tsconfig.node.json'], | ||
tsconfigRootDir: __dirname, | ||
}, | ||
} | ||
``` | ||
|
||
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` | ||
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list | ||
1. Install Node.js | ||
2. Install dependencies: `npm i` | ||
3. Run the development server: `npm run dev` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { VertexAI } from '@google-cloud/vertexai'; | ||
|
||
// A function to generate content using the generative model | ||
export async function generateContent(systemPrompt, prompt) { | ||
const req = { | ||
contents: [ | ||
{ | ||
role: 'user', | ||
parts: [ | ||
{ | ||
text: prompt, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
const result = await getGenModel(systemPrompt).generateContent(req); | ||
|
||
return result.response.candidates[0].content.parts[0].text; | ||
} | ||
|
||
// A function to get the generative model | ||
export function getGenModel(systemPrompt) { | ||
// Initialize Vertex with your Cloud project and location | ||
const vertex_ai = new VertexAI({ project: 'gamedevpl', location: 'us-central1' }); | ||
const model = 'gemini-1.5-pro-001'; | ||
|
||
// Instantiate the models | ||
return vertex_ai.preview.getGenerativeModel({ | ||
model: model, | ||
generationConfig: { | ||
maxOutputTokens: 8192, | ||
temperature: 1, | ||
topP: 0.95, | ||
}, | ||
safetySettings: [ | ||
{ | ||
category: 'HARM_CATEGORY_HATE_SPEECH', | ||
threshold: 'BLOCK_ONLY_HIGH', | ||
}, | ||
{ | ||
category: 'HARM_CATEGORY_DANGEROUS_CONTENT', | ||
threshold: 'BLOCK_ONLY_HIGH', | ||
}, | ||
{ | ||
category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', | ||
threshold: 'BLOCK_ONLY_HIGH', | ||
}, | ||
{ | ||
category: 'HARM_CATEGORY_HARASSMENT', | ||
threshold: 'BLOCK_ONLY_HIGH', | ||
}, | ||
], | ||
systemInstruction: { | ||
role: 'system', | ||
parts: [ | ||
{ | ||
text: systemPrompt, | ||
}, | ||
], | ||
}, | ||
}); | ||
} |