WIP- Under maintenence- Web research working.

This commit is contained in:
AjaySi
2024-02-05 15:15:07 +05:30
parent fd7053fb4b
commit 2a3315f211
96 changed files with 4320 additions and 565 deletions

View File

@@ -17,10 +17,11 @@ from tenacity import (
@retry(wait=wait_random_exponential(min=1, max=60), stop=stop_after_attempt(6))
def gemini_arxiv_img_info(img_path):
def gemini_get_img_info(prompt, img_path):
""" Get image details from arxiv papers. """
logging.info(f"Get image details from Gemini Pro.")
try:
genai.configure(api_key=os.getenv("API_KEY"))
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
except Exception as e:
logging.error(f"Could not load gemini API key: {e}")
raise e
@@ -35,19 +36,19 @@ def gemini_arxiv_img_info(img_path):
safety_settings = [{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
"threshold": "BLOCK_NONE"
},]
try:
@@ -67,13 +68,12 @@ def gemini_arxiv_img_info(img_path):
"data": Path(img_path).read_bytes()
},]
prompt_parts = [
"As scholar on evaluating research papers, I will provide you with an image from a research paper. Your task is to explain the image in details so that I can use it in a blog article. Explain the key findings and conclusions from the image. Your description should be in simple terms to explain to a wider audience. Explain key findings from the given image.",
image_parts[0],]
prompt_parts = [f"{prompt}", image_parts[0],]
try:
response = model.generate_content(prompt_parts)
return response.text
except Exception as e:
logging.error(f"Could not generate gemini content: {e}")
logging.error(f"Gemini is blocking this request: {response.prompt_feedback.block_reason}")
logging.error(f"Gemini Vision, Failed to give image Details: {e}\n{response.prompt_feedback}")
raise e

View File

@@ -32,11 +32,9 @@ def gemini_text_response(prompt):
model = genai.GenerativeModel(model_name="gemini-pro", generation_config=generation_config)
try:
response = model.generate_content(prompt)
except Exception as err:
logger.error(f"Failed to get response from Gemini: {err}. Retrying.")
# Try with minstral.
print(f"\n\n\n--MINSTRAL--\n\n\n\n")
response = mistral_text_response(prompt)
return response
#response = mistral_text_response(prompt)
#return response
return response.text