-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable
gac help-ai
to work with all supported models, patch summari…
…ze crash (#67) * ✨refactor cli help_ai_handler,gen_commit_msg,add llm_chat_completion module * lint * fix summarize command
- Loading branch information
Showing
5 changed files
with
34 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,15 @@ | ||
from ai_commit_msg.core.llm_chat_completion import llm_chat_completion | ||
from ai_commit_msg.core.prompt import get_prompt | ||
from ai_commit_msg.services.anthropic_service import AnthropicService | ||
from ai_commit_msg.services.config_service import ConfigService | ||
from ai_commit_msg.services.git_service import GitService | ||
from ai_commit_msg.services.ollama_service import OLlamaService | ||
from ai_commit_msg.services.openai_service import OpenAiService | ||
from ai_commit_msg.utils.logger import Logger | ||
from ai_commit_msg.utils.models import ANTHROPIC_MODEL_LIST, OPEN_AI_MODEL_LIST | ||
|
||
|
||
def generate_commit_message(diff: str = None) -> str: | ||
|
||
if diff is None: | ||
raise ValueError("Diff is required to generate a commit message") | ||
|
||
select_model = ConfigService.get_model() | ||
|
||
prompt = get_prompt(diff) | ||
|
||
# TODO - create a factory with a shared interface for calling the LLM models, this will make it easier to add new models | ||
ai_gen_commit_msg = None | ||
if str(select_model) in OPEN_AI_MODEL_LIST: | ||
ai_gen_commit_msg = OpenAiService().chat_with_openai(prompt) | ||
elif select_model.startswith("ollama"): | ||
ai_gen_commit_msg = OLlamaService().chat_completion(prompt) | ||
elif select_model in ANTHROPIC_MODEL_LIST: | ||
ai_gen_commit_msg = AnthropicService().chat_completion(prompt) | ||
|
||
if ai_gen_commit_msg is None: | ||
Logger().log("Unsupported model: " + select_model) | ||
return "" | ||
ai_gen_commit_msg = llm_chat_completion(prompt) | ||
|
||
prefix = ConfigService().prefix | ||
|
||
return prefix + ai_gen_commit_msg |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from ai_commit_msg.services.anthropic_service import AnthropicService | ||
from ai_commit_msg.services.config_service import ConfigService | ||
from ai_commit_msg.services.ollama_service import OLlamaService | ||
from ai_commit_msg.services.openai_service import OpenAiService | ||
from ai_commit_msg.utils.logger import Logger | ||
from ai_commit_msg.utils.models import ANTHROPIC_MODEL_LIST, OPEN_AI_MODEL_LIST | ||
|
||
|
||
def llm_chat_completion(prompt): | ||
select_model = ConfigService.get_model() | ||
|
||
# TODO - create a factory with a shared interface for calling the LLM models, this will make it easier to add new models | ||
ai_gen_commit_msg = None | ||
if str(select_model) in OPEN_AI_MODEL_LIST: | ||
ai_gen_commit_msg = OpenAiService().chat_with_openai(prompt) | ||
elif select_model.startswith("ollama"): | ||
ai_gen_commit_msg = OLlamaService().chat_completion(prompt) | ||
elif select_model in ANTHROPIC_MODEL_LIST: | ||
ai_gen_commit_msg = AnthropicService().chat_completion(prompt) | ||
|
||
if ai_gen_commit_msg is None: | ||
Logger().log("Unsupported model: " + select_model) | ||
return "" | ||
|
||
return ai_gen_commit_msg |
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