Skip to content

Commit 0338c85

Browse files
hyz1994121hyz
andauthored
fix mcp-sample bugs (#30)
* fix mcp-client config yaml format bug, fix pom http dependency bug. due to these bugs, mcp-sample can not run success * add readme add evn config 增加了配置全局LLM key的使用方式说明,无需每次调整对应的配置文件 --------- Co-authored-by: hyz <[email protected]>
1 parent 126c4ce commit 0338c85

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ spring.ai.deepseek.chat.options.model=deepseek-chat
102102
```
103103
将你的 `spring.ai.deepseek.api-key` 替换为实际的 API 密钥即可启动运行。关于如何申请 api key ,可以移步项目 [Wiki 页面](https://github.com/java-ai-tech/spring-ai-summary/wiki)进行查看。
104104

105+
有一个一劳永逸的办法,将对应的spring.ai.deepseek.api-key添加到对应环境变量中,后续启动时会带进来,不用再去修改代码了对应的application.yml,不用担心提交代码泄露key
106+
将IDEA启动项中的环境变量添加spring.ai.openai.api-key=sk-***************(你自己对应的 key),运行项目时,会自动带入环境变量。
107+
不过对应的子module每个模块都需要配置
108+
109+
105110
### 3. ▶️ 运行示例
106111

107112
完成上述步骤后,你可以选择运行不同的示例模块来体验 Spring AI 的功能。如启动运行 **spring-ai-chat-deepseek** 模块(具体端口可以根据你自己的配置而定):

README_EN.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ spring.ai.deepseek.chat.options.model=deepseek-chat
100100
```
101101
Replace `spring.ai.deepseek.api-key` with your actual API key to start the service. For how to apply for an API key, see the project [Wiki page](https://github.com/java-ai-tech/spring-ai-summary/wiki).
102102

103+
There's a one-time setup solution: add the spring.ai.deepseek.api-key to your environment variables. This will be automatically loaded during subsequent application startups without needing code modifications in application.yml, eliminating concerns about accidentally committing the code and exposing the key.
104+
105+
In IntelliJ IDEA's launch configuration, add the environment variable spring.ai.openai.api-key=sk-***************(your_actual_key). The project will automatically include this environment variable when running.
106+
107+
Note: Each submodule requires separate configuration for this setting.
103108
### 3. ▶️ Run Examples
104109

105110
After the above steps, you can run different modules to experience Spring AI features. For example, to start **spring-ai-chat-deepseek** (port may vary):

spring-ai-mcp/mcp-client/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<artifactId>httpclient5</artifactId>
2020
<version>5.4.3</version>
2121
</dependency>
22+
<dependency>
23+
<groupId>org.apache.httpcomponents.core5</groupId>
24+
<artifactId>httpcore5</artifactId>
25+
<version>5.3.4</version> <!-- 确保版本兼容 -->
26+
</dependency>
2227

2328
<dependency>
2429
<groupId>org.springframework.ai</groupId>

spring-ai-mcp/mcp-client/src/main/resources/application.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ spring:
66
name: mcp-client
77
profiles:
88
active: mcp-client
9-
ai:
10-
openai:
11-
api-key: sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
12-
chat:
13-
base-url: https://api.deepseek.com
14-
completions-path: /v1/chat/completions
15-
options:
16-
model: deepseek-chat
9+
ai:
10+
openai:
11+
api-key: ${spring.ai.openai.api-key}
12+
chat:
13+
# base-url: https://api.deepseek.com
14+
base-url: https://dashscope.aliyuncs.com/compatible-mode
15+
# completions-path: /v1/chat/completions
16+
completions-path: /v1/chat/completions
17+
options:
18+
# model: deepseek-chat
19+
model: qwen-plus

0 commit comments

Comments
 (0)