Skip to content

typedefs

Class info

Classes

Name Children Inherits
Message
llmling.core.typedefs
A chat message.
    MessageContent
    llmling.core.typedefs
    Content item in a message.
      ProcessingStep
      llmling.core.typedefs
      Configuration for a processing step.
        ToolCall
        llmling.core.typedefs
        A tool call request from the LLM.

          🛈 DocStrings

          Common type definitions for llmling.

          Message

          Bases: Schema

          A chat message.

          Source code in src/llmling/core/typedefs.py
          class Message(Schema):
              """A chat message."""
          
              role: MessageRole
              content: str = ""  # Keep for backward compatibility
              content_items: list[MessageContent] = Field(default_factory=list)
              name: str | None = None
              tool_calls: list[ToolCall] | None = None
              tool_call_id: str | None = None
          
              model_config = ConfigDict(frozen=True)
          
              @model_validator(mode="before")
              @classmethod
              def ensure_content_items(cls, data: dict[str, Any]) -> dict[str, Any]:
                  """Ensure content_items is populated from content if empty."""
                  if isinstance(data, dict):
                      content = data.get("content", "")
                      content_items = data.get("content_items", [])
                      # Only create content_items from content if we have content and no items
                      if content and not content_items:
                          data["content_items"] = [MessageContent(type="text", content=content).model_dump()]
                      # Always keep content in sync with first text content item
                      elif content_items:
                          text_items = [
                              item
                              for item in content_items
                              if isinstance(item, dict) and item.get("type") == "text"
                          ]
                          if text_items:
                              data["content"] = text_items[0]["content"]
                  return data
          
              @classmethod
              def from_dict(cls, data: dict[str, Any]) -> Message:
                  """Create message from dict representation."""
                  # Handle content_items if present
                  if "content_items" in data and isinstance(data["content_items"], list):
                      data["content_items"] = [
                          MessageContent(**item) if isinstance(item, dict) else item
                          for item in data["content_items"]
                      ]
                  # Handle tool_calls if present
                  if "tool_calls" in data and isinstance(data["tool_calls"], list):
                      data["tool_calls"] = [
                          ToolCall(**call) if isinstance(call, dict) else call for call in data["tool_calls"]
                      ]
                  return cls(**data)
          
              def to_dict(self) -> dict[str, Any]:
                  """Convert to dict for serialization."""
                  return self.model_dump(exclude_none=True)
          

          ensure_content_items classmethod

          ensure_content_items(data: dict[str, Any]) -> dict[str, Any]
          

          Ensure content_items is populated from content if empty.

          Source code in src/llmling/core/typedefs.py
          @model_validator(mode="before")
          @classmethod
          def ensure_content_items(cls, data: dict[str, Any]) -> dict[str, Any]:
              """Ensure content_items is populated from content if empty."""
              if isinstance(data, dict):
                  content = data.get("content", "")
                  content_items = data.get("content_items", [])
                  # Only create content_items from content if we have content and no items
                  if content and not content_items:
                      data["content_items"] = [MessageContent(type="text", content=content).model_dump()]
                  # Always keep content in sync with first text content item
                  elif content_items:
                      text_items = [
                          item
                          for item in content_items
                          if isinstance(item, dict) and item.get("type") == "text"
                      ]
                      if text_items:
                          data["content"] = text_items[0]["content"]
              return data
          

          from_dict classmethod

          from_dict(data: dict[str, Any]) -> Message
          

          Create message from dict representation.

          Source code in src/llmling/core/typedefs.py
          @classmethod
          def from_dict(cls, data: dict[str, Any]) -> Message:
              """Create message from dict representation."""
              # Handle content_items if present
              if "content_items" in data and isinstance(data["content_items"], list):
                  data["content_items"] = [
                      MessageContent(**item) if isinstance(item, dict) else item
                      for item in data["content_items"]
                  ]
              # Handle tool_calls if present
              if "tool_calls" in data and isinstance(data["tool_calls"], list):
                  data["tool_calls"] = [
                      ToolCall(**call) if isinstance(call, dict) else call for call in data["tool_calls"]
                  ]
              return cls(**data)
          

          to_dict

          to_dict() -> dict[str, Any]
          

          Convert to dict for serialization.

          Source code in src/llmling/core/typedefs.py
          def to_dict(self) -> dict[str, Any]:
              """Convert to dict for serialization."""
              return self.model_dump(exclude_none=True)
          

          MessageContent

          Bases: Schema

          Content item in a message.

          Source code in src/llmling/core/typedefs.py
          class MessageContent(Schema):
              """Content item in a message."""
          
              type: MessageContentType
              content: str  # The actual content (text/uri/url/base64)
              alt_text: str | None = None  # For images or resource descriptions
          
              model_config = ConfigDict(frozen=True)
          

          ProcessingStep

          Bases: Schema

          Configuration for a processing step.

          Source code in src/llmling/core/typedefs.py
          class ProcessingStep(Schema):  # type: ignore[no-redef]
              """Configuration for a processing step."""
          
              name: str
              parallel: bool = False
              required: bool = True
              kwargs: dict[str, Any] = Field(default_factory=dict)
          
              model_config = ConfigDict(frozen=True)
          

          ToolCall

          Bases: Schema

          A tool call request from the LLM.

          Source code in src/llmling/core/typedefs.py
          class ToolCall(Schema):
              """A tool call request from the LLM."""
          
              id: str  # Required by OpenAI
              name: str
              parameters: dict[str, Any]
          
              model_config = ConfigDict(frozen=True)