Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

client.py 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from mcp.client.session import ClientSession
  17. from mcp.client.sse import sse_client
  18. async def main():
  19. try:
  20. async with sse_client("http://localhost:9382/sse", headers={"api_key": "ragflow-IyMGI1ZDhjMTA2ZTExZjBiYTMyMGQ4Zm"}) as streams:
  21. async with ClientSession(
  22. streams[0],
  23. streams[1],
  24. ) as session:
  25. await session.initialize()
  26. tools = await session.list_tools()
  27. print(f"{tools.tools=}")
  28. response = await session.call_tool(name="ragflow_retrival", arguments={"dataset_ids": ["ce3bb17cf27a11efa69751e139332ced"], "document_ids": [], "question": "How to install neovim?"})
  29. print(f"Tool response: {response.model_dump()}")
  30. except Exception as e:
  31. print(e)
  32. if __name__ == "__main__":
  33. from anyio import run
  34. run(main)