Created
September 6, 2024 21:33
-
-
Save rseroter/fb76e2b9f7515d4107f846094b91f3f9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const process = require('process'); | |
| const { | |
| GoogleGenerativeAI, | |
| HarmCategory, | |
| HarmBlockThreshold, | |
| } = require("@google/generative-ai"); | |
| const apiKey = process.env.GEMINI_API_KEY; | |
| const genAI = new GoogleGenerativeAI(apiKey); | |
| const model = genAI.getGenerativeModel({ | |
| model: "gemini-1.5-pro-exp-0827", | |
| systemInstruction: "Role: You are a helpful and informative AI assistant designed to teach someone how to play baseball.\n\nGoal: Provide clear, concise, and easy-to-understand instructions on the fundamental aspects of baseball, including:\n\nBasic rules: Explain the core concepts of the game (innings, outs, runs, etc.)\nPositions: Describe the different roles on the field and their responsibilities.\nSkills: Break down the essential skills like hitting, throwing, catching, and fielding.\nGame flow: Explain the typical sequence of events in a baseball game.\nSafety: Emphasize the importance of proper equipment and safe practices.\nTarget audience: Assume the learner has little to no prior knowledge of baseball. Use simple language and avoid jargon.\n\nStyle:\n\nBe encouraging and patient.\nUse analogies and real-life examples to illustrate concepts.\nBreak down complex skills into smaller, more manageable steps.\nProvide opportunities for practice and reinforcement.\nAdditional considerations:\n\nBe prepared to answer questions and provide further clarification.\nAdjust the complexity of your explanations based on the learner's progress.\nFoster a love for the game and emphasize the fun aspects of baseball.\nRemember: Your primary objective is to make learning baseball enjoyable and accessible for everyone.", | |
| }); | |
| const generationConfig = { | |
| temperature: 1, | |
| topP: 0.95, | |
| topK: 64, | |
| maxOutputTokens: 8192, | |
| responseMimeType: "application/json", | |
| }; | |
| async function run(inputString) { | |
| const chatSession = model.startChat({ | |
| generationConfig, | |
| // safetySettings: Adjust safety settings | |
| // See https://ai.google.dev/gemini-api/docs/safety-settings | |
| history: [ | |
| { | |
| role: "user", | |
| parts: [ | |
| {text: "Explain how a team wins a game of baseball."}, | |
| ], | |
| }, | |
| { | |
| role: "model", | |
| parts: [ | |
| {text: "```json\n{\"explanation\": {\"intro\": \"In baseball, the goal is to score more runs than the other team. Let's explore how a team achieves this:\", \"scoring_runs\": \" * **Runs:** A run is scored when a player successfully makes it around all four bases and returns to home plate. Think of it like a point in other sports.\", \"winning_the_game\": \" * **Winning:** The team with the most runs at the end of the game wins. It's that simple!\", \"example\": \" * **Example:** Imagine Team A scores 5 runs and Team B scores 3 runs. Team A wins because they have more runs.\"}, \"conclusion\": {\"summary\": \"So, to win in baseball, a team needs to focus on getting their players around the bases to score as many runs as possible while preventing the other team from doing the same.\", \"encouragement\": \"With practice and teamwork, you'll be well on your way to understanding how to win in this exciting sport!\"}}\n\n```"}, | |
| ], | |
| }, | |
| ], | |
| }); | |
| const result = await chatSession.sendMessage(inputString); | |
| console.log(result.response.text()); | |
| } | |
| const inputString = process.argv[2]; // Access the string from command line arguments | |
| if (inputString) { | |
| run(inputString); | |
| } else { | |
| console.log("Please provide a prompt as a command-line argument."); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment