add system instruction
Browse files12345678910111213141516import osimport gradio as grfrom google import genai# 初始化 Gemini clientapi_key = os.getenv("GOOGLE_API_KEY")client = genai.Client(api_key=api_key)chat = client.chats.create(model="gemini-2.0-flash")system_prompt = "You are a helpful assistant and always respond in Traditional Chinese."# 回應函數(符合 type="messages" 的格式)def respond(message,history):response = chat.send_message(f"{system_prompt}:{message}")return response.text# Gradio Chat Interface12345678910111213141516171819202122import osimport gradio as grfrom google import genaifrom google.genai import types# 初始化 Gemini clientapi_key = os.getenv("GOOGLE_API_KEY")client = genai.Client(api_key=api_key)chat = client.chats.create(model="gemini-2.0-flash",config=types.GenerateContentConfig(system_instruction="You are a helpful assistant and always respond in Traditional Chinese.",temperature=0.2,max_output_tokens=256,top_p=0.8,top_k=40,),)# 回應函數(符合 type="messages" 的格式)def respond(message,history):response = chat.send_message(message)return response.text# Gradio Chat Interface
app.py+10-4