初始化
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2026, Easy-Agents (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.easyagents.llm.ollama;
|
||||
|
||||
import com.easyagents.core.model.chat.ChatConfig;
|
||||
|
||||
public class OllamaChatConfig extends ChatConfig {
|
||||
|
||||
private static final String DEFAULT_PROVIDER = "ollama";
|
||||
private static final String DEFAULT_ENDPOINT = "https://localhost:11434";
|
||||
private static final String DEFAULT_REQUEST_PATH = "/v1/chat/completions";
|
||||
|
||||
public OllamaChatConfig() {
|
||||
setProvider(DEFAULT_PROVIDER);
|
||||
setEndpoint(DEFAULT_ENDPOINT);
|
||||
setRequestPath(DEFAULT_REQUEST_PATH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2026, Easy-Agents (fuhai999@gmail.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.easyagents.llm.ollama;
|
||||
|
||||
import com.easyagents.core.model.chat.OpenAICompatibleChatModel;
|
||||
import com.easyagents.core.model.chat.ChatInterceptor;
|
||||
import com.easyagents.core.model.chat.GlobalChatInterceptors;
|
||||
import com.easyagents.core.model.client.ChatRequestSpecBuilder;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OllamaChatModel extends OpenAICompatibleChatModel<OllamaChatConfig> {
|
||||
|
||||
/**
|
||||
* 构造一个聊天模型实例,不使用实例级拦截器。
|
||||
*
|
||||
* @param config 聊天模型配置
|
||||
*/
|
||||
public OllamaChatModel(OllamaChatConfig config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造一个聊天模型实例,并指定实例级拦截器。
|
||||
* <p>
|
||||
* 实例级拦截器会与全局拦截器(通过 {@link GlobalChatInterceptors} 注册)合并,
|
||||
* 执行顺序为:可观测性拦截器 → 全局拦截器 → 实例拦截器。
|
||||
*
|
||||
* @param config 聊天模型配置
|
||||
* @param userInterceptors 实例级拦截器列表
|
||||
*/
|
||||
public OllamaChatModel(OllamaChatConfig config, List<ChatInterceptor> userInterceptors) {
|
||||
super(config, userInterceptors);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ChatRequestSpecBuilder getChatRequestSpecBuilder() {
|
||||
return new OllamaRequestSpecBuilder();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.easyagents.llm.ollama;
|
||||
|
||||
import com.easyagents.core.model.chat.ChatConfig;
|
||||
import com.easyagents.core.model.chat.ChatOptions;
|
||||
import com.easyagents.core.model.client.OpenAIChatRequestSpecBuilder;
|
||||
import com.easyagents.core.prompt.Prompt;
|
||||
import com.easyagents.core.util.Maps;
|
||||
|
||||
public class OllamaRequestSpecBuilder extends OpenAIChatRequestSpecBuilder {
|
||||
protected Maps buildBaseParamsOfRequestBody(Prompt prompt, ChatOptions options, ChatConfig config) {
|
||||
Maps params = super.buildBaseParamsOfRequestBody(prompt, options, config);
|
||||
params.setIf(!options.isStreaming(), "stream", false);
|
||||
|
||||
// 支持思考
|
||||
if (config.isSupportThinking()) {
|
||||
params.setIf(options.getThinkingEnabled() != null, "thinking", options.getThinkingEnabled());
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user