Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mapping for ewiz specific model #25

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions elm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class ApiBase(ABC):
MODEL_ROLE = "You are a research assistant that answers questions."
"""High level model role"""

TOKENIZER_ALIASES = {'gpt-35-turbo': 'gpt-3.5-turbo',
'gpt-4-32k': 'gpt-4-32k-0314'
}
"""Optional mappings for unusual Azure names to tiktoken/openai names."""

def __init__(self, model=None):
"""
Parameters
Expand Down Expand Up @@ -338,8 +343,8 @@ def get_embedding(cls, text):

return embedding

@staticmethod
def count_tokens(text, model):
@classmethod
def count_tokens(cls, text, model):
"""Return the number of tokens in a string.

Parameters
Expand All @@ -355,12 +360,7 @@ def count_tokens(text, model):
Number of tokens in text
"""

# Optional mappings for weird azure names to tiktoken/openai names
tokenizer_aliases = {'gpt-35-turbo': 'gpt-3.5-turbo',
'gpt-4-32k': 'gpt-4-32k-0314'
}

token_model = tokenizer_aliases.get(model, model)
token_model = cls.TOKENIZER_ALIASES.get(model, model)
encoding = tiktoken.encoding_for_model(token_model)

return len(encoding.encode(text))
Expand Down
5 changes: 5 additions & 0 deletions elm/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ class EnergyWizardPostgres(EnergyWizardBase):
"""
EMBEDDING_MODEL = 'amazon.titan-embed-text-v1'

TOKENIZER_ALIASES = {**EnergyWizardBase.TOKENIZER_ALIASES,
'ewiz-gpt-4': 'gpt-4'
}
"""Optional mappings for weird azure names to tiktoken/openai names."""

def __init__(self, db_host, db_port, db_name,
db_schema, db_table, cursor=None, boto_client=None,
model=None, token_budget=3500):
Expand Down
Loading