Skip to content

Commit

Permalink
Use gpt-4 by default for the main thought process
Browse files Browse the repository at this point in the history
Allow specifying the llm through dotenv
Move more things into config
  • Loading branch information
Taytay committed Apr 3, 2023
1 parent 3e587bc commit 80ccd10
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
OPENAI_API_KEY=your-openai-api-key
ELEVENLABS_API_KEY=your-elevenlabs-api-key
SMART_LLM_MODEL="gpt-4"
FAST_LLM_MODEL="gpt-3.5-turbo"
2 changes: 0 additions & 2 deletions scripts/call_ai_function.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import List, Optional
import json
import openai
import dirtyjson
from config import Config
cfg = Config()

Expand Down
11 changes: 4 additions & 7 deletions scripts/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
import time
import openai
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

# Initialize the OpenAI API client
openai.api_key = os.getenv("OPENAI_API_KEY")
from config import Config
cfg = Config()


def create_chat_message(role, content):
Expand Down Expand Up @@ -65,8 +61,9 @@ def chat_with_ai(
f"{message['role'].capitalize()}: {message['content']}")
print("----------- END OF CONTEXT ----------------")

# TODO: use a model defined elsewhere, so that model can contain temperature and other settings we care about
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",#model="gpt-4",
model=cfg.smart_llm_model,
messages=current_context,
)

Expand Down
35 changes: 33 additions & 2 deletions scripts/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import os

from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()

class Singleton(type):
"""
Singleton metaclass for ensuring only one instance of a class.
Expand All @@ -21,9 +27,25 @@ class Config(metaclass=Singleton):
def __init__(self):
self.continuous_mode = False
self.speak_mode = False
self.fast_llm_model = "gpt-3.5-turbo"
self.smart_llm_model = "gpt-3.5-turbo"
# TODO - make these models be self-contained, using langchain, so we can configure them once and call it good
self.fast_llm_model = os.getenv("FAST_LLM_MODEL", "gpt-3.5-turbo")
self.smart_llm_model = os.getenv("SMART_LLM_MODEL", "gpt-4")
self.thinking_token_limit = 4000
# Initialize the OpenAI API client
self.openai_api_key = os.getenv("OPENAI_API_KEY")
self.elevenlabs_api_key = os.getenv("ELEVENLABS_API_KEY")
# Print values:
print("Config values:")
print(f"continuous_mode: {self.continuous_mode}")
print(f"speak_mode: {self.speak_mode}")
print(f"fast_llm_model: {self.fast_llm_model}")
print(f"smart_llm_model: {self.smart_llm_model}")
print(f"thinking_token_limit: {self.thinking_token_limit}")
print(f"openai_api_key: {self.openai_api_key}")
print(f"elevenlabs_api_key: {self.elevenlabs_api_key}")




def set_continuous_mode(self, value: bool):
self.continuous_mode = value
Expand All @@ -39,3 +61,12 @@ def set_smart_llm_model(self, value: str):

def set_thinking_token_limit(self, value: int):
self.thinking_token_limit = value

def set_openai_api_key(self, value: str):
self.apiopenai_api_key_key = value

def set_elevenlabs_api_key(self, value: str):
self.elevenlabs_api_key = value



10 changes: 9 additions & 1 deletion scripts/data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import os
from pathlib import Path


def load_prompt():
try:
# get directory of this file:
file_dir = Path(os.path.dirname(os.path.realpath(__file__)))
data_dir = file_dir / "data"
prompt_file = data_dir / "prompt.txt"
# Load the promt from data/prompt.txt
with open("data/prompt.txt", "r") as prompt_file:
with open(prompt_file, "r") as prompt_file:
prompt = prompt_file.read()

return prompt
Expand Down
13 changes: 4 additions & 9 deletions scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@
from enum import Enum, auto
import sys
from config import Config
from dotenv import load_dotenv
from json_parser import fix_and_parse_json
from ai_config import AIConfig
import traceback
import yaml


# Load environment variables from .env file
load_dotenv()


class Argument(Enum):
CONTINUOUS_MODE = "continuous-mode"
SPEAK_MODE = "speak-mode"
Expand Down Expand Up @@ -262,11 +256,12 @@ def parse_arguments():
print_to_console("Speak Mode: ", Fore.GREEN, "ENABLED")
cfg.set_speak_mode(True)

# TODO: Better argument parsing:
# TODO: fill in llm values here

cfg = Config()

# TODO: Better argument parsing:
# TODO: fill in llm values here

cfg = Config()
parse_arguments()
ai_name = ""
prompt = construct_prompt()
Expand Down
11 changes: 4 additions & 7 deletions scripts/speak.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import os
from playsound import playsound
import requests
from dotenv import load_dotenv


# Load environment variables from .env file
load_dotenv()
from config import Config
cfg = Config()

# TODO: Nicer names for these ids
voices = ["ErXwobaYiN019PkySvjV", "EXAVITQu4vr4xnSDxMaL"]

tts_headers = {
"Content-Type": "application/json",
"xi-api-key": os.getenv("ELEVENLABS_API_KEY")
"xi-api-key": cfg.elevenlabs_api_key
}


def say_text(text, voice_index=0):
tts_url = "https://api.elevenlabs.io/v1/text-to-speech/{voice_id}".format(
voice_id=voices[voice_index])
Expand Down

0 comments on commit 80ccd10

Please sign in to comment.