微调Gemini基础模型访问触发403权限错误,请求技术支持
问题描述
我微调了Gemini基础模型,编写Python代码尝试访问时,始终收到错误提示:
"PermissionDenied: 403 You do not have permission to access tuned model"
我已按说明配置OAuth 2.0 Client ID,验证环节成功,但请求仍无法正常执行。以下是运行的代码:
import os import gspread import google.generativeai as genai from load_creds import load_creds creds = load_creds() genai.configure(credentials=creds) # Configure the API key for the Google Generative AI genai.configure(api_key="My API key") # Configuration for text generation generation_config = { "temperature": 0.9, "top_p": 0.95, "top_k": 64, "max_output_tokens": 1024, "response_mime_type": "text/plain", } # Create a GenerativeModel instance model = genai.GenerativeModel( model_name="tunedModels/mytunedmodel", generation_config=generation_config, ) # Start a chat session chat_session = model.start_chat(enable_automatic_function_calling=True) # Send a message to the chat session including the file URI response = chat_session.send_message(f"Good morning") # Print the response print(response.text)
可能的解决方法
移除认证方式冲突:代码中同时调用了
genai.configure(credentials=creds)和genai.configure(api_key="My API key"),两种认证方式会互相干扰。访问微调模型仅需使用OAuth 2.0凭证,删除genai.configure(api_key="My API key")这一行。确认账号模型权限:登录Google AI Studio的微调模型管理页面,检查目标模型的共享设置,确保当前使用OAuth凭证的账号被添加为授权访问用户。
核对模型名称准确性:确认
model_name参数的格式和拼写完全正确,必须是tunedModels/[你的微调模型ID],注意大小写和特殊字符。检查OAuth权限范围:确保生成OAuth Client ID时,请求的权限范围包含
https://www.googleapis.com/auth/generative-language.tuning和https://www.googleapis.com/auth/generative-language,缺少必要范围会导致访问被拒。刷新OAuth凭证:如果使用的是缓存的旧凭证,可能存在权限未更新或过期的情况,重新生成并加载最新的OAuth凭证文件。
内容的提问来源于stack exchange,提问作者Jonathan Livingston Seagull

