mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-10-05 12:28:22 +00:00
clean up
This commit is contained in:
@@ -140,9 +140,6 @@ async def _openai_chunks_to_anthropic_events(
|
||||
next_block_idx = 0
|
||||
final_finish_reason: str | None = None
|
||||
final_usage: dict[str, int] = {"input_tokens": 0, "output_tokens": 0}
|
||||
chunks_seen = 0
|
||||
chunks_with_usage = 0
|
||||
last_chunk_preview: str | None = None
|
||||
|
||||
def open_text_block() -> bytes:
|
||||
nonlocal text_block_idx, next_block_idx
|
||||
@@ -199,9 +196,6 @@ async def _openai_chunks_to_anthropic_events(
|
||||
if not isinstance(chunk, dict):
|
||||
continue
|
||||
|
||||
chunks_seen += 1
|
||||
last_chunk_preview = payload[:500]
|
||||
|
||||
if not started:
|
||||
started = True
|
||||
yield _sse_event(
|
||||
@@ -224,18 +218,14 @@ async def _openai_chunks_to_anthropic_events(
|
||||
},
|
||||
)
|
||||
|
||||
print(f"[gemini-compat upstream chunk] {payload[:1000]}", flush=True)
|
||||
|
||||
usage = chunk.get("usage")
|
||||
if isinstance(usage, dict):
|
||||
chunks_with_usage += 1
|
||||
in_tok = usage.get("prompt_tokens") or usage.get("input_tokens") or 0
|
||||
out_tok = usage.get("completion_tokens") or usage.get("output_tokens") or 0
|
||||
if in_tok:
|
||||
final_usage["input_tokens"] = int(in_tok)
|
||||
if out_tok:
|
||||
final_usage["output_tokens"] = int(out_tok)
|
||||
print(f"[gemini-compat usage chunk] {usage}", flush=True)
|
||||
|
||||
choices = chunk.get("choices") or []
|
||||
if not choices:
|
||||
@@ -294,16 +284,6 @@ async def _openai_chunks_to_anthropic_events(
|
||||
for block_idx in tool_block_indices.values():
|
||||
yield close_block(block_idx)
|
||||
|
||||
print(
|
||||
f"[gemini-compat stream done] chunks_seen={chunks_seen} "
|
||||
f"chunks_with_usage={chunks_with_usage} "
|
||||
f"input_tokens={final_usage['input_tokens']} "
|
||||
f"output_tokens={final_usage['output_tokens']} "
|
||||
f"finish_reason={final_finish_reason} "
|
||||
f"last_chunk={last_chunk_preview}",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
# message_delta with stop_reason and usage
|
||||
stop_reason = _FINISH_TO_STOP.get(final_finish_reason or "", "end_turn")
|
||||
yield _sse_event(
|
||||
@@ -460,12 +440,6 @@ async def dispatch_gemini_messages(
|
||||
**(log_extra or {}),
|
||||
},
|
||||
)
|
||||
print(
|
||||
f"[gemini-compat outgoing] model={upstream_model} "
|
||||
f"stream_options={openai_kwargs.get('stream_options')} "
|
||||
f"reasoning_effort={openai_kwargs.get('reasoning_effort')}",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
http_client, response = await _post_and_stream(
|
||||
base_url, api_key, openai_kwargs, log_extra
|
||||
|
||||
Reference in New Issue
Block a user