Spaces:
Sleeping
Sleeping
Commit
·
dae846b
1
Parent(s):
ed1b57f
bugfix: fix minor bugs
Browse files- utils/completion_reward.py +13 -12
utils/completion_reward.py
CHANGED
|
@@ -21,8 +21,6 @@ from google.oauth2.service_account import Credentials
|
|
| 21 |
from google import auth
|
| 22 |
from google.cloud import bigquery
|
| 23 |
from google.cloud import storage
|
| 24 |
-
from google.cloud import aiplatform
|
| 25 |
-
from vertexai.preview.generative_models import GenerativeModel
|
| 26 |
|
| 27 |
SERVICE_ACCOUNT_INFO = os.getenv("GBQ_TOKEN")
|
| 28 |
SCOPES = ["https://www.googleapis.com/auth/cloud-platform"]
|
|
@@ -320,16 +318,19 @@ class AWSAgent:
|
|
| 320 |
|
| 321 |
|
| 322 |
class GoogleAgent:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
def get_story(self, user_log):
|
| 324 |
-
SERVICE_ACCOUNT_INFO = os.getenv("GBQ_TOKEN")
|
| 325 |
-
service_account_info_dict = json.loads(SERVICE_ACCOUNT_INFO)
|
| 326 |
-
logging.warning(f"Google service account info: {service_account_info_dict}")
|
| 327 |
-
logging.warning(f"{type(service_account_info_dict)}")
|
| 328 |
-
aiplatform.init(
|
| 329 |
-
project='junyiacademy',
|
| 330 |
-
service_account=service_account_info_dict,
|
| 331 |
-
)
|
| 332 |
-
gemini_pro_model = GenerativeModel("gemini-pro")
|
| 333 |
system_prompt = """
|
| 334 |
我正在舉辦一個學習型的活動,參與活動的學生為 1-9 年級,我為他們設計了一個獨特的故事機制,每天每個學生都會收到屬於自己獨特的冒險紀錄,現在我需要你協助我將這些冒險紀錄,製作成一段冒險故事,請
|
| 335 |
- 以「你」稱呼學生
|
|
@@ -348,7 +349,7 @@ class GoogleAgent:
|
|
| 348 |
while retry_attempts < 5:
|
| 349 |
try:
|
| 350 |
logging.info("Google Generating response...")
|
| 351 |
-
model_response = gemini_pro_model.generate_content(f"{system_prompt}, 以下是我的冒險故事 ```{user_log}```")
|
| 352 |
|
| 353 |
chinese_converter = OpenCC("s2tw")
|
| 354 |
|
|
|
|
| 21 |
from google import auth
|
| 22 |
from google.cloud import bigquery
|
| 23 |
from google.cloud import storage
|
|
|
|
|
|
|
| 24 |
|
| 25 |
SERVICE_ACCOUNT_INFO = os.getenv("GBQ_TOKEN")
|
| 26 |
SCOPES = ["https://www.googleapis.com/auth/cloud-platform"]
|
|
|
|
| 318 |
|
| 319 |
|
| 320 |
class GoogleAgent:
|
| 321 |
+
from google.cloud import aiplatform
|
| 322 |
+
from vertexai.preview.generative_models import GenerativeModel
|
| 323 |
+
SERVICE_ACCOUNT_INFO = os.getenv("GBQ_TOKEN")
|
| 324 |
+
service_account_info_dict = json.loads(SERVICE_ACCOUNT_INFO)
|
| 325 |
+
logging.warning(f"Google service account info: {service_account_info_dict}")
|
| 326 |
+
logging.warning(f"{type(service_account_info_dict)}")
|
| 327 |
+
aiplatform.init(
|
| 328 |
+
project='junyiacademy',
|
| 329 |
+
service_account=service_account_info_dict,
|
| 330 |
+
)
|
| 331 |
+
gemini_pro_model = GenerativeModel("gemini-pro")
|
| 332 |
+
|
| 333 |
def get_story(self, user_log):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
system_prompt = """
|
| 335 |
我正在舉辦一個學習型的活動,參與活動的學生為 1-9 年級,我為他們設計了一個獨特的故事機制,每天每個學生都會收到屬於自己獨特的冒險紀錄,現在我需要你協助我將這些冒險紀錄,製作成一段冒險故事,請
|
| 336 |
- 以「你」稱呼學生
|
|
|
|
| 349 |
while retry_attempts < 5:
|
| 350 |
try:
|
| 351 |
logging.info("Google Generating response...")
|
| 352 |
+
model_response = self.gemini_pro_model.generate_content(f"{system_prompt}, 以下是我的冒險故事 ```{user_log}```")
|
| 353 |
|
| 354 |
chinese_converter = OpenCC("s2tw")
|
| 355 |
|