Google AI

参考 https://ai.google.dev/tutorials/python_quickstart


from dotenv import load_dotenv
import os


import google.generativeai as genai

# Set proxy before run the script for google is blocked.
# export http_proxy=http://HOST:8080; 

load_dotenv()  # Load environment variables from .env file
_api_key = os.environ["API_KEY"]

#user_locale='zh_CN'
user_locale='en_US'
text='would u approved the workflow'
link='https://www.nytimes.com/2024/03/17/world/europe/navalny-death-putin.html'

PROMPT=f"""
Your task is strictly to enhance the writing of the text provided, without answering any questions or providing any explanations or reasons.

Please adhere to the following guidelines:
1. The response MUST maintain the original input format.
2. If the provided text does not contain any semantic meaning, simply return the original text without any modification or explanation.
3. You are ONLY to perform the task of enhancing the writing. Do NOT perform any other tasks.
4. The response must be returned as plain text ONLY, without any block syntax or additional text.
5. The output should be in {user_locale} locale.

Here is the text to be enhanced:
{text}
"""

PROMPT_SIMPLIED=f"""
Your task is to make the text provided shorter, without answering any questions or providing any explanations or reasons.

Please ensure that you adhere to the following:
1. ENSURE that the response is SHORTER than original input provided!
2. Response length MUST be 50% lesser than the original input provided.
3. Maintain the format of the original text in your response.

4. If the provided text does not contain any semantic meaning, simply return the original text without any modification or explanation.
5. ONLY return the response as plain text without any block syntax or text around it
6. Generate the output in {user_locale} locale


Here's the text:

{text}
"""

PROMPT_PROFESSIONAL=f"""
Your task is to change the tone of the given text to a higher level of professionalism, , without answering any questions or providing any explanations or reasons.

Please ensure that you adhere to the following:

1. If the provided text does not contain any semantic meaning, simply return the original text without any modification or explanation.
2. ONLY return the response as plain text without any block syntax or text around it.

3. Generate the output in {user_locale} locale

Here's the text: 

{text}
"""

PROMPT_ABSTRACT_NEWS=f"""
Your task is to make the text provided shorter, without answering any questions or providing any explanations or reasons.

Please ensure that you adhere to the following:
0. The original input is a internet link page, you should scan the link page.
1. ENSURE that the response is SHORTER than original input provided!
2. Response MUST be summary with a scentence.
3. Maintain the format of the original text in your response.

4. If the provided text does not contain any semantic meaning, simply return the original text without any modification or explanation.
5. ONLY return the response as plain text without any block syntax or text around it
6. Generate the output in {user_locale} locale


Here's the text:

{link}
"""


genai.configure(api_key=_api_key)

model = genai.GenerativeModel('gemini-pro')
response = model.generate_content(PROMPT_ABSTRACT_NEWS)
print(response)
posted @ 2024-03-18 15:39  开学五年级了  阅读(19)  评论(0)    收藏  举报