Spaces:
Sleeping
Sleeping
add system instruction
Browse files
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 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# 回應函數(符合 type="messages" 的格式)
|
| 12 |
def respond(message,history):
|
| 13 |
-
response = chat.send_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
|