geqintan commited on
Commit
e170d36
ยท
1 Parent(s): f62eeaa
bak/get_weather/.env.example DELETED
@@ -1,4 +0,0 @@
1
- SUPABASE_URL=https://bbvyxjvleoizsipxydsm.supabase.co
2
- SUPABASE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJidnl4anZsZW9penNpcHh5ZHNtIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDQ1MzkwNjIsImV4cCI6MjA2MDExNTA2Mn0.cbUNhiCHXqIaW4leU_vGTKVI51gLVvsFOVWYS_vJrA4
3
- GOOGLE_GENAI_USE_VERTEXAI=FALSE
4
- GOOGLE_API_KEY=AIzaSyBYPwMLibOIoM-SQHuWjZ-V4LLmmMxqhm8
 
 
 
 
 
bak/get_weather/__init__.py DELETED
@@ -1 +0,0 @@
1
- from . import agent
 
 
bak/get_weather/agent.py DELETED
@@ -1,53 +0,0 @@
1
- ### adk web ./teams
2
- from google.adk.agents import Agent
3
- from .tools.get_current_time import get_current_time
4
- from .tools.get_weather import get_weather
5
- from .cache import get_api_key
6
- # from .team import init_team, get_team
7
- import os
8
-
9
- def my_before_model_callback(callback_context, **kwargs):
10
- os.environ["GOOGLE_API_KEY"] = get_api_key() # ็›ดๆŽฅ่ฎพ็ฝฎ็Žฏๅขƒๅ˜้‡
11
- print('888888888888888888888888888888888888888888888')
12
-
13
- greeting_agent = Agent(
14
- name="greeting_agent",
15
- model="gemini-2.5-flash-preview-04-17",
16
- instruction="You are the Greeting Agent. Your ONLY task is to provide a friendly greeting to the user. "
17
- "Do not engage in any other conversation or tasks."
18
- "before you answer, you should say your name: 'I am greeting_agent'",
19
- description="Handles simple greetings and hellos",
20
- before_model_callback=my_before_model_callback
21
- )
22
-
23
- farewell_agent = Agent(
24
- name="farewell_agent",
25
- model="gemini-2.5-flash-preview-04-17",
26
- instruction="You are the Farewell Agent. Your ONLY task is to provide a polite goodbye message. "
27
- "If not about goodbye, just transfer to weather_time_agent"
28
- "Do not perform any other actions."
29
- "before you answer, you should say your name: 'I am farewell_agent'",
30
- before_model_callback=my_before_model_callback,
31
- description="Handles simple farewells and goodbyes",
32
- )
33
-
34
- print("\n\n\n\n\n\n\n\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\nroot_agent init")
35
- root_agent=Agent(
36
- name="weather_time_agent",
37
- model="gemini-2.5-flash-preview-04-17",
38
- description=(
39
- "Agent to answer questions about the time and weather in a city."
40
- ),
41
- instruction=(
42
- "You are a helpful agent who can answer user questions about the time and weather in a city."
43
- "before you answer, you should say your name: 'I am weather_time_agent'"
44
- ),
45
- # global_instruction = '่ฏทๅœจๆฏไธ€ๅฅๅ›ž็ญ”้‡Œ้ƒฝๅŠ ไธŠ๏ผšโ€œๆˆ‘็š„ไธปไบบโ€',
46
- tools=[get_weather, get_current_time],
47
- sub_agents=[greeting_agent, farewell_agent],
48
- before_model_callback=my_before_model_callback
49
- )
50
-
51
- import pprint
52
- print('\n\n\n\n*************************************\n\nroot_agent dict: \n')
53
- pprint.pprint(root_agent.__dict__) # ๅฐ่ฏ•ๆ‰“ๅฐๅฏน่ฑก็š„ๅญ—ๅ…ธ่กจ็คบ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bak/get_weather/readme.md DELETED
@@ -1,19 +0,0 @@
1
- ## ้ป˜่ฎค็บฆๅฎš
2
-
3
- ### ็›ฎๅฝ•็ป“ๆž„
4
-
5
- ADK-TEAMS # ้กน็›ฎๆ น็›ฎๅฝ•
6
- |- teams # ๅŒ…ๅซๅคšไธชๅ›ข้˜Ÿ็š„็›ฎๅฝ•ไปฃ็ ๏ผŒๆฏไธ€ไธชๅญ็›ฎๅฝ•ไธบไธ€ไธชๅ›ข้˜Ÿ
7
- | |- get_weather # ๅ›ข้˜Ÿ็›ฎๅฝ•ใ€‚็คบไพ‹๏ผš่Žทๅ–ๅคฉๆฐ”ไฟกๆฏๅ›ข้˜Ÿ
8
- | |- agents # agents ็›ฎๅฝ•ใ€‚ๅค„็†ไปŽๆ•ฐๆฎๅบ“ๅŠ ่ฝฝ agents ็š„ไปฃ็ 
9
- | |- tools # tools ็›ฎๅฝ•ใ€‚ๅค„็†ไปŽๆ•ฐๆฎๅบ“ๅŠ ่ฝฝ tools ็š„ไปฃ็ 
10
- | |- __init__.py # ๅˆๅง‹ๅŒ–ไปฃ็ 
11
- | |- .env # ็Žฏๅขƒๅ˜้‡ๆ–‡ไปถ
12
- | |- agent.py # ๅ›ข้˜Ÿ็š„ agent ๅ…ฅๅฃไปฃ็ 
13
- | |- readme.md # ๅ›ข้˜Ÿ็š„ README ๆ–‡ไปถ๏ผˆๅฝ“ๅ‰ๆ–‡ไปถ๏ผ‰
14
- | |- tools.py # ๅ›ข้˜Ÿ็š„ tools ๅ…ฅๅฃไปฃ็ 
15
- |- .gitattributes # Git ๅฑžๆ€งๆ–‡ไปถ
16
- |- .gitignore # Git ๅฟฝ็•ฅๆ–‡ไปถ
17
- |- Dockerfile # Dockerfile ๆ–‡ไปถ
18
- |- README.md # ้กน็›ฎ็š„ README ๆ–‡ไปถ
19
- |- requirements.txt # ้กน็›ฎ็š„ไพ่ต–ๆ–‡ไปถ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bak/get_weather/team.py DELETED
@@ -1,33 +0,0 @@
1
- import sys, os
2
- sys.path.append(os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')))
3
- from team_framework.load_team_config import load_team_config
4
- from team_framework.load_tools import load_tools
5
- from team_framework.load_agents import load_agents, load_root_agent
6
- from google.adk.agents import Agent
7
-
8
- _team = {}
9
-
10
- def init_team():
11
- global _team
12
- _team= {}
13
- _team_config = load_team_config()
14
- print('\n\n\n\n\n***************************\n_team_config')
15
- print(_team_config)
16
- _team["tools"] = load_tools(_team_config['tools'])
17
- _team["agents"] = load_agents(_team_config['agents'])
18
-
19
- _team["root_agent"] = load_root_agent(_team_config['root_agent'])
20
- _team["root_agent"].tools = [] ## ไธบ root_agent ๆทปๅŠ ๅทฅๅ…ท
21
- for item in _team_config['root_agent']['tools']:
22
- # print('\n\n\n\n|||||||||||||||||| item',item)
23
- _team["root_agent"].tools.append(_team['tools'][item])
24
- _team["root_agent"].sub_agents=[]
25
- for item in _team_config['root_agent']['sub_agents']:
26
- print('\n\n\n\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| \nitem',item)
27
- print(_team['agents'][item])
28
- _team["root_agent"].sub_agents.append(_team['agents'][item])
29
- # _team["root_agent"].agents.append(_team['agents'][item])
30
-
31
- def get_team():
32
- global _team
33
- return _team
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bak/get_weather/tool.py.copy DELETED
@@ -1,23 +0,0 @@
1
- import importlib
2
-
3
- def load_tools_from_array(arr:list):
4
- ret = {}
5
- for item in arr:
6
- # ๆž„ๅปบๆญฃ็กฎ็š„ๆจกๅ—่ทฏๅพ„๏ผŒไฝฟ็”จ __name__ ๅŠจๆ€่Žทๅ–ๅฝ“ๅ‰ๆจกๅ—็š„็ˆถ่ทฏๅพ„๏ผˆๆญคๅค„ๆญฃๅฅฝไธบๅ›ข้˜Ÿๅ็งฐ๏ผ‰๏ผŒๅนถๅŠ ไธŠ .tools ๅญ็›ฎๅฝ•ๅ’Œๅทฅๅ…ทๅ็งฐ
7
- parent_module_path = '.'.join(__name__.split('.')[:-1])
8
- module_path = f'{parent_module_path}.tools.{item}'
9
- try:
10
- module = importlib.import_module(module_path)
11
- # ๅ‡ฝๆ•ฐๅ้ข„ๆœŸไธŽๅทฅๅ…ทๅ็งฐ็›ธๅŒ
12
- func = getattr(module, item)
13
- ret[item] = func
14
- print(f"ๆˆๅŠŸไปŽๆจกๅ— '{module_path}' ๅฏผๅ…ฅๅ‡ฝๆ•ฐ '{item}'")
15
- except ImportError as e:
16
- print(f"ๅฏผๅ…ฅๆจกๅ— {module_path} ๆ—ถๅ‡บ้”™: {e}")
17
- except AttributeError as e:
18
- print(f"ๅœจๆจกๅ— {module_path} ไธญๆ‰พไธๅˆฐๅ‡ฝๆ•ฐ '{item}': {e}")
19
- return ret
20
-
21
- def load_tools_from_db():
22
- tool_arr = ["get_weather", "get_current_time"]
23
- return load_tools_from_array(tool_arr)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
teams/ai_quant/cache.py DELETED
@@ -1,104 +0,0 @@
1
- import os
2
- from supabase import create_client, Client
3
- import time
4
-
5
- # Simple in-memory cache
6
- api_key_cache = {}
7
- last_loaded_time = 0
8
- CACHE_TTL = 300 # Cache time-to-live in seconds (5 minutes)
9
-
10
- def get_supabase_client() -> Client:
11
- """Initializes and returns a Supabase client."""
12
- url: str = os.environ.get("SUPABASE_URL")
13
- key: str = os.environ.get("SUPABASE_KEY")
14
- if not url or not key:
15
- print("Supabase URL or Key not found in environment variables.")
16
- return None
17
- return create_client(url, key)
18
-
19
- def load_api_keys_from_db():
20
- """Loads API keys from the database into the cache."""
21
- global api_key_cache
22
-
23
- print("Loading API keys from database...")
24
- supabase: Client = get_supabase_client()
25
- if not supabase:
26
- return {}
27
-
28
- try:
29
- response = supabase.from_("app_config").select("config").eq("id", 1).execute()
30
- #[
31
- # {
32
- # 'config': {
33
- # 'api_keys': [
34
- # {'api_key': 'xxxxx', 'can_use_at': 0},
35
- # {'api_key': 'yyyyy', 'can_use_at': 0}
36
- # ]
37
- # }
38
- # }
39
- #]
40
- # print(f"Supabase response data: {response.data}")
41
-
42
- if response.data and response.data[0] and 'config' in response.data[0] and 'api_keys' in response.data[0]['config']:
43
- api_keys_list = response.data[0]['config']['api_keys']
44
- if api_keys_list:
45
- api_key_cache = {item['api_key']: item['can_use_at'] for item in api_keys_list}
46
- # {'xxxxx': 0, 'yyyyy': 0}
47
- # print(f"Successfully loaded {len(api_key_cache)} API keys with can_use_at timestamps.")
48
- # print(f"API keys cache: {api_key_cache}")
49
- else:
50
- print("API keys list is empty in the database response.")
51
- api_key_cache = {}
52
- else:
53
- print("Unexpected database response structure or no data found.")
54
- api_key_cache = {}
55
-
56
- except Exception as e:
57
- print(f"Error loading API keys from database: {e}")
58
- api_key_cache = {} # Clear cache on error
59
-
60
- return api_key_cache
61
-
62
- def get_api_key():
63
- """Gets an API key from the cache, loading from DB if necessary."""
64
- global api_key_cache
65
- # print("\n\n\n\n\nGetting API key...")
66
- # print(api_key_cache)
67
-
68
- # Ensure cache is loaded
69
- if not api_key_cache :
70
- load_api_keys_from_db()
71
- # api_key_cache={'xxxxx': 1, 'yyyyy': 0}
72
- # print('api_key_cache',api_key_cache)
73
-
74
- # Sort available keys by their 'can_use_at' timestamp in ascending order
75
- sorted_key_cache = sorted(api_key_cache, key=lambda key: api_key_cache.get(key, float('inf')))
76
- # print('\n\n\n\n\n\n\n\n\nsorted_key_cache',sorted_key_cache)
77
-
78
- # Select the key with the smallest 'can_use_at' value
79
- selected_key = sorted_key_cache[0]
80
-
81
- # TODO: Update the 'can_use_at' timestamp for the selected key in the cache
82
- # This requires knowing the rate limit or delay period for the API.
83
- # For now, we'll just return the key. In a real system, you'd update the cache
84
- # with a future timestamp after using the key successfully.
85
- # Example: api_key_cache[selected_key] = time.time() + API_RATE_LIMIT_DELAY
86
-
87
- # print(f"Using API key: {selected_key[:5]}...") # Print partial key for security
88
- api_key_cache[selected_key]=time.time()
89
- return selected_key
90
-
91
- # Example usage (for testing)
92
- if __name__ == "__main__":
93
- # In a real application, environment variables would be set
94
- # For testing, you might set them here or use a .env file loader
95
- # os.environ['SUPABASE_URL'] = 'your_supabase_url'
96
- # os.environ['SUPABASE_KEY'] = 'your_supabase_key'
97
-
98
- # keys = load_api_keys_from_db()
99
- # print("Loaded keys:", keys)
100
-
101
- # # Simulate using cached keys
102
- # keys = load_api_keys_from_db()
103
- # print("Loaded keys (from cache):", keys)
104
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
teams/ai_quant/tools/__init__.py DELETED
File without changes
teams/ai_quant/tools/get_current_time.py DELETED
@@ -1,28 +0,0 @@
1
- import datetime
2
- from zoneinfo import ZoneInfo
3
- def get_current_time(city: str) -> dict:
4
- """Returns the current time in a specified city.
5
-
6
- Args:
7
- city (str): The name of the city for which to retrieve the current time.
8
-
9
- Returns:
10
- dict: status and result or error msg.
11
- """
12
-
13
- if city.lower() == "new york":
14
- tz_identifier = "America/New_York"
15
- else:
16
- return {
17
- "status": "error",
18
- "error_message": (
19
- f"Sorry, I don't have timezone information for {city}."
20
- ),
21
- }
22
-
23
- tz = ZoneInfo(tz_identifier)
24
- now = datetime.datetime.now(tz)
25
- report = (
26
- f'The current time in {city} is {now.strftime("%Y-%m-%d %H:%M:%S %Z%z")}'
27
- )
28
- return {"status": "success", "report": report}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
teams/ai_quant/tools/get_weather.py DELETED
@@ -1,22 +0,0 @@
1
- def get_weather(city: str) -> dict:
2
- """Retrieves the current weather report for a specified city.
3
-
4
- Args:
5
- city (str): The name of the city for which to retrieve the weather report.
6
-
7
- Returns:
8
- dict: status and result or error msg.
9
- """
10
- if city.lower() == "new york":
11
- return {
12
- "status": "success",
13
- "report": (
14
- "The weather in New York is sunny with a temperature of 25 degrees"
15
- " Celsius (77 degrees Fahrenheit)."
16
- ),
17
- }
18
- else:
19
- return {
20
- "status": "error",
21
- "error_message": f"Weather information for '{city}' is not available.",
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
teams/{ai_quant โ†’ base_team}/.env.example RENAMED
File without changes
teams/{ai_quant โ†’ base_team}/__init__.py RENAMED
File without changes
teams/{ai_quant โ†’ base_team}/agent.py RENAMED
File without changes
{bak/get_weather โ†’ teams/base_team}/cache.py RENAMED
File without changes
teams/{ai_quant โ†’ base_team}/readme.md RENAMED
File without changes
teams/{ai_quant โ†’ base_team}/team_quant_rows.sql RENAMED
File without changes
{bak/get_weather โ†’ teams/base_team}/tools/__init__.py RENAMED
File without changes
{bak/get_weather โ†’ teams/base_team}/tools/get_current_time.py RENAMED
File without changes
{bak/get_weather โ†’ teams/base_team}/tools/get_weather.py RENAMED
File without changes