Spaces:
Sleeping
Sleeping
first agent dummy version
Browse files- agent.py +24 -0
- app.py +2 -3
- requirements.txt +4 -1
agent.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
2 |
+
from langchain_core.messages import HumanMessage, SystemMessage
|
3 |
+
|
4 |
+
model = ChatGoogleGenerativeAI(model="gemini-2.5-flash", temperature=0)
|
5 |
+
|
6 |
+
system_template = "You are a general AI assistant. I will ask you a question. Your final answer should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string."
|
7 |
+
messages = [
|
8 |
+
SystemMessage(system_template),
|
9 |
+
HumanMessage("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."),
|
10 |
+
]
|
11 |
+
|
12 |
+
def invoke_agent(question: str) -> str:
|
13 |
+
"""
|
14 |
+
Invoke the agent with a given question.
|
15 |
+
"""
|
16 |
+
messages = [
|
17 |
+
SystemMessage(system_template),
|
18 |
+
HumanMessage(question),
|
19 |
+
]
|
20 |
+
response = model.invoke(messages)
|
21 |
+
return response.content
|
22 |
+
|
23 |
+
response = invoke_agent("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.")
|
24 |
+
print(response)
|
app.py
CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
|
|
6 |
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
@@ -14,9 +15,7 @@ class BasicAgent:
|
|
14 |
def __init__(self):
|
15 |
print("BasicAgent initialized.")
|
16 |
def __call__(self, question: str) -> str:
|
17 |
-
|
18 |
-
fixed_answer = "This is a default answer."
|
19 |
-
print(f"Agent returning fixed answer: {fixed_answer}")
|
20 |
return fixed_answer
|
21 |
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from agent import *
|
7 |
|
8 |
# (Keep Constants as is)
|
9 |
# --- Constants ---
|
|
|
15 |
def __init__(self):
|
16 |
print("BasicAgent initialized.")
|
17 |
def __call__(self, question: str) -> str:
|
18 |
+
fixed_answer = invoke_agent(question)
|
|
|
|
|
19 |
return fixed_answer
|
20 |
|
21 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
requirements.txt
CHANGED
@@ -1,2 +1,5 @@
|
|
1 |
gradio
|
2 |
-
requests
|
|
|
|
|
|
|
|
1 |
gradio
|
2 |
+
requests
|
3 |
+
langchain
|
4 |
+
langchain-community
|
5 |
+
langchain-google-genai
|