|
27 | 27 |
|
28 | 28 | from . import _exceptions |
29 | 29 | from ._qs import Querystring |
| 30 | +from .types import client_search_params |
30 | 31 | from ._types import ( |
31 | 32 | NOT_GIVEN, |
| 33 | + Body, |
32 | 34 | Omit, |
| 35 | + Query, |
| 36 | + Headers, |
33 | 37 | Timeout, |
34 | 38 | NotGiven, |
35 | 39 | Transport, |
36 | 40 | ProxiesTypes, |
37 | 41 | RequestOptions, |
38 | 42 | ) |
39 | | -from ._utils import is_given, get_async_library |
| 43 | +from ._utils import ( |
| 44 | + is_given, |
| 45 | + maybe_transform, |
| 46 | + get_async_library, |
| 47 | + async_maybe_transform, |
| 48 | +) |
40 | 49 | from ._compat import cached_property |
41 | 50 | from ._version import __version__ |
| 51 | +from ._response import ( |
| 52 | + to_raw_response_wrapper, |
| 53 | + to_streamed_response_wrapper, |
| 54 | + async_to_raw_response_wrapper, |
| 55 | + async_to_streamed_response_wrapper, |
| 56 | +) |
42 | 57 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream |
43 | 58 | from ._exceptions import APIStatusError, ReplicateError |
44 | 59 | from ._base_client import ( |
45 | 60 | DEFAULT_MAX_RETRIES, |
46 | 61 | SyncAPIClient, |
47 | 62 | AsyncAPIClient, |
| 63 | + make_request_options, |
48 | 64 | ) |
| 65 | +from .types.search_response import SearchResponse |
49 | 66 |
|
50 | 67 | if TYPE_CHECKING: |
51 | 68 | from .resources import files, models, account, hardware, webhooks, trainings, collections, deployments, predictions |
@@ -354,6 +371,70 @@ def copy( |
354 | 371 | # client.with_options(timeout=10).foo.create(...) |
355 | 372 | with_options = copy |
356 | 373 |
|
| 374 | + def search( |
| 375 | + self, |
| 376 | + *, |
| 377 | + query: str, |
| 378 | + limit: int | NotGiven = NOT_GIVEN, |
| 379 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 380 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 381 | + extra_headers: Headers | None = None, |
| 382 | + extra_query: Query | None = None, |
| 383 | + extra_body: Body | None = None, |
| 384 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 385 | + ) -> SearchResponse: |
| 386 | + """ |
| 387 | + Search for public models, collections, and docs using a text query. |
| 388 | +
|
| 389 | + For models, the response includes all model data, plus a new `metadata` object |
| 390 | + with the following fields: |
| 391 | +
|
| 392 | + - `generated_description`: A longer and more detailed AI-generated description |
| 393 | + of the model |
| 394 | + - `tags`: An array of tags for the model |
| 395 | + - `score`: A score for the model's relevance to the search query |
| 396 | +
|
| 397 | + Example cURL request: |
| 398 | +
|
| 399 | + ```console |
| 400 | + curl -s \\ |
| 401 | + -H "Authorization: Bearer $REPLICATE_API_TOKEN" \\ |
| 402 | + "https://api.replicate.com/v1/search?query=nano+banana" |
| 403 | + ``` |
| 404 | +
|
| 405 | + Note: This search API is currently in beta and may change in future versions. |
| 406 | +
|
| 407 | + Args: |
| 408 | + query: The search query string |
| 409 | +
|
| 410 | + limit: Maximum number of model results to return (1-50, defaults to 20) |
| 411 | +
|
| 412 | + extra_headers: Send extra headers |
| 413 | +
|
| 414 | + extra_query: Add additional query parameters to the request |
| 415 | +
|
| 416 | + extra_body: Add additional JSON properties to the request |
| 417 | +
|
| 418 | + timeout: Override the client-level default timeout for this request, in seconds |
| 419 | + """ |
| 420 | + return self.get( |
| 421 | + "/search", |
| 422 | + options=make_request_options( |
| 423 | + extra_headers=extra_headers, |
| 424 | + extra_query=extra_query, |
| 425 | + extra_body=extra_body, |
| 426 | + timeout=timeout, |
| 427 | + query=maybe_transform( |
| 428 | + { |
| 429 | + "query": query, |
| 430 | + "limit": limit, |
| 431 | + }, |
| 432 | + client_search_params.ClientSearchParams, |
| 433 | + ), |
| 434 | + ), |
| 435 | + cast_to=SearchResponse, |
| 436 | + ) |
| 437 | + |
357 | 438 | @override |
358 | 439 | def _make_status_error( |
359 | 440 | self, |
@@ -665,6 +746,70 @@ def copy( |
665 | 746 | # client.with_options(timeout=10).foo.create(...) |
666 | 747 | with_options = copy |
667 | 748 |
|
| 749 | + async def search( |
| 750 | + self, |
| 751 | + *, |
| 752 | + query: str, |
| 753 | + limit: int | NotGiven = NOT_GIVEN, |
| 754 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 755 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 756 | + extra_headers: Headers | None = None, |
| 757 | + extra_query: Query | None = None, |
| 758 | + extra_body: Body | None = None, |
| 759 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 760 | + ) -> SearchResponse: |
| 761 | + """ |
| 762 | + Search for public models, collections, and docs using a text query. |
| 763 | +
|
| 764 | + For models, the response includes all model data, plus a new `metadata` object |
| 765 | + with the following fields: |
| 766 | +
|
| 767 | + - `generated_description`: A longer and more detailed AI-generated description |
| 768 | + of the model |
| 769 | + - `tags`: An array of tags for the model |
| 770 | + - `score`: A score for the model's relevance to the search query |
| 771 | +
|
| 772 | + Example cURL request: |
| 773 | +
|
| 774 | + ```console |
| 775 | + curl -s \\ |
| 776 | + -H "Authorization: Bearer $REPLICATE_API_TOKEN" \\ |
| 777 | + "https://api.replicate.com/v1/search?query=nano+banana" |
| 778 | + ``` |
| 779 | +
|
| 780 | + Note: This search API is currently in beta and may change in future versions. |
| 781 | +
|
| 782 | + Args: |
| 783 | + query: The search query string |
| 784 | +
|
| 785 | + limit: Maximum number of model results to return (1-50, defaults to 20) |
| 786 | +
|
| 787 | + extra_headers: Send extra headers |
| 788 | +
|
| 789 | + extra_query: Add additional query parameters to the request |
| 790 | +
|
| 791 | + extra_body: Add additional JSON properties to the request |
| 792 | +
|
| 793 | + timeout: Override the client-level default timeout for this request, in seconds |
| 794 | + """ |
| 795 | + return await self.get( |
| 796 | + "/search", |
| 797 | + options=make_request_options( |
| 798 | + extra_headers=extra_headers, |
| 799 | + extra_query=extra_query, |
| 800 | + extra_body=extra_body, |
| 801 | + timeout=timeout, |
| 802 | + query=await async_maybe_transform( |
| 803 | + { |
| 804 | + "query": query, |
| 805 | + "limit": limit, |
| 806 | + }, |
| 807 | + client_search_params.ClientSearchParams, |
| 808 | + ), |
| 809 | + ), |
| 810 | + cast_to=SearchResponse, |
| 811 | + ) |
| 812 | + |
668 | 813 | @override |
669 | 814 | def _make_status_error( |
670 | 815 | self, |
@@ -705,6 +850,10 @@ class ReplicateWithRawResponse: |
705 | 850 | def __init__(self, client: Replicate) -> None: |
706 | 851 | self._client = client |
707 | 852 |
|
| 853 | + self.search = to_raw_response_wrapper( |
| 854 | + client.search, |
| 855 | + ) |
| 856 | + |
708 | 857 | @cached_property |
709 | 858 | def collections(self) -> collections.CollectionsResourceWithRawResponse: |
710 | 859 | from .resources.collections import CollectionsResourceWithRawResponse |
@@ -766,6 +915,10 @@ class AsyncReplicateWithRawResponse: |
766 | 915 | def __init__(self, client: AsyncReplicate) -> None: |
767 | 916 | self._client = client |
768 | 917 |
|
| 918 | + self.search = async_to_raw_response_wrapper( |
| 919 | + client.search, |
| 920 | + ) |
| 921 | + |
769 | 922 | @cached_property |
770 | 923 | def collections(self) -> collections.AsyncCollectionsResourceWithRawResponse: |
771 | 924 | from .resources.collections import AsyncCollectionsResourceWithRawResponse |
@@ -827,6 +980,10 @@ class ReplicateWithStreamedResponse: |
827 | 980 | def __init__(self, client: Replicate) -> None: |
828 | 981 | self._client = client |
829 | 982 |
|
| 983 | + self.search = to_streamed_response_wrapper( |
| 984 | + client.search, |
| 985 | + ) |
| 986 | + |
830 | 987 | @cached_property |
831 | 988 | def collections(self) -> collections.CollectionsResourceWithStreamingResponse: |
832 | 989 | from .resources.collections import CollectionsResourceWithStreamingResponse |
@@ -888,6 +1045,10 @@ class AsyncReplicateWithStreamedResponse: |
888 | 1045 | def __init__(self, client: AsyncReplicate) -> None: |
889 | 1046 | self._client = client |
890 | 1047 |
|
| 1048 | + self.search = async_to_streamed_response_wrapper( |
| 1049 | + client.search, |
| 1050 | + ) |
| 1051 | + |
891 | 1052 | @cached_property |
892 | 1053 | def collections(self) -> collections.AsyncCollectionsResourceWithStreamingResponse: |
893 | 1054 | from .resources.collections import AsyncCollectionsResourceWithStreamingResponse |
|
0 commit comments