Spaces:
Sleeping
Sleeping
import constants | |
from langchain_google_genai import ChatGoogleGenerativeAI | |
from langchain_core.tools import tool | |
from langchain.agents import AgentExecutor, create_tool_calling_agent | |
from langchain_core.runnables import Runnable | |
from langchain_openai import ChatOpenAI | |
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder | |
from langchain_core.messages import SystemMessage | |
from wikipedia_tool import wikipedia_revision_by_year_keyword | |
from count_max_distinct_bird_species_tool import count_max_distinct_bird_species_in_video | |
from image_to_text_tool import image_to_text | |
from utils import get_bytes, get_text_file_contents, get_base64 | |
from internet_search_tool import internet_search | |
from botanical_classification_tool import get_botanical_classification | |
from excel_parser_tool import parse_excel | |
llm = ChatGoogleGenerativeAI( | |
model=constants.MODEL, | |
api_key=constants.API_KEY, | |
temperature=0.7) | |
tools = [ | |
wikipedia_revision_by_year_keyword, | |
count_max_distinct_bird_species_in_video, | |
image_to_text, | |
internet_search, | |
get_botanical_classification, | |
parse_excel | |
] | |
prompt = ChatPromptTemplate.from_messages([ | |
SystemMessage( | |
content=( | |
constants.PROMPT_LIMITADOR_LLM | |
) | |
), | |
MessagesPlaceholder(variable_name="chat_history"), | |
("human", "{input}"), | |
MessagesPlaceholder(variable_name="agent_scratchpad"), | |
]) | |
agent = create_tool_calling_agent(llm, tools, prompt=prompt) | |
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) | |
questoes = [ | |
'How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.', | |
'In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?', | |
'.rewsna eht sa \"tfel\" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI', # trivial - o modelo responde | |
'Review the chess position provided in the image. It is blacks turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.', | |
'Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?', | |
'Given this table defining * on the set S = {a, b, c, d, e}\n\n|*|a|b|c|d|e|\n|---|---|---|---|---|---|\n|a|a|b|c|b|d|\n|b|b|c|a|e|c|\n|c|c|a|b|b|a|\n|d|b|e|b|e|d|\n|e|d|b|a|d|c|\n\nprovide the subset of S involved in any possible counter-examples that prove * is not commutative. Provide your answer as a comma separated list of the elements in the set in alphabetical order.', | |
## questoes puladas | |
'What is the final numeric output from the attached Python code?', # trivial - o modelo responde | |
'How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?', | |
"What is the surname of the equine veterinarian mentioned in 1.E Exercises from the chemistry materials licensed by Marisa Alviar-Agnew & Henry Agnew under the CK-12 license in LibreText's Introductory Chemistry materials as compiled 08/21/2023?", | |
"I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far:\n\nmilk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts\n\nI need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list.", | |
"Hi, I'm making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I'm not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can't quite make out what she's saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I've attached the recipe as Strawberry pie.mp3.\n\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for \"a pinch of salt\" or \"two cups of ripe strawberries\" the ingredients on the list would be \"salt\" and \"ripe strawberries\".\n\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.", | |
"Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name.", | |
"What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?", | |
"What country had the least number of athletes at the 1928 Summer Olympics? If there's a tie for a number of athletes, return the first in alphabetical order. Give the IOC country code as your answer.", | |
"Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations. Look up the web.", | |
"The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.", | |
] | |
# CUB | |
# resposta esperada: "Final answer": "broccoli, celery, fresh basil, lettuce, sweet potatoes" | |
#"Final answer": "89706.00" | |
response = agent_executor.invoke({ | |
# "input": questoes[15], | |
"input": f"{questoes[15]} The relevant data is provided as a base64 encoded Excel file string. Here is the base64 string: {get_base64(r'C:\Users\agazo\Downloads\7bd855d8-463d-4ed5-93ca-5fe35145f733_file.xlsx')}", | |
"chat_history": [] | |
}) | |
print(response) | |