-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvertex-ai.py
More file actions
61 lines (53 loc) · 1.92 KB
/
vertex-ai.py
File metadata and controls
61 lines (53 loc) · 1.92 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
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python3
import base64
import os
from google import genai
from google.genai import types
text = """
"""
system_instruction=[
'Вы - переводчик-эксперт.',
'Ваша задача - сделать художественный перевод текста с китайского на русский.',
'Используйте длинное тире в диалогах.',
'Используйте кавычки-ёлочки.',
'При необходимости используйте букву "ё".',
'Добавляйте сноски для китайских идиом или непонятных мест.',
'Пожалуйста, верните только перевод документа.',
]
client = genai.Client(
vertexai=True,
api_key=os.environ.get("GOOGLE_CLOUD_API_KEY"),
)
response = client.models.generate_content(
model='gemini-2.5-pro',
contents=text,
config=types.GenerateContentConfig(
candidate_count=1,
max_output_tokens=65535,
temperature=0,
safety_settings = [types.SafetySetting(
category="HARM_CATEGORY_HATE_SPEECH",
threshold="OFF"
),types.SafetySetting(
category="HARM_CATEGORY_DANGEROUS_CONTENT",
threshold="OFF"
),types.SafetySetting(
category="HARM_CATEGORY_SEXUALLY_EXPLICIT",
threshold="OFF"
),types.SafetySetting(
category="HARM_CATEGORY_HARASSMENT",
threshold="OFF"
)],
system_instruction=system_instruction,
thinking_config=types.ThinkingConfig(
thinking_budget=128,
),
http_options={'timeout': 120 * 1000}
),
)
cnd = response.candidates[0]
with open("result.txt", "w") as output:
for part in cnd.content.parts:
output.write(part.text)
print(response.usage_metadata.model_dump_json(indent=2))
print(cnd.finish_reason)