浏览器中fetch请求gemini api流式输出示例代码
代码语言:html
所属分类:其他
代码描述:浏览器中fetch请求gemini api流式输出示例代码
代码标签: 浏览器 fetch 请求 gemini api 流式 输出 示例 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" /> <title>BFW NEW PAGE</title> </head> <body> <script type="module"> const API_KEY = "";//官网 const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:streamGenerateContent?alt=sse&key=`+API_KEY, { body: JSON.stringify({ "contents": [ { "role": "user", "parts": [ {"text":"hello"} ] } ], "generationConfig": { "maxOutputTokens": 8192, "temperature": 1, "topP": 0.95, }, "safetySettings": [ { "category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE" }, { "category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE" }, { "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE" }, { .........完整代码请登录后点击上方下载按钮下载查看
网友评论0