Skip to content

Commit

Permalink
Adding AzurePhiModel
Browse files Browse the repository at this point in the history
  • Loading branch information
parkervg committed Oct 22, 2024
1 parent 4604a8b commit e648ecc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions blendsql/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .local._transformers import TransformersLLM, TransformersVisionModel
from .local._azure_phi import AzurePhiModel
from .remote._ollama import OllamaLLM
from .remote._openai import OpenaiLLM, AzureOpenaiLLM
from .remote._anthropic import AnthropicLLM
Expand Down
48 changes: 48 additions & 0 deletions blendsql/models/local/_azure_phi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import importlib.util
import os
from typing import Optional

from .._model import LocalModel, ModelObj

_has_transformers = importlib.util.find_spec("transformers") is not None


class AzurePhiModel(LocalModel):
def __init__(
self,
config: Optional[dict] = None,
caching: bool = True,
**kwargs,
):
if not _has_transformers:
raise ImportError(
"Please install transformers with `pip install transformers`!"
) from None
import transformers

transformers.logging.set_verbosity_error()
if config is None:
config = {}

super().__init__(
model_name_or_path="microsoft/Phi-3.5-mini-instruct",
requires_config=True,
tokenizer=transformers.AutoTokenizer.from_pretrained(
"microsoft/Phi-3.5-mini-instruct"
),
load_model_kwargs=config,
caching=caching,
**kwargs,
)

def _load_model(self) -> ModelObj:
# https://huggingface.co/blog/how-to-generate
from guidance.models import AzureGuidance

assert all(os.getenv(k) is not None for k in ["AZURE_PHI_KEY", "AZURE_PHI_URL"])
lm = AzureGuidance(
f"{os.getenv('AZURE_PHI_URL')}/guidance#auth={os.getenv('AZURE_PHI_KEY')}",
echo=False,
# **self.load_model_kwargs,
)
return lm

0 comments on commit e648ecc

Please sign in to comment.