“ 暂时免费使用,如下图,抓紧白嫖把
https://blog.google/technology/ai/gemini-api-developers-cloud/
如果只是测试,可以用本文提供的这个小工具,如下图,点击1对应的地址可以跳转到申请key的地方。 当然你可以直接访问下链接。
https://makersuite.google.com/app/apikey
申请了key,可以自己用curl请求,也可以粘贴到工具里
工具源码,复制到记事本里,另存为.html ,双击浏览器打开即可
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gemini demo</title>
</head>
<body>
<div style="display: flex; gap: 0.25rem; padding: 0.5rem;">
<div style="display: flex; flex-direction: column; gap: 0.25rem;">
<h3 style="margin: 0;">How to use:</h3>
<ol style="margin-top:0">
<li>申请AK: <a href="https://makersuite.google.com/app/apikey" style="color: #3b82f6;">Google AI Suite</a> </li>
<li>复制到下面第一个文本框</li>
<li>在下面 <b style="font-weight: bold;">文本框</b>输入提示词</li>
<li>点击 <b style="font-weight: bold;">generate</b></li>
</ol>
<input type="text" placeholder="Paste API key here" id="apiKeyInput" style="border: 1px solid; padding: 0.125rem; border-radius: 0.125rem;"></input>
<textarea placeholder="Prompt goes here" id="inputText" style="margin-top: 0.125rem; padding: 0.125rem; border: 1px solid; border-radius: 0.125rem;"></textarea>
<button id="generate" style="margin-top: 0.125rem; background-color: #3b82f6; color: white; padding: 0.125rem; border-radius: 0.125rem;">Generate</button>
</div>
<div id="resultText" style="white-space: pre-line; margin-left: auto; margin-right:auto; width: 32rem; ">Result will be here</div>
</div>
<script type="importmap">
{
"imports": {
"@google/generative-ai": "https://esm.run/@google/generative-ai"
}
}
</script>
<script type="module">
import { GoogleGenerativeAI } from "@google/generative-ai";
import { HarmBlockThreshold, HarmCategory } from "@google/generative-ai";
// ...
const inputText = document.querySelector("#inputText");
const resultText = document.querySelector("#resultText");
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 generationConfig = {
maxOutputTokens: 16000,
temperature: 0.9
};
async function run() {
resultText.innerHTML = '';
// Access your API key (see "Set up your API key" above)
const API_KEY = document.querySelector("#apiKeyInput");
const genAI = new GoogleGenerativeAI(API_KEY.value);
// For text-only input, use the gemini-pro model
const model = genAI.getGenerativeModel({ model: "gemini-pro", generationConfig, safetySettings });
const prompt = inputText.value;
const result = await model.generateContentStream(prompt);
for await (const chunk of result.stream) {
const chunkText = chunk.text();
resultText.innerHTML += chunkText;
}
}
// Call the run function when the generate button is clicked
const generateButton = document.querySelector("#generate");
generateButton.addEventListener("click", run);
// ...
</script>
</body>
</html>