-
Notifications
You must be signed in to change notification settings - Fork 354
PoC: InferenceClient
is also a McpClient
#1351
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
Conversation
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.
huggingface/huggingface_hub#2986 few of my comments there are also relevant here. Probably major one is I think you could add SSE support quite easily.
Also very minor but first time I see typescript with 4 indents, but why not.
It uses tabs, you can set your tab width to whatever you want :) (2, 4 or 8) |
Ah the good old tab vs space conundrum then :) |
At this point we should let LLMs decide between tabs and spaces once and for all |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Ok this is ready for review! Note, there's now a small cd packages/mcp-client
pnpm run agent |
Not sure I am using this the expected way but I had to tweak a bit to run
"devDependencies": {
"@huggingface/hub": "workspace:^",
"ts-node": "^10.9.2",
"typescript": "^5.8.3",
"zod": "^3.24.3"
}
command: "pnpm",
args: ["run", "hf-mcp"],
Then with everything setup I ran
(yup, not very inspired here) => resulting in https://huggingface.co/spaces/Wauplin/list-huggingface.js-packages Some random feedback:
|
export interface ChatCompletionInputMessageTool extends ChatCompletionInputMessage { | ||
role: "tool"; | ||
tool_call_id: string; | ||
content: string; | ||
name?: string; | ||
} |
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.
missing type in our spec probably @hanouticelina
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.
isn't that ChatCompletionOutputTextMessage ?
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.
well:
- it's not in our generated types (inference.ts)
- and it's weird to me to use a output message type as an input message
wdyt?
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.
ok ok you're right, I'd rather define another type indeed, but I'd keep this type defined here instead of putting it in our specs if that's okay for you
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.
yes that works
InferenceClient
is also a MCPClient
InferenceClient
is also a McpClient
role: "tool", | ||
tool_call_id: toolCall.id, | ||
content: "", | ||
name: toolName, |
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.
do we need to include the tool name here?
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.
maybe not for the LLM inference, but i'm using it in my agent's outer loop (in cli.ts) and i think it can't hurt anyways
Required reading
https://modelcontextprotocol.io/quickstart/client
TL;DR: MCP is a standard API to expose sets of Tools that can be hooked to LLMs
Summary of how to use this
You can either use McpClient, or you can run an example Agent directly:
Tiny Agent
We now have a tiny Agent (a while loop, really) in this PR, built on top of the MCP Client. You can run it like this:
cd packages/mcp-client pnpm run agent
McpClient
i.e. the underlying classVariant where we call a custom, local MCP server
Where to find the MCP Server used here as an example
https://gist.github.com/julien-c/0500ba922e1b38f2dc30447fb81f7dc6
(Note that you can replace it with any MCP Server, from this doc for instance: https://modelcontextprotocol.io/examples)
Python version
Python version will be implemented in
huggingface_hub
in this PR: huggingface/huggingface_hub#2986Contributions are welcome!