File size: 2,244 Bytes
b36a86c
 
 
 
 
 
 
 
 
 
0399d44
b36a86c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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"
# MODEL = "gpt-3.5-turbo-16k"
# %%


# This uses the Wikipedia Search API.
# Results from it are nondeterministic, your mileage will vary.
# def search(query):
#     """Search the internet."""
#     wiki_matches = wikipedia_search(query, n=3)
#     return {"context": ", ".join(wiki_matches), "titles": wiki_matches}


# def lookup(query):
#     """Lookup more information about a topic."""
#     page = wikipedia_search_lookup(query, sentences=3)
#     return page


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()
    # AIChat(character="Morgan Freeman")
    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"])

    # ai.reset_session()

# TODO: play music, create routines for spotify and/or amazon music; play videos on youtube (i know it will just be the audio)
#  use faster-whisper instead of the API
#  using llama.cpp https://github.com/minimaxir/simpleaichat/pull/52
# checkout swarms: https://github.com/kyegomez/swarms
# improve chat interface: https://www.gradio.app/guides/creating-a-custom-chatbot-with-blocks