huchiahsi commited on
Commit
a299303
·
1 Parent(s): cf2cad8

add system instruction

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -1,16 +1,22 @@
1
  import os
2
  import gradio as gr
3
  from google import genai
 
4
 
5
  # 初始化 Gemini client
6
  api_key = os.getenv("GOOGLE_API_KEY")
7
  client = genai.Client(api_key=api_key)
8
- chat = client.chats.create(model="gemini-2.0-flash")
9
- system_prompt = "You are a helpful assistant and always respond in Traditional Chinese."
10
-
 
 
 
 
 
11
  # 回應函數(符合 type="messages" 的格式)
12
  def respond(message,history):
13
- response = chat.send_message(f"{system_prompt}:{message}")
14
  return response.text
15
 
16
  # Gradio Chat Interface
 
1
  import os
2
  import gradio as gr
3
  from google import genai
4
+ from google.genai import types
5
 
6
  # 初始化 Gemini client
7
  api_key = os.getenv("GOOGLE_API_KEY")
8
  client = genai.Client(api_key=api_key)
9
+ chat = client.chats.create(model="gemini-2.0-flash",
10
+ config=types.GenerateContentConfig(
11
+ system_instruction="You are a helpful assistant and always respond in Traditional Chinese.",
12
+ temperature=0.2,
13
+ max_output_tokens=256,
14
+ top_p=0.8,
15
+ top_k=40,
16
+ ),)
17
  # 回應函數(符合 type="messages" 的格式)
18
  def respond(message,history):
19
+ response = chat.send_message(message)
20
  return response.text
21
 
22
  # Gradio Chat Interface