@@ -1576,6 +1576,7 @@ def __init__( |
1576 | 1576 | response_mime_type: Optional[str] = None, |
1577 | 1577 | response_schema: Optional[Dict[str, Any]] = None, |
1578 | 1578 | seed: Optional[int] = None, |
| 1579 | + routing_config: Optional["RoutingConfig"] = None, |
1579 | 1580 | ): |
1580 | 1581 | r"""Constructs a GenerationConfig object. |
1581 | 1582 |
|
@@ -1601,6 +1602,7 @@ def __init__( |
1601 | 1602 | response type, otherwise the behavior is undefined. |
1602 | 1603 | response_schema: Output response schema of the genreated candidate text. Only valid when |
1603 | 1604 | response_mime_type is application/json. |
| 1605 | + routing_config: Model routing preference set in the request. |
1604 | 1606 |
|
1605 | 1607 | Usage: |
1606 | 1608 | ``` |
@@ -1636,6 +1638,10 @@ def __init__( |
1636 | 1638 | response_schema=raw_schema, |
1637 | 1639 | seed=seed, |
1638 | 1640 | ) |
| 1641 | + if routing_config is not None: |
| 1642 | + self._raw_generation_config.routing_config = ( |
| 1643 | + routing_config._gapic_routing_config |
| 1644 | + ) |
1639 | 1645 |
|
1640 | 1646 | @classmethod |
1641 | 1647 | def _from_gapic( |
@@ -1659,6 +1665,109 @@ def to_dict(self) -> Dict[str, Any]: |
1659 | 1665 | def __repr__(self) -> str: |
1660 | 1666 | return self._raw_generation_config.__repr__() |
1661 | 1667 |
|
| 1668 | + class RoutingConfig: |
| 1669 | + r"""The configuration for model router requests. |
| 1670 | +
|
| 1671 | + The routing config is either one of the two nested classes: |
| 1672 | + - AutoRoutingMode: Automated routing. |
| 1673 | + - ManualRoutingMode: Manual routing. |
| 1674 | +
|
| 1675 | + Usage: |
| 1676 | + - AutoRoutingMode: |
| 1677 | +
|
| 1678 | + ``` |
| 1679 | + routing_config=generative_models.RoutingConfig( |
| 1680 | + routing_config=generative_models.RoutingConfig.AutoRoutingMode( |
| 1681 | + model_routing_preference=generative_models.RoutingConfig.AutoRoutingMode.ModelRoutingPreference.BALANCED, |
| 1682 | + ), |
| 1683 | + ) |
| 1684 | + ``` |
| 1685 | + - ManualRoutingMode: |
| 1686 | +
|
| 1687 | + ``` |
| 1688 | + routing_config=generative_models.RoutingConfig( |
| 1689 | + routing_config=generative_models.RoutingConfig.ManutalRoutingMode( |
| 1690 | + model_name="gemini-1.5-pro-001", |
| 1691 | + ), |
| 1692 | + ) |
| 1693 | + ``` |
| 1694 | + """ |
| 1695 | + |
| 1696 | + def __init__( |
| 1697 | + self, |
| 1698 | + *, |
| 1699 | + routing_config: Union[ |
| 1700 | + "GenerationConfig.RoutingConfig.AutoRoutingMode", |
| 1701 | + "GenerationConfig.RoutingConfig.ManualRoutingMode", |
| 1702 | + ], |
| 1703 | + ): |
| 1704 | + if isinstance(routing_config, self.AutoRoutingMode): |
| 1705 | + self._gapic_routing_config = ( |
| 1706 | + gapic_content_types.GenerationConfig.RoutingConfig( |
| 1707 | + auto_mode=routing_config._gapic_auto_mode |
| 1708 | + ) |
| 1709 | + ) |
| 1710 | + else: |
| 1711 | + self._gapic_routing_config = ( |
| 1712 | + gapic_content_types.GenerationConfig.RoutingConfig( |
| 1713 | + manual_mode=routing_config._gapic_manual_mode |
| 1714 | + ) |
| 1715 | + ) |
| 1716 | + |
| 1717 | + def __repr__(self): |
| 1718 | + return self._gapic_routing_config.__repr__() |
| 1719 | + |
| 1720 | + class AutoRoutingMode: |
| 1721 | + r"""When automated routing is specified, the routing will be |
| 1722 | + determined by the routing model predicted quality and customer provided |
| 1723 | + model routing preference. |
| 1724 | + """ |
| 1725 | + |
| 1726 | + ModelRoutingPreference = ( |
| 1727 | + gapic_content_types.GenerationConfig.RoutingConfig.AutoRoutingMode.ModelRoutingPreference |
| 1728 | + ) |
| 1729 | + |
| 1730 | + def __init__( |
| 1731 | + self, |
| 1732 | + *, |
| 1733 | + model_routing_preference: "GenerationConfig.RoutingConfig.AutoRoutingMode.ModelRoutingPreference", |
| 1734 | + ): |
| 1735 | + r"""AutoRouingMode constructor |
| 1736 | +
|
| 1737 | + Args: |
| 1738 | + model_routing_preference: Model routing preference for the routing request. |
| 1739 | + """ |
| 1740 | + self._gapic_auto_mode = ( |
| 1741 | + gapic_content_types.GenerationConfig.RoutingConfig.AutoRoutingMode( |
| 1742 | + model_routing_preference=model_routing_preference |
| 1743 | + ) |
| 1744 | + ) |
| 1745 | + |
| 1746 | + def __repr__(self): |
| 1747 | + return self._gapic_auto_mode.__repr__() |
| 1748 | + |
| 1749 | + class ManualRoutingMode: |
| 1750 | + r"""When manual routing is set, the specified model will be used |
| 1751 | + directly. |
| 1752 | + """ |
| 1753 | + |
| 1754 | + def __init__( |
| 1755 | + self, |
| 1756 | + *, |
| 1757 | + model_name: str, |
| 1758 | + ): |
| 1759 | + r"""ManualRoutingMode constructor |
| 1760 | +
|
| 1761 | + Args: |
| 1762 | + model_name: The model to use. Only public LLM model names and those that are supported by the router are allowed. |
| 1763 | + """ |
| 1764 | + self._gapic_manual_mode = gapic_content_types.GenerationConfig.RoutingConfig.ManualRoutingMode( |
| 1765 | + model_name=model_name |
| 1766 | + ) |
| 1767 | + |
| 1768 | + def __repr__(self): |
| 1769 | + return self._gapic_manual_mode.__repr__() |
| 1770 | + |
1662 | 1771 |
|
1663 | 1772 | class Tool: |
1664 | 1773 | r"""A collection of functions that the model may use to generate response. |
|