mirror of
https://github.com/mcp-use/mcp-use.git
synced 2026-09-14 18:06:01 +08:00
39e85c8c25
* feat(python): accept HumanMessage queries and move file input into messages * use image as example * restore remote.py Signed-off-by: Salvatore Gabriele Karra <86735558+gabrielekarra@users.noreply.github.com> * lint * fix example in docs - create example * update docs * remove tests --------- Signed-off-by: Salvatore Gabriele Karra <86735558+gabrielekarra@users.noreply.github.com> Co-authored-by: pietrozullo <pietro.zullo@gmail.com>
36 lines
833 B
Python
36 lines
833 B
Python
import asyncio
|
|
import base64
|
|
from pathlib import Path
|
|
|
|
from langchain_core.messages import HumanMessage
|
|
from langchain_openai import ChatOpenAI
|
|
|
|
from mcp_use import MCPAgent, MCPClient
|
|
|
|
|
|
async def main():
|
|
client = MCPClient()
|
|
agent = MCPAgent(
|
|
llm=ChatOpenAI(model_name="gpt-5"),
|
|
client=client,
|
|
)
|
|
|
|
image_bytes = base64.b64encode(Path("static/logo-gh.jpg").read_bytes()).decode("utf-8")
|
|
human_message = HumanMessage(
|
|
content=[
|
|
{"type": "text", "text": "What is in this image?"},
|
|
{
|
|
"type": "image",
|
|
"base64": image_bytes,
|
|
"mime_type": "image/jpeg",
|
|
},
|
|
]
|
|
)
|
|
|
|
async for step in agent.stream(human_message, max_steps=10):
|
|
print(step)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|