Skip to content

databricks_factory

Module for creating a Databricks factory.

DatabricksFactory

Bases: OpenAIFactory

A databricks factory.

Source code in spark_instructor/factory/databricks_factory.py
class DatabricksFactory(OpenAIFactory):
    """A databricks factory."""

    @classmethod
    def from_config(
        cls,
        mode: Optional[instructor.Mode] = None,
        base_url: Optional[str] = None,
        api_key: Optional[str] = None,
        **kwargs
    ) -> "DatabricksFactory":
        """Build a databricks factory from custom entries."""
        return cls(get_databricks_aclient(mode or instructor.Mode.MD_JSON, base_url, api_key))

    def format_messages(self, messages: SparkChatCompletionMessages) -> List[ChatCompletionMessageParam]:
        """Format messages by using default callable."""
        return [message(string_only=True) for message in messages.root]

format_messages(messages)

Format messages by using default callable.

Source code in spark_instructor/factory/databricks_factory.py
def format_messages(self, messages: SparkChatCompletionMessages) -> List[ChatCompletionMessageParam]:
    """Format messages by using default callable."""
    return [message(string_only=True) for message in messages.root]

from_config(mode=None, base_url=None, api_key=None, **kwargs) classmethod

Build a databricks factory from custom entries.

Source code in spark_instructor/factory/databricks_factory.py
@classmethod
def from_config(
    cls,
    mode: Optional[instructor.Mode] = None,
    base_url: Optional[str] = None,
    api_key: Optional[str] = None,
    **kwargs
) -> "DatabricksFactory":
    """Build a databricks factory from custom entries."""
    return cls(get_databricks_aclient(mode or instructor.Mode.MD_JSON, base_url, api_key))