|
| 1 | +<<<<<<< HEAD |
1 | 2 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
2 | 3 |
|
3 | 4 | from __future__ import annotations |
@@ -247,3 +248,243 @@ def __init__(self, retrieve: AsyncRetrieveResource) -> None: |
247 | 248 | self.documents = async_to_streamed_response_wrapper( |
248 | 249 | retrieve.documents, |
249 | 250 | ) |
| 251 | +||||||| parent of 8b48985 (feat(api): manual updates) |
| 252 | +======= |
| 253 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 254 | + |
| 255 | +from __future__ import annotations |
| 256 | + |
| 257 | +import httpx |
| 258 | + |
| 259 | +from ..types import retrieve_documents_params |
| 260 | +from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given |
| 261 | +from .._utils import maybe_transform, async_maybe_transform |
| 262 | +from .._compat import cached_property |
| 263 | +from .._resource import SyncAPIResource, AsyncAPIResource |
| 264 | +from .._response import ( |
| 265 | + to_raw_response_wrapper, |
| 266 | + to_streamed_response_wrapper, |
| 267 | + async_to_raw_response_wrapper, |
| 268 | + async_to_streamed_response_wrapper, |
| 269 | +) |
| 270 | +from .._base_client import make_request_options |
| 271 | +from ..types.retrieve_documents_response import RetrieveDocumentsResponse |
| 272 | + |
| 273 | +__all__ = ["RetrieveResource", "AsyncRetrieveResource"] |
| 274 | + |
| 275 | + |
| 276 | +class RetrieveResource(SyncAPIResource): |
| 277 | + @cached_property |
| 278 | + def with_raw_response(self) -> RetrieveResourceWithRawResponse: |
| 279 | + """ |
| 280 | + This property can be used as a prefix for any HTTP method call to return |
| 281 | + the raw response object instead of the parsed content. |
| 282 | +
|
| 283 | + For more information, see https://www.github.com/digitalocean/gradient-python#accessing-raw-response-data-eg-headers |
| 284 | + """ |
| 285 | + return RetrieveResourceWithRawResponse(self) |
| 286 | + |
| 287 | + @cached_property |
| 288 | + def with_streaming_response(self) -> RetrieveResourceWithStreamingResponse: |
| 289 | + """ |
| 290 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 291 | +
|
| 292 | + For more information, see https://www.github.com/digitalocean/gradient-python#with_streaming_response |
| 293 | + """ |
| 294 | + return RetrieveResourceWithStreamingResponse(self) |
| 295 | + |
| 296 | + def documents( |
| 297 | + self, |
| 298 | + knowledge_base_id: str, |
| 299 | + *, |
| 300 | + num_results: int, |
| 301 | + query: str, |
| 302 | + alpha: float | Omit = omit, |
| 303 | + filters: retrieve_documents_params.Filters | Omit = omit, |
| 304 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 305 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 306 | + extra_headers: Headers | None = None, |
| 307 | + extra_query: Query | None = None, |
| 308 | + extra_body: Body | None = None, |
| 309 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 310 | + ) -> RetrieveDocumentsResponse: |
| 311 | + """ |
| 312 | + Retrieve relevant documents from a knowledge base using semantic search. |
| 313 | +
|
| 314 | + This endpoint: |
| 315 | +
|
| 316 | + 1. Authenticates the request using the provided bearer token |
| 317 | + 2. Generates embeddings for the query using the knowledge base's configured |
| 318 | + model |
| 319 | + 3. Performs vector similarity search in the knowledge base |
| 320 | + 4. Returns the most relevant document chunks |
| 321 | +
|
| 322 | + Args: |
| 323 | + num_results: Number of results to return |
| 324 | +
|
| 325 | + query: The search query text |
| 326 | +
|
| 327 | + alpha: |
| 328 | + Weight for hybrid search (0-1): |
| 329 | +
|
| 330 | + - 0 = pure keyword search (BM25) |
| 331 | + - 1 = pure vector search (default) |
| 332 | + - 0.5 = balanced hybrid search |
| 333 | +
|
| 334 | + filters: Metadata filters to apply to the search |
| 335 | +
|
| 336 | + extra_headers: Send extra headers |
| 337 | +
|
| 338 | + extra_query: Add additional query parameters to the request |
| 339 | +
|
| 340 | + extra_body: Add additional JSON properties to the request |
| 341 | +
|
| 342 | + timeout: Override the client-level default timeout for this request, in seconds |
| 343 | + """ |
| 344 | + if not knowledge_base_id: |
| 345 | + raise ValueError(f"Expected a non-empty value for `knowledge_base_id` but received {knowledge_base_id!r}") |
| 346 | + return self._post( |
| 347 | + f"/{knowledge_base_id}/retrieve" |
| 348 | + if self._client._base_url_overridden |
| 349 | + else f"https://kbaas.do-ai.run/v1/{knowledge_base_id}/retrieve", |
| 350 | + body=maybe_transform( |
| 351 | + { |
| 352 | + "num_results": num_results, |
| 353 | + "query": query, |
| 354 | + "alpha": alpha, |
| 355 | + "filters": filters, |
| 356 | + }, |
| 357 | + retrieve_documents_params.RetrieveDocumentsParams, |
| 358 | + ), |
| 359 | + options=make_request_options( |
| 360 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 361 | + ), |
| 362 | + cast_to=RetrieveDocumentsResponse, |
| 363 | + ) |
| 364 | + |
| 365 | + |
| 366 | +class AsyncRetrieveResource(AsyncAPIResource): |
| 367 | + @cached_property |
| 368 | + def with_raw_response(self) -> AsyncRetrieveResourceWithRawResponse: |
| 369 | + """ |
| 370 | + This property can be used as a prefix for any HTTP method call to return |
| 371 | + the raw response object instead of the parsed content. |
| 372 | +
|
| 373 | + For more information, see https://www.github.com/digitalocean/gradient-python#accessing-raw-response-data-eg-headers |
| 374 | + """ |
| 375 | + return AsyncRetrieveResourceWithRawResponse(self) |
| 376 | + |
| 377 | + @cached_property |
| 378 | + def with_streaming_response(self) -> AsyncRetrieveResourceWithStreamingResponse: |
| 379 | + """ |
| 380 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 381 | +
|
| 382 | + For more information, see https://www.github.com/digitalocean/gradient-python#with_streaming_response |
| 383 | + """ |
| 384 | + return AsyncRetrieveResourceWithStreamingResponse(self) |
| 385 | + |
| 386 | + async def documents( |
| 387 | + self, |
| 388 | + knowledge_base_id: str, |
| 389 | + *, |
| 390 | + num_results: int, |
| 391 | + query: str, |
| 392 | + alpha: float | Omit = omit, |
| 393 | + filters: retrieve_documents_params.Filters | Omit = omit, |
| 394 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 395 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 396 | + extra_headers: Headers | None = None, |
| 397 | + extra_query: Query | None = None, |
| 398 | + extra_body: Body | None = None, |
| 399 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 400 | + ) -> RetrieveDocumentsResponse: |
| 401 | + """ |
| 402 | + Retrieve relevant documents from a knowledge base using semantic search. |
| 403 | +
|
| 404 | + This endpoint: |
| 405 | +
|
| 406 | + 1. Authenticates the request using the provided bearer token |
| 407 | + 2. Generates embeddings for the query using the knowledge base's configured |
| 408 | + model |
| 409 | + 3. Performs vector similarity search in the knowledge base |
| 410 | + 4. Returns the most relevant document chunks |
| 411 | +
|
| 412 | + Args: |
| 413 | + num_results: Number of results to return |
| 414 | +
|
| 415 | + query: The search query text |
| 416 | +
|
| 417 | + alpha: |
| 418 | + Weight for hybrid search (0-1): |
| 419 | +
|
| 420 | + - 0 = pure keyword search (BM25) |
| 421 | + - 1 = pure vector search (default) |
| 422 | + - 0.5 = balanced hybrid search |
| 423 | +
|
| 424 | + filters: Metadata filters to apply to the search |
| 425 | +
|
| 426 | + extra_headers: Send extra headers |
| 427 | +
|
| 428 | + extra_query: Add additional query parameters to the request |
| 429 | +
|
| 430 | + extra_body: Add additional JSON properties to the request |
| 431 | +
|
| 432 | + timeout: Override the client-level default timeout for this request, in seconds |
| 433 | + """ |
| 434 | + if not knowledge_base_id: |
| 435 | + raise ValueError(f"Expected a non-empty value for `knowledge_base_id` but received {knowledge_base_id!r}") |
| 436 | + return await self._post( |
| 437 | + f"/{knowledge_base_id}/retrieve" |
| 438 | + if self._client._base_url_overridden |
| 439 | + else f"https://kbaas.do-ai.run/v1/{knowledge_base_id}/retrieve", |
| 440 | + body=await async_maybe_transform( |
| 441 | + { |
| 442 | + "num_results": num_results, |
| 443 | + "query": query, |
| 444 | + "alpha": alpha, |
| 445 | + "filters": filters, |
| 446 | + }, |
| 447 | + retrieve_documents_params.RetrieveDocumentsParams, |
| 448 | + ), |
| 449 | + options=make_request_options( |
| 450 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 451 | + ), |
| 452 | + cast_to=RetrieveDocumentsResponse, |
| 453 | + ) |
| 454 | + |
| 455 | + |
| 456 | +class RetrieveResourceWithRawResponse: |
| 457 | + def __init__(self, retrieve: RetrieveResource) -> None: |
| 458 | + self._retrieve = retrieve |
| 459 | + |
| 460 | + self.documents = to_raw_response_wrapper( |
| 461 | + retrieve.documents, |
| 462 | + ) |
| 463 | + |
| 464 | + |
| 465 | +class AsyncRetrieveResourceWithRawResponse: |
| 466 | + def __init__(self, retrieve: AsyncRetrieveResource) -> None: |
| 467 | + self._retrieve = retrieve |
| 468 | + |
| 469 | + self.documents = async_to_raw_response_wrapper( |
| 470 | + retrieve.documents, |
| 471 | + ) |
| 472 | + |
| 473 | + |
| 474 | +class RetrieveResourceWithStreamingResponse: |
| 475 | + def __init__(self, retrieve: RetrieveResource) -> None: |
| 476 | + self._retrieve = retrieve |
| 477 | + |
| 478 | + self.documents = to_streamed_response_wrapper( |
| 479 | + retrieve.documents, |
| 480 | + ) |
| 481 | + |
| 482 | + |
| 483 | +class AsyncRetrieveResourceWithStreamingResponse: |
| 484 | + def __init__(self, retrieve: AsyncRetrieveResource) -> None: |
| 485 | + self._retrieve = retrieve |
| 486 | + |
| 487 | + self.documents = async_to_streamed_response_wrapper( |
| 488 | + retrieve.documents, |
| 489 | + ) |
| 490 | +>>>>>>> 8b48985 (feat(api): manual updates) |
0 commit comments