Skip to content
This repository was archived by the owner on Apr 12, 2026. It is now read-only.

Commit 453b036

Browse files
authored
Merge pull request #233 from Daethyra/7.0.0
7.0.0 initial commit | PowerBot and Pagination - Repurposed archived Home page - updated Home body and reference links - added LangChain privacy policy link in README - created PowerBot - tools: get_weather, web_search, clock, calculate - uses Agentic memory and ReAct decision making thanks to LangChain's `create_agent` - added `google-search-results` to dependencies
2 parents 1ea4d8a + d324b78 commit 453b036

12 files changed

Lines changed: 470 additions & 95 deletions

File tree

.streamlit/template.secrets.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[DEEPSEEK]
22
DEEPSEEK_API_KEY = ""
33

4+
[SERPAPI]
5+
SERPAPI_KEY = ""
6+
47
[OPENAI]
58
openai_api_key = ""
69

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Streamlit Chatbots - Work in Progress
1919

2020
## Quickstart
2121

22-
This app is hosted via Streamlit Community Cloud, [here](https://freestream.streamlit.app/ "Current Version: 4.0.1")
22+
This app is hosted via Streamlit Community Cloud, [here](https://freestream.streamlit.app/ "Current Version: 7.0.0")
2323

2424
### Installation
2525

@@ -69,6 +69,7 @@ Just a freaking robot.
6969

7070
# LLM Providers' Privacy Policies
7171

72+
- [LangChain](https://www.langchain.com/privacy-policy)
7273
- [DeepSeek Privacy Policy](https://cdn.deepseek.com/policies/en-US/deepseek-privacy-policy.html)
7374
- [Streamlit](https://streamlit.io/privacy-policy/)
7475

freestream/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .pages.utils.styles import footer
1+
from .pages.utils.styles import footer

freestream/pages/.archive/🏡_Home.py

Lines changed: 0 additions & 89 deletions
This file was deleted.

freestream/pages/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@
77
set_bg_url,
88
set_bg_local,
99
save_conversation_history,
10+
format_weather_data,
11+
get_weather,
12+
web_search,
13+
clock,
14+
calculate,
1015
)

freestream/pages/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from .streamlit_operators import *
33
from .lc_premade import *
44
from .styles import *
5+
from .bot_tools import *
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import math
2+
import os
3+
from datetime import datetime
4+
5+
from langchain_core.tools import tool
6+
from serpapi import GoogleSearch
7+
8+
# First, create the output formatting function
9+
def format_weather_data(text_blocks):
10+
"""Format the weather data from text_blocks into a readable string"""
11+
formatted_text = ""
12+
13+
for block in text_blocks:
14+
if block["type"] == "paragraph":
15+
formatted_text += f"{block['snippet']}\n\n"
16+
elif block["type"] == "heading":
17+
formatted_text += f"--- {block['snippet']} ---\n"
18+
elif block["type"] == "list" and "list" in block:
19+
for item in block["list"]:
20+
formatted_text += f"• {item['snippet']}\n"
21+
formatted_text += "\n"
22+
23+
return formatted_text.strip()
24+
25+
# Define the tool using the langchain decorator
26+
@tool
27+
def get_weather(location: str) -> str:
28+
"""Get current weather information for a specific location.
29+
Example: "portland oregon", "new york", "london uk"
30+
"""
31+
try:
32+
params = {
33+
"engine": "google_ai_mode",
34+
"q": f"{location} weather",
35+
"api_key": os.environ["SERPAPI_KEY"],
36+
"location": "Portland, OR"
37+
}
38+
39+
search = GoogleSearch(params)
40+
results = search.get_dict()
41+
42+
if "text_blocks" in results and len(results["text_blocks"]) > 0:
43+
# Extract and format weather information from the text blocks
44+
weather_info = format_weather_data(results["text_blocks"])
45+
return f"Weather in {location}:\n{weather_info}"
46+
else:
47+
return f"Could not find weather information for {location}"
48+
49+
except Exception as e:
50+
return f"Error fetching weather data: {str(e)}"
51+
52+
@tool
53+
def web_search(query: str) -> str:
54+
"""Search the web using Google. Pass in the query you want to search. You can use anything that you would use in a regular Google search. e.g. inurl:, site:, intitle:.
55+
"""
56+
try:
57+
params = {
58+
"engine": "google_ai_mode",
59+
"q": f"{query}",
60+
"api_key": os.environ["SERPAPI_KEY"],
61+
"location": "Portland, OR"
62+
}
63+
64+
search = GoogleSearch(params)
65+
results = search.get_dict()
66+
67+
if "text_blocks" in results and len(results["text_blocks"]) > 0:
68+
# Extract and format weather information from the text blocks
69+
output = results["text_blocks"]
70+
return f"{query} results:\n{output}"
71+
else:
72+
return f"Could not find search Google for {query}"
73+
74+
except Exception as e:
75+
return f"Error fetching weather data: {str(e)}"
76+
77+
@tool
78+
def clock():
79+
"""Get the datetime. Returns datetime.now().strftime("%Y-%m-%d %I:%M %p")"""
80+
return datetime.now().strftime("%Y-%m-%d %I:%M %p")
81+
82+
@tool
83+
def calculate(expression: str) -> str:
84+
"""Evaluate a mathematical expression. You can use basic operators (+, -, *, /, ^) and functions like sqrt, sin, cos, etc.
85+
Example expressions:
86+
- "2 + 3 * 4"
87+
- "sqrt(16)"
88+
- "sin(30) + cos(60)"
89+
"""
90+
try:
91+
# Replace ^ with ** for exponentiation
92+
expression = expression.replace('^', '**')
93+
94+
# Add math functions to the evaluation context
95+
safe_dict = {
96+
'abs': abs, 'round': round, 'min': min, 'max': max,
97+
'sqrt': math.sqrt, 'sin': math.sin, 'cos': math.cos,
98+
'tan': math.tan, 'log': math.log, 'log10': math.log10,
99+
'pi': math.pi, 'e': math.e
100+
}
101+
102+
# Evaluate the expression safely
103+
result = eval(expression, {"__builtins__": None}, safe_dict)
104+
return f"The result of {expression} is {result}"
105+
except Exception as e:
106+
return f"Error evaluating expression: {str(e)}"

0 commit comments

Comments
 (0)