Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/cghll_ai-agent-scaffold.json
T

1 line
24 KiB
JSON
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "cghll/ai-agent-scaffold", "files": {"ai-agent-scaffold-app/src/test/java/com/gduf/test/api/tool/SpringAiToolTest.java": {"2d3b77e6973599c53c068217136b636f7c407e9a": {"t": 1785746128.3400693, "n": 2741, "h": "e8e6f3866bc4a1ef", "c": "package com.gduf.test.api.tool;\n\nimport io.modelcontextprotocol.client.McpClient;\nimport io.modelcontextprotocol.client.McpSyncClient;\nimport io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;\nimport lombok.extern.slf4j.Slf4j;\nimport org.springframework.ai.chat.model.ChatModel;\nimport org.springframework.ai.mcp.SyncMcpToolCallbackProvider;\nimport org.springframework.ai.openai.OpenAiChatModel;\nimport org.springframework.ai.openai.OpenAiChatOptions;\nimport org.springframework.ai.openai.api.OpenAiApi;\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.nio.file.Paths;\nimport java.time.Duration;\nimport java.util.Properties;\n\n/**\n * Spring Ai Tool\n *\n * @author xiaofuge bugstack.cn @小傅哥\n * 2025/12/14 09:51\n */\n@Slf4j\npublic class SpringAiToolTest {\n\n public static void main(String[] args) throws IOException {\n Properties config = new Properties();\n try (InputStream is = new FileInputStream(Paths.get(\"ai-config.properties\").toFile())) {\n config.load(is);\n }\n\n OpenAiApi openAiApi = OpenAiApi.builder()\n .baseUrl(\"https://api.deepseek.com\")\n .apiKey(config.getProperty(\"ai.api.key\"))\n .completionsPath(\"v1/chat/completions\")\n .embeddingsPath(\"v1/embeddings\")\n .build();\n\n ChatModel chatModel = OpenAiChatModel.builder()\n .openAiApi(openAiApi)\n .defaultOptions(OpenAiChatOptions.builder()\n .model(\"deepseek-v4-pro\")\n .toolCallbacks(SyncMcpToolCallbackProvider.builder()\n .mcpClients(sseMcpClient(config)).build()\n .getToolCallbacks())\n .build())\n .build();\n\n String call = chatModel.call(\"你哪有哪些工具能力\");\n\n log.info(\"测试结果:{}\", call);\n }\n\n /**\n * 百度搜索MCP服务(url);https://sai.baidu.com/zh/detail/e014c6ffd555697deabf00d058baf388\n * 百度搜索MCP服务(key);https://console.bce.baidu.com/iam/?_=1753597622044#/iam/apikey/list\n */\n public static McpSyncClient sseMcpClient(Properties config) {\n\n // 自己申请 api_key\n HttpClientSseClientTransport sseClientTransport = HttpClientSseClientTransport.builder(\"http://appbuilder.baidu.com/v2/ai_search/mcp/\")\n .sseEndpoint(\"sse?api_key=\" + config.getProperty(\"mcp.baidu.api.key\"))\n .build();\n\n McpSyncClient mcpSyncClient = McpClient.sync(sseClientTransport).requestTimeout(Duration.ofMinutes(360)).build();\n var init_sse = mcpSyncClient.initialize();\n log.info(\"Tool SSE MCP Initialized {}\", init_sse);\n\n return mcpSyncClient;\n }\n\n}\n"}, "e1f5ee92cfbd5e5e37a6a5fe101f0c21c2f838c8": {"t": 1785760045.717741, "n": 2741, "h": "e8e6f3866bc4a1ef", "c": "package com.gduf.test.api.tool;\n\nimport io.modelcontextprotocol.client.McpClient;\nimport io.modelcontextprotocol.client.McpSyncClient;\nimport io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;\nimport lombok.extern.slf4j.Slf4j;\nimport org.springframework.ai.chat.model.ChatModel;\nimport org.springframework.ai.mcp.SyncMcpToolCallbackProvider;\nimport org.springframework.ai.openai.OpenAiChatModel;\nimport org.springframework.ai.openai.OpenAiChatOptions;\nimport org.springframework.ai.openai.api.OpenAiApi;\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.nio.file.Paths;\nimport java.time.Duration;\nimport java.util.Properties;\n\n/**\n * Spring Ai Tool\n *\n * @author xiaofuge bugstack.cn @小傅哥\n * 2025/12/14 09:51\n */\n@Slf4j\npublic class SpringAiToolTest {\n\n public static void main(String[] args) throws IOException {\n Properties config = new Properties();\n try (InputStream is = new FileInputStream(Paths.get(\"ai-config.properties\").toFile())) {\n config.load(is);\n }\n\n OpenAiApi openAiApi = OpenAiApi.builder()\n .baseUrl(\"https://api.deepseek.com\")\n .apiKey(config.getProperty(\"ai.api.key\"))\n .completionsPath(\"v1/chat/completions\")\n .embeddingsPath(\"v1/embeddings\")\n .build();\n\n ChatModel chatModel = OpenAiChatModel.builder()\n .openAiApi(openAiApi)\n .defaultOptions(OpenAiChatOptions.builder()\n .model(\"deepseek-v4-pro\")\n .toolCallbacks(SyncMcpToolCallbackProvider.builder()\n .mcpClients(sseMcpClient(config)).build()\n .getToolCallbacks())\n .build())\n .build();\n\n String call = chatModel.call(\"你哪有哪些工具能力\");\n\n log.info(\"测试结果:{}\", call);\n }\n\n /**\n * 百度搜索MCP服务(url);https://sai.baidu.com/zh/detail/e014c6ffd555697deabf00d058baf388\n * 百度搜索MCP服务(key);https://console.bce.baidu.com/iam/?_=1753597622044#/iam/apikey/list\n */\n public static McpSyncClient sseMcpClient(Properties config) {\n\n // 自己申请 api_key\n HttpClientSseClientTransport sseClientTransport = HttpClientSseClientTransport.builder(\"http://appbuilder.baidu.com/v2/ai_search/mcp/\")\n .sseEndpoint(\"sse?api_key=\" + config.getProperty(\"mcp.baidu.api.key\"))\n .build();\n\n McpSyncClient mcpSyncClient = McpClient.sync(sseClientTransport).requestTimeout(Duration.ofMinutes(360)).build();\n var init_sse = mcpSyncClient.initialize();\n log.info(\"Tool SSE MCP Initialized {}\", init_sse);\n\n return mcpSyncClient;\n }\n\n}\n"}}, "ai-agent-scaffold-app/src/test/java/com/gduf/test/api/agent/SequentialAgentTest.java": {"2d3b77e6973599c53c068217136b636f7c407e9a": {"t": 1785746133.5846162, "n": 8639, "h": "fab4a68e20404a33", "c": "package com.gduf.test.api.agent;\n\nimport com.google.adk.agents.LlmAgent;\nimport com.google.adk.agents.SequentialAgent;\nimport com.google.adk.events.Event;\nimport com.google.adk.models.springai.SpringAI;\nimport com.google.adk.runner.InMemoryRunner;\nimport com.google.adk.sessions.Session;\nimport com.google.genai.types.Content;\nimport com.google.genai.types.Part;\nimport io.modelcontextprotocol.client.McpClient;\nimport io.modelcontextprotocol.client.McpSyncClient;\nimport io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;\nimport io.reactivex.rxjava3.core.Flowable;\nimport lombok.extern.slf4j.Slf4j;\nimport org.springframework.ai.chat.model.ChatModel;\nimport org.springframework.ai.mcp.SyncMcpToolCallbackProvider;\nimport org.springframework.ai.openai.OpenAiChatModel;\nimport org.springframework.ai.openai.OpenAiChatOptions;\nimport org.springframework.ai.openai.api.OpenAiApi;\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.nio.file.Paths;\nimport java.time.Duration;\nimport java.util.Properties;\n\n@Slf4j\npublic class SequentialAgentTest {\n\n private static final String APP_NAME = \"CodePipelineAgent\";\n private static final String USER_ID = \"test_user_456\";\n\n public static void main(String[] args) throws IOException {\n Properties config = new Properties();\n try (InputStream is = new FileInputStream(Paths.get(\"ai-config.properties\").toFile())) {\n config.load(is);\n }\n\n OpenAiApi openAiApi = OpenAiApi.builder()\n .baseUrl(\"https://api.deepseek.com\")\n .apiKey(config.getProperty(\"ai.api.key\"))\n .completionsPath(\"v1/chat/completions\")\n .embeddingsPath(\"v1/embeddings\")\n .build();\n\n ChatModel chatModel = OpenAiChatModel.builder()\n .openAiApi(openAiApi)\n .defaultOptions(OpenAiChatOptions.builder()\n .model(\"deepseek-v4-pro\")\n .toolCallbacks(new SyncMcpToolCallbackProvider(sseMcpClient(config)).getToolCallbacks())\n .build())\n .build();\n\n SequentialAgent codePipelineAgent =\n SequentialAgent.builder()\n .name(\"CodePipelineAgent\")\n .description(\"Executes a sequence of code writing, reviewing, and refactoring.\")\n // The agents will run in the order provided: Writer -> Reviewer -> Refactorer\n .subAgents(codeWriterAgent(chatModel), codeReviewerAgent(chatModel), codeRefactorerAgent(chatModel))\n .build();\n\n // Create an InMemoryRunner\n InMemoryRunner runner = new InMemoryRunner(codePipelineAgent, APP_NAME);\n // InMemoryRunner automatically creates a session service. Create a session using the service\n Session session = runner.sessionService().createSession(APP_NAME, USER_ID).blockingGet();\n Content userMessage = Content.fromParts(Part.fromText(\"Write a Java function to calculate the factorial of a number.\"));\n\n // Run the agent\n Flowable<Event> eventStream = runner.runAsync(USER_ID, session.id(), userMessage);\n\n // Stream event response\n eventStream.blockingForEach(\n event -> {\n if (event.finalResponse()) {\n System.out.println(event.stringifyContent());\n }\n });\n\n }\n\n public static LlmAgent codeWriterAgent(ChatModel chatModel) {\n return LlmAgent.builder()\n .model(new SpringAI(chatModel))\n .name(\"CodeWriterAgent\")\n .description(\"Writes initial Java code based on a specification.\")\n .instruction(\n \"\"\"\n You are a Java Code Generator.\n Based *only* on the user's request, write Java code that fulfills the requirement.\n Output *only* the complete Java code block, enclosed in triple backticks (```java ... ```).\n Do not add any other text before or after the code block.\n \"\"\")\n .outputKey(\"generated_code\")\n .build();\n }\n\n public static LlmAgent codeReviewerAgent(ChatModel chatModel) {\n return LlmAgent.builder()\n .model(new SpringAI(chatModel))\n .name(\"CodeReviewerAgent\")\n .description(\"Reviews code and provides feedback.\")\n .instruction(\n \"\"\"\n You are an expert Java Code Reviewer.\n Your task is to provide constructive feedback on the provided code.\n \n **Code to Review:**\n ```java\n {generated_code}\n ```\n \n **Review Criteria:**\n 1. **Correctness:** Does the code work as intended? Are there logic errors?\n 2. **Readability:** Is the code clear and easy to understand? Follows Java style guidelines?\n 3. **Efficiency:** Is the code reasonably efficient? Any obvious performance bottlenecks?\n 4. **Edge Cases:** Does the code handle potential edge cases or invalid inputs gracefully?\n 5. **Best Practices:** Does the code follow common Java best practices?\n \n **Output:**\n Provide your feedback as a concise, bulleted list. Focus on the most important points for improvement.\n If the code is excellent and requires no changes, simply state: \"No major issues found.\"\n Output *only* the review comments or the \"No major issues\" statement.\n \"\"\")\n .outputKey(\"review_comments\")\n .build();\n }\n\n public static LlmAgent codeRefactorerAgent(ChatModel chatModel) {\n return LlmAgent.builder()\n .model(new SpringAI(chatModel))\n .name(\"CodeRefactorerAgent\")\n .description(\"Refactors code based on review comments.\")\n .instruction(\n \"\"\"\n You are a Java Code Refactoring AI.\n Your goal is to improve the given Java code based on the provided review comments.\n \n **Original Code:**\n ```java\n {generated_code}\n ```\n \n **Review Comments:**\n {review_comments}\n \n **Task:**\n Carefully apply the suggestions from the review comments to refactor the original code.\n If the review comments state \"No major issues found,\" return the original code unchanged.\n Ensure the final code is complete, functional, and includes necessary imports and docstrings.\n \n **Output:**\n Output *only* the final, refactored Java code block, enclosed in triple backticks (```java ... ```).\n Do not add any other text before or after the code block.\n \"\"\")\n .outputKey(\"refactored_code\")\n\n .build();\n }\n\n public static McpSyncClient sseMcpClient(Properties config) {\n HttpClientSseClientTransport sseClientTransport = HttpClientSseClientTransport.builder(\"http://appbuilder.baidu.com/v2/ai_search/mcp/\")\n .sseEndpoint(\"sse?api_key=\" + config.getProperty(\"mcp.baidu.api.key\"))\n .build();\n\n McpSyncClient mcpSyncClient = McpClient.sync(sseClientTransport).requestTimeout(Duration.ofMinutes(360)).build();\n var init_sse = mcpSyncClient.initialize();\n log.info(\"Tool SSE MCP Initialized {}\", init_sse);\n\n return mcpSyncClient;\n }\n\n}\n"}, "e1f5ee92cfbd5e5e37a6a5fe101f0c21c2f838c8": {"t": 1785760045.7534416, "n": 8639, "h": "fab4a68e20404a33", "c": "package com.gduf.test.api.agent;\n\nimport com.google.adk.agents.LlmAgent;\nimport com.google.adk.agents.SequentialAgent;\nimport com.google.adk.events.Event;\nimport com.google.adk.models.springai.SpringAI;\nimport com.google.adk.runner.InMemoryRunner;\nimport com.google.adk.sessions.Session;\nimport com.google.genai.types.Content;\nimport com.google.genai.types.Part;\nimport io.modelcontextprotocol.client.McpClient;\nimport io.modelcontextprotocol.client.McpSyncClient;\nimport io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;\nimport io.reactivex.rxjava3.core.Flowable;\nimport lombok.extern.slf4j.Slf4j;\nimport org.springframework.ai.chat.model.ChatModel;\nimport org.springframework.ai.mcp.SyncMcpToolCallbackProvider;\nimport org.springframework.ai.openai.OpenAiChatModel;\nimport org.springframework.ai.openai.OpenAiChatOptions;\nimport org.springframework.ai.openai.api.OpenAiApi;\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.nio.file.Paths;\nimport java.time.Duration;\nimport java.util.Properties;\n\n@Slf4j\npublic class SequentialAgentTest {\n\n private static final String APP_NAME = \"CodePipelineAgent\";\n private static final String USER_ID = \"test_user_456\";\n\n public static void main(String[] args) throws IOException {\n Properties config = new Properties();\n try (InputStream is = new FileInputStream(Paths.get(\"ai-config.properties\").toFile())) {\n config.load(is);\n }\n\n OpenAiApi openAiApi = OpenAiApi.builder()\n .baseUrl(\"https://api.deepseek.com\")\n .apiKey(config.getProperty(\"ai.api.key\"))\n .completionsPath(\"v1/chat/completions\")\n .embeddingsPath(\"v1/embeddings\")\n .build();\n\n ChatModel chatModel = OpenAiChatModel.builder()\n .openAiApi(openAiApi)\n .defaultOptions(OpenAiChatOptions.builder()\n .model(\"deepseek-v4-pro\")\n .toolCallbacks(new SyncMcpToolCallbackProvider(sseMcpClient(config)).getToolCallbacks())\n .build())\n .build();\n\n SequentialAgent codePipelineAgent =\n SequentialAgent.builder()\n .name(\"CodePipelineAgent\")\n .description(\"Executes a sequence of code writing, reviewing, and refactoring.\")\n // The agents will run in the order provided: Writer -> Reviewer -> Refactorer\n .subAgents(codeWriterAgent(chatModel), codeReviewerAgent(chatModel), codeRefactorerAgent(chatModel))\n .build();\n\n // Create an InMemoryRunner\n InMemoryRunner runner = new InMemoryRunner(codePipelineAgent, APP_NAME);\n // InMemoryRunner automatically creates a session service. Create a session using the service\n Session session = runner.sessionService().createSession(APP_NAME, USER_ID).blockingGet();\n Content userMessage = Content.fromParts(Part.fromText(\"Write a Java function to calculate the factorial of a number.\"));\n\n // Run the agent\n Flowable<Event> eventStream = runner.runAsync(USER_ID, session.id(), userMessage);\n\n // Stream event response\n eventStream.blockingForEach(\n event -> {\n if (event.finalResponse()) {\n System.out.println(event.stringifyContent());\n }\n });\n\n }\n\n public static LlmAgent codeWriterAgent(ChatModel chatModel) {\n return LlmAgent.builder()\n .model(new SpringAI(chatModel))\n .name(\"CodeWriterAgent\")\n .description(\"Writes initial Java code based on a specification.\")\n .instruction(\n \"\"\"\n You are a Java Code Generator.\n Based *only* on the user's request, write Java code that fulfills the requirement.\n Output *only* the complete Java code block, enclosed in triple backticks (```java ... ```).\n Do not add any other text before or after the code block.\n \"\"\")\n .outputKey(\"generated_code\")\n .build();\n }\n\n public static LlmAgent codeReviewerAgent(ChatModel chatModel) {\n return LlmAgent.builder()\n .model(new SpringAI(chatModel))\n .name(\"CodeReviewerAgent\")\n .description(\"Reviews code and provides feedback.\")\n .instruction(\n \"\"\"\n You are an expert Java Code Reviewer.\n Your task is to provide constructive feedback on the provided code.\n \n **Code to Review:**\n ```java\n {generated_code}\n ```\n \n **Review Criteria:**\n 1. **Correctness:** Does the code work as intended? Are there logic errors?\n 2. **Readability:** Is the code clear and easy to understand? Follows Java style guidelines?\n 3. **Efficiency:** Is the code reasonably efficient? Any obvious performance bottlenecks?\n 4. **Edge Cases:** Does the code handle potential edge cases or invalid inputs gracefully?\n 5. **Best Practices:** Does the code follow common Java best practices?\n \n **Output:**\n Provide your feedback as a concise, bulleted list. Focus on the most important points for improvement.\n If the code is excellent and requires no changes, simply state: \"No major issues found.\"\n Output *only* the review comments or the \"No major issues\" statement.\n \"\"\")\n .outputKey(\"review_comments\")\n .build();\n }\n\n public static LlmAgent codeRefactorerAgent(ChatModel chatModel) {\n return LlmAgent.builder()\n .model(new SpringAI(chatModel))\n .name(\"CodeRefactorerAgent\")\n .description(\"Refactors code based on review comments.\")\n .instruction(\n \"\"\"\n You are a Java Code Refactoring AI.\n Your goal is to improve the given Java code based on the provided review comments.\n \n **Original Code:**\n ```java\n {generated_code}\n ```\n \n **Review Comments:**\n {review_comments}\n \n **Task:**\n Carefully apply the suggestions from the review comments to refactor the original code.\n If the review comments state \"No major issues found,\" return the original code unchanged.\n Ensure the final code is complete, functional, and includes necessary imports and docstrings.\n \n **Output:**\n Output *only* the final, refactored Java code block, enclosed in triple backticks (```java ... ```).\n Do not add any other text before or after the code block.\n \"\"\")\n .outputKey(\"refactored_code\")\n\n .build();\n }\n\n public static McpSyncClient sseMcpClient(Properties config) {\n HttpClientSseClientTransport sseClientTransport = HttpClientSseClientTransport.builder(\"http://appbuilder.baidu.com/v2/ai_search/mcp/\")\n .sseEndpoint(\"sse?api_key=\" + config.getProperty(\"mcp.baidu.api.key\"))\n .build();\n\n McpSyncClient mcpSyncClient = McpClient.sync(sseClientTransport).requestTimeout(Duration.ofMinutes(360)).build();\n var init_sse = mcpSyncClient.initialize();\n log.info(\"Tool SSE MCP Initialized {}\", init_sse);\n\n return mcpSyncClient;\n }\n\n}\n"}}}}