Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 74 additions & 68 deletions docs/en/development/pydantic-ai-inference.md

Large diffs are not rendered by default.

275 changes: 50 additions & 225 deletions docs/en/docs/operate/observability.md

Large diffs are not rendered by default.

133 changes: 74 additions & 59 deletions docs/zh/development/pydantic-ai-inference.md

Large diffs are not rendered by default.

234 changes: 46 additions & 188 deletions docs/zh/docs/operate/observability.md

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions e2e/bub/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions evaluation/memory/locomo/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from time import perf_counter
from typing import Any, Literal, TypeVar, cast

import httpx
import httpx2
from dotenv import load_dotenv
from pydantic import AnyHttpUrl, BaseModel, ConfigDict, Field, SecretStr
from pydantic_ai.messages import ModelMessage, ModelResponse
Expand Down Expand Up @@ -614,7 +614,7 @@ async def evaluate_dataset( # noqa: C901
async with AsyncExitStack() as resources:
reranker: MemoryReranker | None = None
if rerank_mode == "jev":
jev_client = await resources.enter_async_context(httpx.AsyncClient())
jev_client = await resources.enter_async_context(httpx2.AsyncClient())
reranker = JevMemoryReranker(_jev_config(), jev_client)
elif rerank_mode == MemoryRerankMode.LLM and answer_max_bytes is not None:
inference = settings.inference
Expand Down
41 changes: 24 additions & 17 deletions evaluation/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ async def before_model_request(
request_context,
messages=_without_powercontext_context(request_context.messages),
)
# Request-only replacements no longer update the history used by later tool steps.
ctx.messages[:] = _without_powercontext_context(ctx.messages)
if not query:
return request_context

Expand All @@ -146,6 +148,7 @@ async def before_model_request(
run_id=ctx.run_id,
conversation_id=ctx.conversation_id,
)
ctx.messages.insert(0, context_request)
Comment thread
PsiACE marked this conversation as resolved.
Resolved
return replace(request_context, messages=[context_request, *request_context.messages])

@override
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ builtin = [
"cryptography>=46,<51",
"filelock>=3.16,<4",
"httpx>=0.28,<1",
"httpx2>=2.7,<3",
"jieba==0.42.1",
"packaging>=24,<27",
"pydantic-ai-slim[anthropic,openai]>=2.27.1,<3",
"pydantic-ai-slim[anthropic,openai]>=2.64.0,<3",
Comment thread
PsiACE marked this conversation as resolved.
Resolved
"pydantic-settings>=2.7,<3",
"pyyaml>=6,<7",
"pycasbin>=2.8,<3",
Expand Down Expand Up @@ -142,6 +143,7 @@ resource-build = [
"click>=8.1,<9",
"filelock>=3.16,<4",
"httpx>=0.28,<1",
"httpx2>=2.7,<3",
"jsonschema>=4.23,<5",
"opentelemetry-api>=1.30,<2",
"opentelemetry-sdk>=1.30,<2",
Expand Down
22 changes: 11 additions & 11 deletions src/powercontext/builtin/artifacts/memory/jev_reranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from collections.abc import Coroutine, Iterable
from typing import Literal, Self

import httpx
import httpx2
from pydantic import BaseModel, ConfigDict, Field, SecretStr, model_validator

from powercontext.builtin.artifacts.memory.reranking import (
Expand Down Expand Up @@ -72,7 +72,7 @@ class JevRerankConfig(BaseModel):

@model_validator(mode="after")
def validate_endpoint_and_model(self) -> Self:
url = httpx.URL(self.endpoint)
url = httpx2.URL(self.endpoint)
if (
url.scheme not in {"http", "https"}
or not url.host
Expand Down Expand Up @@ -112,7 +112,7 @@ class _JevResponse(BaseModel):
usage: _JevUsage


def _http_failure(error: httpx.HTTPStatusError, timeout_seconds: float) -> InferenceError:
def _http_failure(error: httpx2.HTTPStatusError, timeout_seconds: float) -> InferenceError:
status = error.response.status_code
if status in {408, 504}:
return InferenceTimeoutError("memory.rerank", timeout_seconds)
Expand Down Expand Up @@ -188,7 +188,7 @@ class JevMemoryReranker:
def __init__(
self,
config: JevRerankConfig,
client: httpx.AsyncClient | None = None,
client: httpx2.AsyncClient | None = None,
*,
protection: InferenceProtectionConfig | None = None,
) -> None:
Expand All @@ -199,13 +199,13 @@ def __init__(

if client is not None:
raise InferenceConfigurationError("protected Jev reranking requires an owned HTTP transport") # noqa: TRY003
self._client = httpx.AsyncClient(
self._client = httpx2.AsyncClient(
transport=ProtectedAsyncTransport(protection),
follow_redirects=False,
headers={"Accept-Encoding": "identity"},
)
else:
self._client = client if client is not None else httpx.AsyncClient(follow_redirects=False)
self._client = client if client is not None else httpx2.AsyncClient(follow_redirects=False)
self._semaphore = asyncio.Semaphore(config.max_concurrency)
self.policy_id = f"{JEV_MEMORY_RERANK_POLICY}:{config.model}"

Expand Down Expand Up @@ -233,15 +233,15 @@ async def score(candidate: MemoryRerankText) -> float:
if len(content) > self._config.max_request_bytes:
raise InferenceConfigurationError("Jev rerank request exceeds max_request_bytes") # noqa: TRY003
async with self._semaphore:
request = httpx.Request(
request = httpx2.Request(
"POST",
self._config.endpoint,
content=content,
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {self._config.api_key.get_secret_value()}",
},
extensions={"timeout": httpx.Timeout(self._config.timeout_seconds).as_dict()},
extensions={"timeout": httpx2.Timeout(self._config.timeout_seconds).as_dict()},
)
response = await self._client.send(request, auth=None, follow_redirects=False)
response.raise_for_status()
Expand All @@ -256,11 +256,11 @@ async def score(candidate: MemoryRerankText) -> float:
(score(candidate) for candidate in candidates), usages, self._config.timeout_seconds
)
ranks = tuple(sorted(range(1, len(candidates) + 1), key=lambda rank: (-scores[rank - 1], rank))[:limit])
except (TimeoutError, httpx.TimeoutException) as error:
except (TimeoutError, httpx2.TimeoutException) as error:
raise InferenceTimeoutError("memory.rerank", self._config.timeout_seconds) from error
except httpx.HTTPStatusError as error:
except httpx2.HTTPStatusError as error:
raise _http_failure(error, self._config.timeout_seconds) from error
except (httpx.RequestError, OSError) as error:
except (httpx2.RequestError, OSError) as error:
raise InferenceUnavailableError("memory.rerank") from error
except (ValueError, KeyError, TypeError) as error:
raise InvalidInferenceOutputError("memory.rerank", "Jev did not return a valid result") from error
Expand Down
Loading
Loading