20250329 function call(还需要调整,目前qwen貌似不支持,要试试ollama的方式)
This commit is contained in:
parent
3ee1c62f70
commit
4fbeca899b
@ -1,5 +1,6 @@
|
||||
package com.ai.config;
|
||||
|
||||
import com.ai.function.MyCalculator;
|
||||
import com.ai.service.Assist;
|
||||
import dev.langchain4j.community.model.dashscope.QwenChatModel;
|
||||
import dev.langchain4j.data.document.Document;
|
||||
@ -36,6 +37,8 @@ public class AssistantInit {
|
||||
return AiServices.builder(Assist.class)
|
||||
.chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10))
|
||||
.chatLanguageModel(qwenModel)
|
||||
.contentRetriever(EmbeddingStoreContentRetriever.from(embeddingStore)).build();
|
||||
.contentRetriever(EmbeddingStoreContentRetriever.from(embeddingStore))
|
||||
.tools(new MyCalculator())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
@ -55,10 +55,16 @@ public class LangChainController {
|
||||
}
|
||||
|
||||
@GetMapping("/zhipu/img")
|
||||
public String memoryChat( @RequestParam("input") String input) {
|
||||
System.out.println("start highlevel memory chat...");
|
||||
public String generateImg( @RequestParam("input") String input) {
|
||||
System.out.println("start generate img...");
|
||||
Response<Image> generate = zhipuAiImageModel.generate(input);
|
||||
URI url = generate.content().url();
|
||||
return "Your remote image is here: " + url;
|
||||
}
|
||||
|
||||
@GetMapping("/high/call")
|
||||
public String functionCall(@RequestParam("input") String input) {
|
||||
System.out.println("start highlevel memory chat...");
|
||||
return assist.chat(input);
|
||||
}
|
||||
}
|
||||
|
11
src/main/java/com/ai/function/MyCalculator.java
Normal file
11
src/main/java/com/ai/function/MyCalculator.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.ai.function;
|
||||
|
||||
import dev.langchain4j.agent.tool.Tool;
|
||||
|
||||
public class MyCalculator {
|
||||
|
||||
@Tool("路飞算法")
|
||||
public int luffy(int a, int b){
|
||||
return (a + b) / (a - b);
|
||||
}
|
||||
}
|
@ -13,3 +13,6 @@ GET http://localhost:8080/langchain/high/memory-chat?memoryId=1&input=详细介
|
||||
|
||||
### 测试 LangChainController 的 highlevel chat 接口
|
||||
GET http://localhost:8080/langchain/zhipu/img?input=请画一张魔兽世界里的兽人高举锤子的图
|
||||
|
||||
### 测试 LangChainController 的 highlevel chat 接口
|
||||
GET http://localhost:8080/langchain/high/call?input=我的两个数分别是9和3,请用路飞算法计算结果
|
||||
|
Loading…
Reference in New Issue
Block a user