打开cloudflare的ai gateway页面
登录进去后创建一个gateway,名字自定义:我们以test为例
创建后生产一个gateway的地址url
gemini的访问uri是https://gateway.ai.cloudflare.com/v1/{你的用户uid}/{gateway名字}/google-ai-studio
我们写个python脚本测试一下
from google import genai from google.genai import types from PIL import Image from io import BytesIO import PIL.Image client = genai.Client( api_key="gemini的apikey", http_options=genai.types.HttpOptions( base_url="https://gateway.ai.cloudflare.com/v1/123dfsfdsfgd6/test/google-ai-studio" #这里换成你自己创建的gateway的url ) ) contents = ('Hi, can you create a 3d rendered image of a woman ' 'with wings and a top hat flying over a happy ' 'futuristic scifi city with lots of greenery?') response = client.models.generate_content( model="gemini-2.0-flash-preview-image-generation", contents=contents, config=types.GenerateContentConfig( response_modalities=['TEXT', 'IMAGE'] ) ) for part in response.candidates[0].content.parts: if part.text is not None: print(part.text) elif part.inline_data is not None: image = Image.open(BytesIO((part.inline_data.data))) image.save('gemini-native-image.png') image.show()
网友回复
腾讯混元模型广场里都是混元模型的垂直小模型,如何api调用?
为啥所有的照片分辨率提升工具都会修改照片上的图案细节?
js如何在浏览器中将webm视频的声音分离为单独音频?
微信小程序如何播放第三方域名url的mp4视频?
ai多模态大模型能实时识别视频中的手语为文字吗?
如何远程调试别人的chrome浏览器获取调试信息?
为啥js打开新网页window.open设置窗口宽高无效?
浏览器中js的navigator.mediaDevices.getDisplayMedia屏幕录像无法录制SpeechSynthesisUtterance产生的说话声音?
js中mediaRecorder如何录制window.speechSynthesis声音音频并下载?
python如何直接获取抖音短视频的音频文件url?