-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cecbf7e
commit 21e78e8
Showing
7 changed files
with
48 additions
and
46 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,2 +1,2 @@ | ||
from .base import Model | ||
from .models import get_model | ||
from .base import Model as Model | ||
from .models import get_model as get_model |
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,23 +1,15 @@ | ||
import json | ||
import re | ||
|
||
from transformers import PreTrainedTokenizerFast | ||
|
||
from libertai_agents.interfaces import ToolCallFunction | ||
from libertai_agents.models.base import Model | ||
|
||
|
||
class HermesModel(Model): | ||
tokenizer: PreTrainedTokenizerFast | ||
vm_url: str | ||
|
||
def __init__(self, model_id: str, vm_url: str): | ||
super().__init__(model_id, vm_url) | ||
|
||
@staticmethod | ||
def extract_tool_calls_from_response(response: str) -> list[ToolCallFunction]: | ||
tool_calls = re.findall("<tool_call>\s*(.*)\s*</tool_call>", response) | ||
return [ToolCallFunction(**json.loads(call)) for call in tool_calls] | ||
|
||
def generate_tool_call_id(self) -> str | None: | ||
return None |
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,23 +1,22 @@ | ||
import json | ||
import re | ||
|
||
from transformers import PreTrainedTokenizerFast | ||
import random | ||
import string | ||
|
||
from libertai_agents.interfaces import ToolCallFunction | ||
from libertai_agents.models.base import Model | ||
|
||
|
||
class MistralModel(Model): | ||
tokenizer: PreTrainedTokenizerFast | ||
vm_url: str | ||
|
||
def __init__(self, model_id: str, vm_url: str): | ||
super().__init__(model_id, vm_url) | ||
super().__init__(model_id, vm_url, system_message=False) | ||
|
||
@staticmethod | ||
def extract_tool_calls_from_response(response: str) -> list[ToolCallFunction]: | ||
tool_calls = re.findall("<tool_call>\s*(.*)\s*</tool_call>", response) | ||
return [ToolCallFunction(**json.loads(call)) for call in tool_calls] | ||
try: | ||
tool_calls = json.loads(response) | ||
return [ToolCallFunction(**call) for call in tool_calls] | ||
except Exception: | ||
return [] | ||
|
||
def generate_tool_call_id(self) -> str | None: | ||
return None | ||
def generate_tool_call_id(self) -> str: | ||
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(9)) |
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