All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.langchain4j.service.AiServiceContext Maven / Gradle / Ivy

Go to download

Java implementation of LangChain: Integrate your Java application with countless AI tools and services smoothly

There is a newer version: 0.36.2
Show newest version
package dev.langchain4j.service;

import dev.langchain4j.agent.tool.ToolExecutor;
import dev.langchain4j.agent.tool.ToolSpecification;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import dev.langchain4j.model.moderation.ModerationModel;
import dev.langchain4j.rag.RetrievalAugmentor;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

public class AiServiceContext {

    private static final Function> DEFAULT_MESSAGE_PROVIDER = x -> Optional.empty();

    public final Class aiServiceClass;

    public ChatLanguageModel chatModel;
    public StreamingChatLanguageModel streamingChatModel;

    public Map chatMemories;
    public ChatMemoryProvider chatMemoryProvider;

    public ModerationModel moderationModel;

    public List toolSpecifications;
    public Map toolExecutors;

    public RetrievalAugmentor retrievalAugmentor;

    public Function> systemMessageProvider = DEFAULT_MESSAGE_PROVIDER;

    public AiServiceContext(Class aiServiceClass) {
        this.aiServiceClass = aiServiceClass;
    }

    public boolean hasChatMemory() {
        return chatMemories != null;
    }

    public ChatMemory chatMemory(Object memoryId) {
        return chatMemories.computeIfAbsent(memoryId, ignored -> chatMemoryProvider.get(memoryId));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy