Skip to content

Commit

Permalink
Refactor config reading and expand test coverage
Browse files Browse the repository at this point in the history
This commit refactors the way we read the configuration in `lm.py` to ensure that we always return a dictionary, even when the configuration file is not found. This change simplifies the code and makes it more robust.

In `output.py`, we've updated the comment to better reflect the actual code change, which is setting the padding to 0.

In `test_lm.py`, we've expanded the test coverage to include more models. This will help us catch potential issues with these models earlier.

These changes should improve the overall quality and reliability of our code. 🚀👍🏽
  • Loading branch information
TechNickAI committed Aug 4, 2023
1 parent 8940ca3 commit 8ec4065
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions aicodebot/lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get_api_key(self, key_name):
if api_key:
return api_key
else:
config = read_config()
config = read_config() or {}
key_name_lower = key_name.lower()
# Try both upper and lower case from the config file
if key_name_lower in config:
Expand Down Expand Up @@ -218,7 +218,7 @@ def get_token_size(self, text):

def read_model_config(self):
# Figure out which model to use, based on the config file or environment variables
config = read_config()
config = read_config() or {}
self.provider = os.getenv(
"AICODEBOT_MODEL_PROVIDER", config.get("language_model_provider", self.DEFAULT_PROVIDER)
)
Expand Down
2 changes: 1 addition & 1 deletion aicodebot/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class OurCodeBlock(CodeBlock):

def __rich_console__(self, console, options):
code = str(self.text)
# set dedent=True to remove leading spaces and turn off padding
# Set the padding to 0
syntax = Syntax(code, self.lexer_name, theme=self.theme, word_wrap=True, padding=0)
yield syntax

Expand Down
11 changes: 7 additions & 4 deletions tests/test_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def test_token_size(monkeypatch):


@pytest.mark.parametrize(
"provider,model_name", [(LanguageModelManager.OPENAI, "gpt-4"), (LanguageModelManager.OPENROUTER, "gpt-4")]
"provider,model_name",
[
(LanguageModelManager.OPENAI, "gpt-4"),
(LanguageModelManager.OPENAI, "gpt-3.5-turbo"),
(LanguageModelManager.OPENROUTER, "gpt-4"),
(LanguageModelManager.OPENROUTER, "gpt-4-32k"),
],
)
def test_chain_factory(provider, model_name, monkeypatch):
monkeypatch.setenv("AICODEBOT_MODEL_PROVIDER", provider)
Expand All @@ -31,6 +37,3 @@ def test_chain_factory(provider, model_name, monkeypatch):
if hasattr(chain.llm, "model_name"):
# OpenAI compatible
assert chain.llm.model_name == model_name
elif hasattr(chain.llm, "repo_id"):
# Hugging Face Hub
assert chain.llm.repo_id == model_name

0 comments on commit 8ec4065

Please sign in to comment.