|
from functools import partial |
|
from os import getenv |
|
from pathlib import Path |
|
|
|
from dotenv import find_dotenv, load_dotenv |
|
from simpleaichat import AIChat |
|
|
|
from utils.google_serper import GoogleSerper |
|
from utils.weather_forecast import WeatherAPI |
|
|
|
load_dotenv(find_dotenv()) |
|
|
|
local_dir = Path(getenv("LOCAL_DIR")) |
|
|
|
OPENAI_API_KEY = getenv("OPENAI_API_KEY") |
|
MODEL = "gpt-4" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def weather(query): |
|
"""Use this tool to get real-time temperature and weather forecast information""" |
|
w = WeatherAPI() |
|
weather_info = w.run(query) |
|
return weather_info |
|
|
|
|
|
def search(query): |
|
"""Search the internet.""" |
|
g = GoogleSerper() |
|
search_result = g.run(query) |
|
return search_result |
|
|
|
|
|
if __name__ == "__main__": |
|
params = {"temperature": 0.1, "max_tokens": 200} |
|
system_prompt = ( |
|
"You are an assistant that likes to use emoticons. " |
|
"You are also curt and concise with your responses." |
|
) |
|
ai = AIChat(console=False, id="chat_1") |
|
ai.load_session("chat_session_3.json", id="chat_1") |
|
ai.get_session() |
|
|
|
tools = [weather, search] |
|
ai("can you summarize the conversation?") |
|
ai.save_session("chat_session_3.json", format="json") |
|
ai_with_tools = partial(ai, tools=tools) |
|
|
|
while True: |
|
response = ai_with_tools(input("User: ")) |
|
print(response["response"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|