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

Commit 6d03446

Browse files
committed
Add personality selection to AICodeBot setup
This commit introduces a new feature to the AICodeBot setup process. Now, users can select a personality for their AI assistant from a predefined list. The chosen personality is stored in the configuration file and used to generate the AI's responses. This change also includes a refactoring of the personality prompts, moving them into a dictionary for easier access and management. Ain't no half-steppin' here, we're making this bot a real cool cat.
1 parent 7f0e817 commit 6d03446

2 files changed

Lines changed: 36 additions & 20 deletions

File tree

aicodebot/cli.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
logger,
99
read_config,
1010
)
11-
from aicodebot.prompts import generate_files_context, get_prompt
11+
from aicodebot.prompts import PERSONALITIES, generate_files_context, get_prompt
1212
from langchain.callbacks.base import BaseCallbackHandler
1313
from langchain.chains import LLMChain
1414
from langchain.chat_models import ChatOpenAI
@@ -404,8 +404,6 @@ def setup_config(openai_api_key=None, gpt_4_supported=None):
404404
logger.info("Using OPENAI_API_KEY environment variable")
405405
openai.api_key = os.getenv("OPENAI_API_KEY")
406406

407-
logger.info(f"openai.api_key {openai.api_key}")
408-
409407
config_file = get_config_file()
410408
console.print(f"[bold red]The config file does not exist.[/bold red]\nLet's set that up for you at {config_file}\n")
411409

@@ -421,7 +419,6 @@ def setup_config(openai_api_key=None, gpt_4_supported=None):
421419

422420
openai.api_key = click.prompt("Please enter your OpenAI API key")
423421

424-
logger.info(f"openai.api_key 2 {openai.api_key}")
425422
# Validate the API key and check if it supports GPT-4
426423
if gpt_4_supported is None:
427424
try:
@@ -436,9 +433,22 @@ def setup_config(openai_api_key=None, gpt_4_supported=None):
436433
except Exception as e:
437434
raise click.ClickException(f"Failed to validate the API key: {str(e)}") from e
438435

439-
config_data = {"config_version": 1, "OPENAI_API_KEY": openai.api_key, "gpt_4_supported": gpt_4_supported}
436+
# Pull the choices from the name from each of the PERSONALITIES
437+
personality_choices = "\nHow would you like your AI to act? You can choose from the following personalities:\n"
438+
for key, personality in PERSONALITIES.items():
439+
personality_choices += f"\t{key} - {personality.description}\n"
440+
console.print(personality_choices)
441+
442+
personality = click.prompt(
443+
"Please choose a personality", type=click.Choice(PERSONALITIES.keys(), case_sensitive=False)
444+
)
440445

441-
logger.info(f"openai.api_key 3 {openai.api_key}")
446+
config_data = {
447+
"config_version": 1,
448+
"OPENAI_API_KEY": openai.api_key,
449+
"gpt_4_supported": gpt_4_supported,
450+
"personality": personality,
451+
}
442452

443453
with Path.open(config_file, "w") as f:
444454
yaml.dump(config_data, f)

aicodebot/prompts.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from aicodebot.helpers import get_token_length, logger
1+
from aicodebot.helpers import get_token_length, logger, read_config
22
from langchain import PromptTemplate
33
from pathlib import Path
4+
from types import SimpleNamespace
45
import os
56

67
# ---------------------------------------------------------------------------- #
@@ -42,23 +43,28 @@
4243
Speak like Morpheus.
4344
"""
4445

46+
PERSONALITIES = {
47+
"HER": SimpleNamespace(name="Her", prompt=HER, description="The AI character from the movie Her"),
48+
"JULES": SimpleNamespace(name="Jules", prompt=JULES, description="Samuel L. Jackson's character from Pulp Fiction"),
49+
"SHERLOCK": SimpleNamespace(name="Sherlock", prompt=SHERLOCK, description="Sherlock Holmes"),
50+
"THE_DUDE": SimpleNamespace(name="The Dude", prompt=THE_DUDE, description="The Dude from The Big Lebowski"),
51+
"MORPHEUS": SimpleNamespace(name="Morpheus", prompt=MORPHEUS, description="Morpheus from The Matrix"),
52+
}
53+
4554

4655
def get_personality_prompt():
4756
"""Generates a prompt for the sidekick personality."""
48-
personality_map = {
49-
"HER": HER,
50-
"JULES": JULES,
51-
"SHERLOCK": SHERLOCK,
52-
"THE_DUDE": THE_DUDE,
53-
"MORPHEUS": MORPHEUS,
54-
}
57+
if os.getenv("AICODEBOT_PERSONALITY"):
58+
personality = os.getenv("AICODEBOT_PERSONALITY")
59+
else:
60+
config = read_config()
61+
personality = config["personality"]
5562

56-
personality = os.getenv("AICODEBOT_PERSONALITY", "HER")
57-
try:
58-
logger.debug(f"Using personality {personality}")
59-
return personality_map[personality]
60-
except KeyError as e:
61-
raise ValueError(f"Personality {personality} not found") from e
63+
if personality not in PERSONALITIES:
64+
raise ValueError(f"Personality {personality} not found")
65+
66+
logger.debug(f"Using personality {personality}")
67+
return PERSONALITIES[personality].prompt
6268

6369

6470
# ---------------------------------------------------------------------------- #

0 commit comments

Comments
 (0)