Skip to content

Commit 5125e5a

Browse files
committed
take out litellm
1 parent 8cb080c commit 5125e5a

3 files changed

Lines changed: 39 additions & 40 deletions

File tree

eval_protocol/pytest/remote_rollout_processor.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import requests
66

7-
from eval_protocol.models import EvaluationRow
7+
from eval_protocol.models import EvaluationRow, Status
88
from eval_protocol.data_loader.dynamic_data_loader import DynamicDataLoader
99
from .rollout_processor import RolloutProcessor
1010
from .types import RolloutProcessorConfig
@@ -167,12 +167,15 @@ def _load_data():
167167

168168
output_rows: List[EvaluationRow] = [row for result in results for row in result.rows]
169169

170-
assert len(output_rows) == 1, "Dataloader used for RemoteRolloutProcessor should have exactly one row"
171-
172-
langfuse_row = output_rows[0]
173-
langfuse_row.input_metadata.completion_params = row.input_metadata.completion_params
174-
175-
return langfuse_row
170+
if len(output_rows) == 0: # Fallback to original row if no Langfuse data found
171+
row.rollout_status = Status(code=Status.Code.NOT_FOUND, message="No Langfuse data found for rollout")
172+
return row
173+
elif len(output_rows) == 1: # Return the Langfuse row
174+
langfuse_row = output_rows[0]
175+
langfuse_row.input_metadata.completion_params = row.input_metadata.completion_params
176+
return langfuse_row
177+
else:
178+
raise ValueError("RemoteRolloutProcessor's output_data_loader should return exactly one row.")
176179

177180
for r in rows:
178181
tasks.append(asyncio.create_task(_process_row(r)))

tests/chinook/langfuse/remote_server.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import uvicorn
66
from fastapi import FastAPI, HTTPException
77
from pydantic import BaseModel
8-
import requests
8+
from langfuse.openai import openai # pyright: ignore[reportPrivateImportUsage]
99

1010

1111
app = FastAPI()
@@ -42,52 +42,50 @@ def init(req: InitRequest):
4242
# Persist state
4343
_STATE[req.rollout_id] = {"terminated": False}
4444

45-
# Kick off worker thread that runs multi-turn chat via LiteLLM proxy
45+
# Kick off worker thread that runs multi-turn chat via Langfuse OpenAI integration
4646
def _worker():
4747
try:
48-
base_url = os.getenv(
49-
"LITELLM_BASE_URL",
50-
"https://litellm-cloud-proxy-prod-644257448872.us-central1.run.app",
51-
)
52-
url = f"{base_url}/v1/chat/completions"
53-
headers = {
54-
"Authorization": f"Bearer {os.getenv('FIREWORKS_API_KEY', '')}",
55-
"Content-Type": "application/json",
56-
}
57-
58-
# Prepare metadata payload to attach for Langfuse filtering
48+
# Prepare tags for Langfuse filtering
5949
metadata = {
60-
"tags": [
50+
"langfuse_tags": [
6151
f"invocation_id:{req.metadata.get('invocation_id')}",
6252
f"experiment_id:{req.metadata.get('experiment_id')}",
6353
f"rollout_id:{req.metadata.get('rollout_id')}",
6454
f"run_id:{req.metadata.get('run_id')}",
6555
f"row_id:{req.metadata.get('row_id')}",
66-
],
67-
"invocation_id": req.metadata.get("invocation_id"),
68-
"experiment_id": req.metadata.get("experiment_id"),
69-
"rollout_id": req.metadata.get("rollout_id"),
70-
"run_id": req.metadata.get("run_id"),
71-
"row_id": req.metadata.get("row_id"),
56+
]
7257
}
7358

7459
messages = req.messages
7560

7661
# Simulate N-1 assistant turns (single-shot or simple echo)
7762
for _ in range(max(1, req.num_turns)):
78-
payload = {
63+
completion_kwargs = {
7964
"model": req.model,
8065
"messages": _clean_messages_for_api(messages),
8166
"metadata": metadata,
8267
}
68+
8369
if req.tools:
84-
payload["tools"] = req.tools
85-
r = requests.post(url, json=payload, headers=headers, timeout=60)
86-
r.raise_for_status()
87-
data = r.json()
88-
assistant = data.get("choices", [{}])[0].get("message", {})
70+
completion_kwargs["tools"] = req.tools
71+
72+
completion = openai.chat.completions.create(**completion_kwargs)
73+
assistant_message = completion.choices[0].message
74+
75+
# Convert to dict format for next turn
76+
assistant_dict = {"role": "assistant", "content": assistant_message.content}
77+
if assistant_message.tool_calls:
78+
assistant_dict["tool_calls"] = [
79+
{
80+
"id": tc.id,
81+
"type": tc.type,
82+
"function": {"name": tc.function.name, "arguments": tc.function.arguments},
83+
}
84+
for tc in assistant_message.tool_calls
85+
]
86+
8987
# Append assistant for next turn
90-
messages = messages + [assistant]
88+
messages = messages + [assistant_dict]
9189

9290
except Exception:
9391
# Best-effort; mark as done even on error to unblock polling

tests/chinook/langfuse/test_remote_langfuse_chinook.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ def check_rollout_coverage():
2525
ROLLOUT_IDS.clear()
2626
yield
2727

28-
# Verify we've seen the expected number of rollout_ids after test is done
29-
expected_rollout_count = 3
30-
assert len(ROLLOUT_IDS) == expected_rollout_count, (
31-
f"Expected to see {expected_rollout_count} rollout_ids, but only saw {len(ROLLOUT_IDS)}: {ROLLOUT_IDS}"
32-
)
28+
assert len(ROLLOUT_IDS) == 3, f"Expected to see {ROLLOUT_IDS} rollout_ids, but only saw {ROLLOUT_IDS}"
3329

3430

3531
def fetch_langfuse_traces(rollout_id: str) -> List[EvaluationRow]:
@@ -95,7 +91,7 @@ def remote_langfuse_data_generator() -> List[EvaluationRow]:
9591

9692

9793
@pytest.mark.skipif(os.environ.get("CI") == "true", reason="Only run this test locally (skipped in CI)")
98-
@pytest.mark.parametrize("completion_params", [{"model": "fireworks_ai/accounts/fireworks/models/kimi-k2-instruct"}])
94+
@pytest.mark.parametrize("completion_params", [{"model": "gpt-4o"}])
9995
@evaluation_test(
10096
data_loaders=DynamicDataLoader(
10197
generators=[remote_langfuse_data_generator],
@@ -115,6 +111,8 @@ async def test_remote_rollout_and_fetch_langfuse(row: EvaluationRow) -> Evaluati
115111
- fetch traces from Langfuse filtered by metadata via output_data_loader; FAIL if none found
116112
"""
117113
assert row.messages[0].content == "Hello there! Please say hi back.", "Row should have correct message content"
114+
assert len(row.messages) > 1, "Row should have a response. If this fails, we fellback to the original row."
115+
118116
assert row.execution_metadata.rollout_id in ROLLOUT_IDS, (
119117
f"Row rollout_id {row.execution_metadata.rollout_id} should be in tracked rollout_ids: {ROLLOUT_IDS}"
120118
)

0 commit comments

Comments
 (0)