WIP000.1- AI content writer
This commit is contained in:
@@ -1,47 +1,37 @@
|
||||
"""
|
||||
At the command line, only need to run once to install the package via pip:
|
||||
|
||||
$ pip install google-generativeai
|
||||
"""
|
||||
from .gpt_providers.gemini_pro_text import gemini_text_response
|
||||
|
||||
import google.generativeai as genai
|
||||
|
||||
genai.configure(api_key="YOUR_API_KEY")
|
||||
def gemini_get_code_samples(blog_article):
|
||||
""" Provide a programming blog and get code exmaples."""
|
||||
prompt = f"""As an expert programmer and copywriter, I will provide you with blog article.
|
||||
Your task is to research and write one code example for the given blog article.
|
||||
Do not include your explanations in response.
|
||||
Blog Article: '{blog_article}' """
|
||||
try:
|
||||
code_sample = gemini_text_response(prompt)
|
||||
response = combine_blog_code_sample(blog_article, code_sample)
|
||||
return response
|
||||
except Exception as err:
|
||||
raise ValueError(f"Failed to get response from Gemini pro: {err}")
|
||||
|
||||
# Set up the model
|
||||
generation_config = {
|
||||
"temperature": 1,
|
||||
"top_p": 1,
|
||||
"top_k": 1,
|
||||
"max_output_tokens": 2048,
|
||||
}
|
||||
|
||||
safety_settings = [
|
||||
{
|
||||
"category": "HARM_CATEGORY_HARASSMENT",
|
||||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_HATE_SPEECH",
|
||||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||||
},
|
||||
{
|
||||
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
||||
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
||||
}
|
||||
]
|
||||
def combine_blog_code_sample(blog_article, code_sample):
|
||||
""" Include the code sample into the given blog. """
|
||||
prompt = """You are expert document editor, I will provide you blog article and a code sample.
|
||||
Your task is to edit the given blog article to include the code sample after the introduction section.
|
||||
Do not modify the content of the given blog article. Your response should include the whole blog_article with
|
||||
the code sample added to it.
|
||||
Adopt the formatting of the given blog article. Do not include explanations of your response.
|
||||
Edit the given blog to include the code sample in it.
|
||||
Blog Article: {blog_article}\n
|
||||
Code sample: {code_sample}\n"""
|
||||
|
||||
model = genai.GenerativeModel(model_name="gemini-pro",
|
||||
generation_config=generation_config,
|
||||
safety_settings=safety_settings)
|
||||
|
||||
prompt_parts = [
|
||||
"As an expert programmer and web researcher, I will provide you with blog content. Your task is to understand the blog content and do web research around the main keywords. Check if the blog content is about programming then provide me with original code examples, relevant to the blog content. The provided code example should be of high coding standards, include docstring and follow pep8 standards. Do not provide explanations for your response.\nBlog content: \"\"\" {blog_content} \"\"\"\n ",
|
||||
]
|
||||
|
||||
response = model.generate_content(prompt_parts)
|
||||
print(response.text)
|
||||
try:
|
||||
response = gemini_text_response(prompt)
|
||||
return response
|
||||
except Exception as err:
|
||||
raise ValueError(f"Failed to combine blog and code: {err}")
|
||||
|
||||
Reference in New Issue
Block a user