-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriting.py
More file actions
51 lines (39 loc) · 2.11 KB
/
Copy pathwriting.py
File metadata and controls
51 lines (39 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
"""writing.gAdjusted.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1CY47Crn5Kp6Wwsl783H1jLrjwlW4ZMIr
"""
# Block 01: 環境設置 (無需修改)
#!pip install -q -U google-generativeai
#!pip install pandas
import google.generativeai as genai
import os
import pandas as pd
import json
api_key = 'AIzaSyCzxTThllx9X_KSrGECc9_33QEE8DB45jw'
genai.configure(api_key=api_key)
model = genai.GenerativeModel('gemini-1.5-flash')
# BLOCK 02: 修正生成內容(以 prompt 為輸出)
def generate_writing_practice(previous_grade):
# 綜合寫作 (Integrated Writing)
list=[None,None,None]
prompt_reading = "根據TOEFL寫作測驗要求,生成一篇閱讀文章,主題為「環境保護」,文章不換行。"
prompt_listening = "根據TOEFL寫作測驗要求,生成一篇聽力記錄文章,主題為「環境保護」,文章不換行。"
reading_content = model.generate_content(prompt_reading).text.replace("\n", "").replace("\r", "")
listening_content = model.generate_content(prompt_listening).text.replace("\n", "").replace("\r", "")
list[0]=(f"Read the article and listen to the lecture. Write an essay summarizing the points made in the lecture and explaining how they challenge the points in the reading.\n{reading_content}")
list[1]=listening_content
# 學術討論 (Academic Discussion)
prompt_discussion = (
"根據TOEFL寫作學術討論要求,"
"生成一個情境對話,教授提出問題,"
"有兩名學生交換兩種不同看法,"
"請寫一篇至少一百字的回應。"
)
discussion_content = model.generate_content(prompt_discussion).text.replace("\n", "").replace("\r", "")
list[2]=(f"Read the professor's question and the two students' opinions. Write a response that adds your own perspective to the discussion. Be sure to support your ideas with examples and reasoning. Write at least 100 words.\n{discussion_content}")
# 返回生成的內容
return list
# 主程式呼叫生成內容
print(generate_writing_practice(0))