Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
vblagoje committed Jun 5, 2024
1 parent df07dad commit d9ebb8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
from dataclasses import dataclass
from enum import Enum
from typing import Any, Optional, Tuple
from typing import Any, Dict, Optional, Tuple


class LLMProvider(Enum):
Expand All @@ -18,7 +18,7 @@ class LLMProvider(Enum):
COHERE = "cohere"


PROVIDER_DETAILS = {
PROVIDER_DETAILS: Dict[LLMProvider, Dict[str, Any]] = {
LLMProvider.OPENAI: {
"class_path": "haystack.components.generators.chat.openai.OpenAIChatGenerator",
"patterns": [re.compile(r"^gpt.*")],
Expand Down Expand Up @@ -71,19 +71,19 @@ def create_generator(
"""
Create ChatGenerator instance based on the model name and provider.
"""
provider_enum = None
if provider:
if provider.lower() not in LLMProvider.__members__:
raise ValueError(f"Invalid provider: {provider}")
provider_enum = LLMProvider[provider.lower()]
else:
provider_enum = None
for prov, details in PROVIDER_DETAILS.items():
if any(pattern.match(model_name) for pattern in details["patterns"]):
provider_enum = prov
break

if provider_enum is None:
raise ValueError(f"Could not infer provider for model name: {model_name}")
if provider_enum is None:
raise ValueError(f"Could not infer provider for model name: {model_name}")

llm_identifier = LLMIdentifier(provider=provider_enum, model_name=model_name)
class_path = PROVIDER_DETAILS[llm_identifier.provider]["class_path"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
logger = logging.getLogger(__name__)


def openai_converter(schema: "OpenAPISpecification") -> List[Dict[str, Any]]: # noqa: F821
def openai_converter(schema: "OpenAPISpecification") -> List[Dict[str, Any]]: # type: ignore[name-defined] # noqa: F821
"""
Converts OpenAPI specification to a list of function suitable for OpenAI LLM function calling.
Expand All @@ -29,7 +29,7 @@ def openai_converter(schema: "OpenAPISpecification") -> List[Dict[str, Any]]: #
return [{"type": "function", "function": fn} for fn in fn_definitions]


def anthropic_converter(schema: "OpenAPISpecification") -> List[Dict[str, Any]]: # noqa: F821
def anthropic_converter(schema: "OpenAPISpecification") -> List[Dict[str, Any]]: # type: ignore # noqa: F821
"""
Converts an OpenAPI specification to a list of function definitions for Anthropic LLM function calling.
Expand All @@ -42,7 +42,7 @@ def anthropic_converter(schema: "OpenAPISpecification") -> List[Dict[str, Any]]:
)


def cohere_converter(schema: "OpenAPISpecification") -> List[Dict[str, Any]]: # noqa: F821
def cohere_converter(schema: "OpenAPISpecification") -> List[Dict[str, Any]]: # type: ignore[name-defined] # noqa: F821
"""
Converts an OpenAPI specification to a list of function definitions for Cohere LLM function calling.
Expand Down

0 comments on commit d9ebb8c

Please sign in to comment.