- harness/es.py: append-only event store + проекции (образец — кооп-портал) - harness/levels.py: уровни 1с/1м/1ч/1д, контекст ∝ масштабу - harness/scheduler.py: уровневые потоки, идемпотентные тики, absorbed-стабы - harness/isolated_runner.py + _llm_worker.py: LLM-тик в сабпроцессе (глобальный asyncio-рантайм Strands не переживает 2+ create_harness) - cli.py: init/task/tasks/status/events + requeue (написан самим минутным агентом) - 9router: отдельный ключ sk-simbiot, модель auto (glm-5.3 первым)
263 lines
11 KiB
Python
263 lines
11 KiB
Python
# File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Union, Iterable
|
|
from functools import partial
|
|
from typing_extensions import Literal
|
|
|
|
import httpx2
|
|
|
|
from .. import _legacy_response
|
|
from ..types import embedding_create_params
|
|
from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given
|
|
from .._utils import is_given, maybe_transform
|
|
from .._compat import cached_property
|
|
from .._resource import SyncAPIResource, AsyncAPIResource
|
|
from .._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
|
|
from .._base_client import make_request_options
|
|
from ..types.embedding_model import EmbeddingModel
|
|
from ..lib._parsing._embeddings import parse_embedding_response as _parse_embedding_response
|
|
from ..types.create_embedding_response import CreateEmbeddingResponse
|
|
|
|
__all__ = ["Embeddings", "AsyncEmbeddings"]
|
|
|
|
|
|
class Embeddings(SyncAPIResource):
|
|
"""
|
|
Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
|
|
"""
|
|
|
|
@cached_property
|
|
def with_raw_response(self) -> EmbeddingsWithRawResponse:
|
|
"""
|
|
This property can be used as a prefix for any HTTP method call to return
|
|
the raw response object instead of the parsed content.
|
|
|
|
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
|
|
"""
|
|
return EmbeddingsWithRawResponse(self)
|
|
|
|
@cached_property
|
|
def with_streaming_response(self) -> EmbeddingsWithStreamingResponse:
|
|
"""
|
|
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
|
|
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
|
|
"""
|
|
return EmbeddingsWithStreamingResponse(self)
|
|
|
|
def create(
|
|
self,
|
|
*,
|
|
input: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]]],
|
|
model: Union[str, EmbeddingModel],
|
|
dimensions: int | Omit = omit,
|
|
encoding_format: Literal["float", "base64"] | Omit = omit,
|
|
user: str | Omit = omit,
|
|
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
extra_headers: Headers | None = None,
|
|
extra_query: Query | None = None,
|
|
extra_body: Body | None = None,
|
|
timeout: float | httpx2.Timeout | None | NotGiven = not_given,
|
|
) -> CreateEmbeddingResponse:
|
|
"""
|
|
Creates an embedding vector representing the input text.
|
|
|
|
Args:
|
|
input: Input text to embed, encoded as a string or array of tokens. To embed multiple
|
|
inputs in a single request, pass an array of strings or array of token arrays.
|
|
The input must not exceed the max input tokens for the model (8192 tokens for
|
|
all embedding models), cannot be an empty string, and any array must be 2048
|
|
dimensions or less.
|
|
[Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
|
|
for counting tokens. In addition to the per-input token limit, all embedding
|
|
models enforce a maximum of 300,000 tokens summed across all inputs in a single
|
|
request.
|
|
|
|
model: ID of the model to use. You can use the
|
|
[List models](https://developers.openai.com/api/reference/resources/models/methods/list)
|
|
API to see all of your available models, or see our
|
|
[Model overview](https://developers.openai.com/api/docs/models) for descriptions
|
|
of them.
|
|
|
|
dimensions: The number of dimensions the resulting output embeddings should have. Only
|
|
supported in `text-embedding-3` and later models.
|
|
|
|
encoding_format: The format to return the embeddings in. Can be either `float` or
|
|
[`base64`](https://pypi.org/project/pybase64/).
|
|
|
|
user: A unique identifier representing your end-user, which can help OpenAI to monitor
|
|
and detect abuse.
|
|
[Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers).
|
|
|
|
extra_headers: Send extra headers
|
|
|
|
extra_query: Add additional query parameters to the request
|
|
|
|
extra_body: Add additional JSON properties to the request
|
|
|
|
timeout: Override the client-level default timeout for this request, in seconds
|
|
"""
|
|
params = {
|
|
"input": input,
|
|
"model": model,
|
|
"user": user,
|
|
"dimensions": dimensions,
|
|
"encoding_format": encoding_format,
|
|
}
|
|
if not is_given(encoding_format):
|
|
params["encoding_format"] = "base64"
|
|
|
|
return self._post(
|
|
"/embeddings",
|
|
body=maybe_transform(params, embedding_create_params.EmbeddingCreateParams),
|
|
options=make_request_options(
|
|
extra_headers=extra_headers,
|
|
extra_query=extra_query,
|
|
extra_body=extra_body,
|
|
timeout=timeout,
|
|
post_parser=partial(_parse_embedding_response, encoding_format=encoding_format),
|
|
security={"bearer_auth": True},
|
|
),
|
|
cast_to=CreateEmbeddingResponse,
|
|
)
|
|
|
|
|
|
class AsyncEmbeddings(AsyncAPIResource):
|
|
"""
|
|
Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
|
|
"""
|
|
|
|
@cached_property
|
|
def with_raw_response(self) -> AsyncEmbeddingsWithRawResponse:
|
|
"""
|
|
This property can be used as a prefix for any HTTP method call to return
|
|
the raw response object instead of the parsed content.
|
|
|
|
For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
|
|
"""
|
|
return AsyncEmbeddingsWithRawResponse(self)
|
|
|
|
@cached_property
|
|
def with_streaming_response(self) -> AsyncEmbeddingsWithStreamingResponse:
|
|
"""
|
|
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
|
|
For more information, see https://www.github.com/openai/openai-python#with_streaming_response
|
|
"""
|
|
return AsyncEmbeddingsWithStreamingResponse(self)
|
|
|
|
async def create(
|
|
self,
|
|
*,
|
|
input: Union[str, SequenceNotStr[str], Iterable[int], Iterable[Iterable[int]]],
|
|
model: Union[str, EmbeddingModel],
|
|
dimensions: int | Omit = omit,
|
|
encoding_format: Literal["float", "base64"] | Omit = omit,
|
|
user: str | Omit = omit,
|
|
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
extra_headers: Headers | None = None,
|
|
extra_query: Query | None = None,
|
|
extra_body: Body | None = None,
|
|
timeout: float | httpx2.Timeout | None | NotGiven = not_given,
|
|
) -> CreateEmbeddingResponse:
|
|
"""
|
|
Creates an embedding vector representing the input text.
|
|
|
|
Args:
|
|
input: Input text to embed, encoded as a string or array of tokens. To embed multiple
|
|
inputs in a single request, pass an array of strings or array of token arrays.
|
|
The input must not exceed the max input tokens for the model (8192 tokens for
|
|
all embedding models), cannot be an empty string, and any array must be 2048
|
|
dimensions or less.
|
|
[Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
|
|
for counting tokens. In addition to the per-input token limit, all embedding
|
|
models enforce a maximum of 300,000 tokens summed across all inputs in a single
|
|
request.
|
|
|
|
model: ID of the model to use. You can use the
|
|
[List models](https://developers.openai.com/api/reference/resources/models/methods/list)
|
|
API to see all of your available models, or see our
|
|
[Model overview](https://developers.openai.com/api/docs/models) for descriptions
|
|
of them.
|
|
|
|
dimensions: The number of dimensions the resulting output embeddings should have. Only
|
|
supported in `text-embedding-3` and later models.
|
|
|
|
encoding_format: The format to return the embeddings in. Can be either `float` or
|
|
[`base64`](https://pypi.org/project/pybase64/).
|
|
|
|
user: A unique identifier representing your end-user, which can help OpenAI to monitor
|
|
and detect abuse.
|
|
[Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers).
|
|
|
|
extra_headers: Send extra headers
|
|
|
|
extra_query: Add additional query parameters to the request
|
|
|
|
extra_body: Add additional JSON properties to the request
|
|
|
|
timeout: Override the client-level default timeout for this request, in seconds
|
|
"""
|
|
params = {
|
|
"input": input,
|
|
"model": model,
|
|
"user": user,
|
|
"dimensions": dimensions,
|
|
"encoding_format": encoding_format,
|
|
}
|
|
if not is_given(encoding_format):
|
|
params["encoding_format"] = "base64"
|
|
|
|
return await self._post(
|
|
"/embeddings",
|
|
body=maybe_transform(params, embedding_create_params.EmbeddingCreateParams),
|
|
options=make_request_options(
|
|
extra_headers=extra_headers,
|
|
extra_query=extra_query,
|
|
extra_body=extra_body,
|
|
timeout=timeout,
|
|
post_parser=partial(_parse_embedding_response, encoding_format=encoding_format),
|
|
security={"bearer_auth": True},
|
|
),
|
|
cast_to=CreateEmbeddingResponse,
|
|
)
|
|
|
|
|
|
class EmbeddingsWithRawResponse:
|
|
def __init__(self, embeddings: Embeddings) -> None:
|
|
self._embeddings = embeddings
|
|
|
|
self.create = _legacy_response.to_raw_response_wrapper(
|
|
embeddings.create,
|
|
)
|
|
|
|
|
|
class AsyncEmbeddingsWithRawResponse:
|
|
def __init__(self, embeddings: AsyncEmbeddings) -> None:
|
|
self._embeddings = embeddings
|
|
|
|
self.create = _legacy_response.async_to_raw_response_wrapper(
|
|
embeddings.create,
|
|
)
|
|
|
|
|
|
class EmbeddingsWithStreamingResponse:
|
|
def __init__(self, embeddings: Embeddings) -> None:
|
|
self._embeddings = embeddings
|
|
|
|
self.create = to_streamed_response_wrapper(
|
|
embeddings.create,
|
|
)
|
|
|
|
|
|
class AsyncEmbeddingsWithStreamingResponse:
|
|
def __init__(self, embeddings: AsyncEmbeddings) -> None:
|
|
self._embeddings = embeddings
|
|
|
|
self.create = async_to_streamed_response_wrapper(
|
|
embeddings.create,
|
|
)
|