-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update AICodeBot to handle larger context sizes and improve user expe…
…rience 🚀 This commit introduces several enhancements to AICodeBot. The README.md file has been updated with more detailed instructions on how to configure the language model to use, manage tokens effectively, and handle larger context sizes. The version in the configuration file has been updated to 1.2. In addition, the language model manager now dynamically switches to a larger model if the context size exceeds the limit of the current model. This feature is supported for both OpenAI and OpenRouter models. The user interface has also been improved. When a request is sent to the language model, a message is displayed indicating which model is being used. If the model is changed due to the context size, a warning message is displayed. Finally, the test suite has been updated to cover these new features. These changes should make AICodeBot more robust and user-friendly, especially when dealing with larger context sizes. 🎉
- Loading branch information
1 parent
3120b99
commit b6adba1
Showing
8 changed files
with
109 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
openai_api_key: sk-dummy | ||
personality: Her | ||
version: 1.1 | ||
version: 1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,42 @@ | ||
from aicodebot.lm import LanguageModelManager, token_size | ||
from aicodebot.prompts import get_prompt | ||
import pytest | ||
from pathlib import Path | ||
import os, pytest | ||
|
||
|
||
def test_token_size(): | ||
def test_token_size(monkeypatch): | ||
monkeypatch.setenv("AICODEBOT_CONFIG_FILE", str(Path(__file__).parent / "test_config.yaml")) | ||
assert token_size("") == 0 | ||
|
||
text = "Code with heart, align AI with humanity. ❤️🤖" | ||
assert LanguageModelManager().get_token_size(text) == 14 | ||
assert token_size(text) == 14 | ||
|
||
|
||
@pytest.mark.parametrize("provider,model_name", [("OpenAI", "gpt-4"), ("OpenRouter", "gpt-4")]) | ||
@pytest.mark.parametrize( | ||
"provider,model_name", | ||
[ | ||
(LanguageModelManager.OPENAI, "gpt-4"), | ||
(LanguageModelManager.OPENROUTER, "gpt-4"), | ||
(LanguageModelManager.HUGGINGFACE_HUB, "google/flan-t5-xxl"), | ||
], | ||
) | ||
def test_chain_factory(provider, model_name, monkeypatch): | ||
monkeypatch.setenv("AICODEBOT_MODEL_PROVIDER", provider) | ||
monkeypatch.setenv("AICODEBOT_MODEL", model_name) | ||
monkeypatch.setenv("OPENROUTER_API_KEY", "dummy") | ||
monkeypatch.setenv("OPENAI_API_KEY", "dummy") | ||
monkeypatch.setenv("HUGGINGFACE_API_KEY", "dummy") | ||
|
||
llm = LanguageModelManager() | ||
assert os.getenv("OPENROUTER_API_KEY") == "dummy" | ||
assert llm.get_api_key("OPENROUTER_API_KEY") == "dummy" | ||
|
||
prompt = get_prompt("alignment") | ||
chain = llm.chain_factory(prompt) | ||
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 |