-
Notifications
You must be signed in to change notification settings - Fork 16
klavis MCP #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
klavis MCP #312
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"messages": [ { "role": "system", "content": "You are a helpful assistant that can answer questions about Gmail. You have access to tools to help you find information." }, { "role": "user", "content": "Find the first 5 emails title in my inbox." } ], "ground_truth": "The first 5 emails contain meeting between Benny and Zheng"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| { | ||
| "mcpServers": { | ||
| "klavis-strata": { | ||
| "url": "https://strata.klavis.ai/mcp/", | ||
| "authorization": "Bearer ${KLAVIS_API_KEY}" | ||
| } | ||
| "klavis-strata": { | ||
| "url": "https://strata.klavis.ai/mcp/", | ||
| "authorization": "Bearer ${KLAVIS_API_KEY}" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,54 @@ | ||
| from eval_protocol.models import EvaluateResult, EvaluationRow, Message | ||
| from eval_protocol.pytest import AgentRolloutProcessor, evaluation_test | ||
| from openai import AsyncOpenAI | ||
| import json | ||
| from pydantic import BaseModel | ||
| import logging | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
| import os | ||
|
|
||
|
|
||
| class ResponseFormat(BaseModel): | ||
| score: float | ||
|
|
||
|
|
||
| @evaluation_test( | ||
| input_messages=[ | ||
| [ | ||
| [ | ||
| Message( | ||
| role="system", | ||
| content=( | ||
| "You are a helpful assistant that can answer questions about Gmail. You have access to tools to help you find information.\n" | ||
| ), | ||
| ), | ||
| Message( | ||
| role="user", | ||
| content=("Find the first 5 emails title in my inbox."), | ||
| ), | ||
| ] | ||
| ] | ||
| ], | ||
| input_dataset=["tests/pytest/datasets/gmail_inbox.jsonl"], | ||
| rollout_processor=AgentRolloutProcessor(), | ||
| completion_params=[{"model": "fireworks_ai/accounts/fireworks/models/kimi-k2-instruct"}], | ||
| mode="pointwise", | ||
| mcp_config_path="tests/pytest/mcp_configurations/klavis_strata_mcp.json", | ||
| ) | ||
| def test_pytest_klavis_mcp(row: EvaluationRow) -> EvaluationRow: | ||
| # filter for all tool calls | ||
| tool_calls = [msg for msg in row.messages if msg.role == "tool"] | ||
| if len(tool_calls) == 0: | ||
| async def test_pytest_klavis_mcp(row: EvaluationRow) -> EvaluationRow: | ||
| ground_truth = row.ground_truth | ||
| # check if the final messages contains the ground truth | ||
|
|
||
| async with AsyncOpenAI( | ||
| api_key=os.environ["FIREWORKS_API_KEY"], base_url="https://api.fireworks.ai/inference/v1" | ||
| ) as client: | ||
| response = await client.chat.completions.create( | ||
| model="accounts/fireworks/models/kimi-k2-instruct-0905", | ||
| messages=[ | ||
| { | ||
| "role": "system", | ||
| "content": "You are judging the output of the model versus the ground truth. Return score = 1 if the output contains the ground truth, 0 otherwise.", | ||
| }, | ||
| { | ||
| "role": "user", | ||
| "content": "Final model output: {row.messages[-1].content}\nGround truth: {ground_truth}", | ||
| }, | ||
|
benjibc marked this conversation as resolved.
|
||
| ], | ||
| response_format={ | ||
| "type": "json_schema", | ||
| "json_schema": {"name": "ResponseFormat", "schema": ResponseFormat.model_json_schema()}, | ||
| }, | ||
| ) | ||
| response_text = response.choices[0].message.content | ||
| logger.info("response_text: %s", response_text) | ||
| score = json.loads(response_text or "{}")["score"] | ||
| row.evaluation_result = EvaluateResult( | ||
| score=0, | ||
| reason="No tool calls made", | ||
| score=score, | ||
| reason=response_text, | ||
| ) | ||
| return row | ||
|
|
||
| row.evaluation_result = EvaluateResult( | ||
| score=1, | ||
| reason="At least one tool call was made", | ||
| ) | ||
| return row | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Missing Prefix Causes Placeholder Interpolation Failure
The user message's content string is missing the
fprefix, so the{row.messages[-1].content}and{ground_truth}placeholders are not interpolated. This sends literal text to the API, preventing the LLM judge from receiving the correct data for evaluation.