alanchen1115 commited on
Commit
d7b5fcf
·
verified ·
1 Parent(s): e5d9d13

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +6 -5
main.py CHANGED
@@ -10,10 +10,6 @@ import PyPDF2
10
  # 設定 Google AI API 金鑰
11
  client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY"))
12
 
13
- # 設定生成文字的參數 + 角色扮演
14
- generation_config = genai.types.GenerateContentConfig(max_output_tokens=3000, temperature=0.1, top_p=0.2,
15
- system_instruction="您是一位問答助手。請僅限使用以上提供的內容來回答問題。如果您不知道答案,請說您不知道,不要捏造答案。")
16
-
17
  # Retrieve the PDF
18
  files = glob.glob('docs/*.pdf')
19
  pdf_content = ''
@@ -23,6 +19,11 @@ for filename in files:
23
  for i in range(len(pdf_reader.pages)):
24
  page = pdf_reader.pages[i]
25
  pdf_content+= page.extract_text()
 
 
 
 
 
26
 
27
  # 設定 Line Bot 的 API 金鑰和秘密金鑰
28
  line_bot_api = LineBotApi(os.environ["CHANNEL_ACCESS_TOKEN"])
@@ -97,7 +98,7 @@ def handle_message(event):
97
  # Combine the PDF contents and the new prompt into a single list for the 'contents' argument
98
  completion = client.models.generate_content(
99
  model="gemini-2.0-flash",
100
- contents=[pdf_content, prompt],
101
  config=generation_config).text
102
  # 檢查生成結果是否為空
103
  if (completion != None):
 
10
  # 設定 Google AI API 金鑰
11
  client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY"))
12
 
 
 
 
 
13
  # Retrieve the PDF
14
  files = glob.glob('docs/*.pdf')
15
  pdf_content = ''
 
19
  for i in range(len(pdf_reader.pages)):
20
  page = pdf_reader.pages[i]
21
  pdf_content+= page.extract_text()
22
+
23
+ # 設定生成文字的參數 + 角色扮演
24
+ generation_config = genai.types.GenerateContentConfig(max_output_tokens=3000, temperature=0.1, top_p=0.2,
25
+ system_instruction=pdf_content + "\n" +
26
+ "您是一位問答助手。請僅限使用以上提供的內容來回答問題。如果您不知道答案,請說您不知道,不要捏造答案。")
27
 
28
  # 設定 Line Bot 的 API 金鑰和秘密金鑰
29
  line_bot_api = LineBotApi(os.environ["CHANNEL_ACCESS_TOKEN"])
 
98
  # Combine the PDF contents and the new prompt into a single list for the 'contents' argument
99
  completion = client.models.generate_content(
100
  model="gemini-2.0-flash",
101
+ contents=prompt,
102
  config=generation_config).text
103
  # 檢查生成結果是否為空
104
  if (completion != None):