Skip to content

Commit

Permalink
Merge pull request #541 from haesleinhuepf/git-bob-mod-cuAd2f8RlU
Browse files Browse the repository at this point in the history
Add regex-based extension filtering using environment variable
  • Loading branch information
haesleinhuepf authored Jan 26, 2025
2 parents ec0f98a + 835f9ff commit 843f0f7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/git-bob.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
- name: Run git-bob
env:
GIT_BOB_AGENT_NAME: "git-bob"
GIT_BOB_EXTENSIONS_FILTER_REGEXP: ".*"
GIT_BOB_LLM_NAME: "${{ secrets.GIT_BOB_LLM_NAME }}"
ANTHROPIC_API_KEY: "${{ secrets.ANTHROPIC_API_KEY }}"
GOOGLE_API_KEY: "${{ secrets.GOOGLE_API_KEY }}"
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ At the moment, these limitations can be observed:

git-bob can be extended in multiple ways.
All you need to do is to set up small python library which implements specific functions and exposes them using Pythons plugin system.
You find an example implementation of the extensions described below in [this respository](https://github.com/haesleinhuepf/git-bob-plugin-example).

### Adding new trigger words

Expand Down Expand Up @@ -319,6 +320,27 @@ git_bob.prompt_handlers =
git-bob will then detect your plugin and can use it if the `GIT_BOB_LLM_NAME` secret is set to any model containing `my_custom_llm`.
You could for example configure a llama model running on your LLM-server like this: `my_custom_llm:llama3.3-70b`.

### Filtering extensions

If you wish to extend git-bob with custom triggers or prompt handlers, but avoid default triggers and prompt handlers, you can configure a filter in the `git-bob.yml` workflow file.
Just overwrite this default regular expression accepting all extensions:

```
GIT_BOB_EXTENSIONS_FILTER_REGEXP: ".*"
```

If you want to only accept extensions starting with `my_library`, you can configure the filter like this:

```
GIT_BOB_EXTENSIONS_FILTER_REGEXP: "^my_library.*"
```

If you want to accept all extensions but not git-bob`s defaults, you can configure the filter like this:

```
GIT_BOB_EXTENSIONS_FILTER_REGEXP: "^(?!git_bob).*"
```

## Similar projects

There are similar projects out there
Expand Down
10 changes: 10 additions & 0 deletions src/git_bob/_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,15 @@ def init_prompt_handlers():
Dictionary mapping handler names to functions that can handle prompts
"""
from importlib.metadata import entry_points
import os
import re

handlers = {}
module_filter = os.environ.get("GIT_BOB_EXTENSIONS_FILTER_REGEXP", ".*")
for entry_point in entry_points(group='git_bob.prompt_handlers'):
try:
if not re.match(module_filter, entry_point.module):
continue
handler_func = entry_point.load()
key = entry_point.name
handlers[key] = handler_func
Expand All @@ -240,10 +245,15 @@ def init_triggers():
Dictionary mapping trigger names to functions that can handle triggers
"""
from importlib.metadata import entry_points
import os
import re

triggers = {}
module_filter = os.environ.get("GIT_BOB_EXTENSIONS_FILTER_REGEXP", ".*")
for entry_point in entry_points(group='git_bob.triggers'):
try:
if not re.match(module_filter, entry_point.module):
continue
trigger_func = entry_point.load()
key = entry_point.name
triggers[key] = trigger_func
Expand Down

0 comments on commit 843f0f7

Please sign in to comment.