forked from microsoft/semantic-kernel-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseAIServiceSelector.java
More file actions
90 lines (81 loc) · 3.75 KB
/
BaseAIServiceSelector.java
File metadata and controls
90 lines (81 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.services;
import com.microsoft.semantickernel.semanticfunctions.KernelFunction;
import com.microsoft.semantickernel.semanticfunctions.KernelArguments;
import java.util.Map;
import javax.annotation.Nullable;
/**
* Base class for {@link AIServiceSelector} implementations which provides a {@code Map} based
* collection from which an {@link AIService} can be selected. The
* {@link #trySelectAIService(Class, KernelFunction, KernelArguments)} method has been
* implemented. Child classes must implement the method
* {@link #trySelectAIService(Class, KernelFunction, KernelArguments, Map)}.
*/
public abstract class BaseAIServiceSelector implements AIServiceSelector {
protected final AIServiceCollection services;
/**
* Initializes a new instance of the {@link BaseAIServiceSelector} class.
*
* @param services The services to select from.
*/
protected BaseAIServiceSelector(AIServiceCollection services) {
this.services = services;
}
@Override
@Nullable
public <T extends AIService> AIServiceSelection<T> trySelectAIService(
Class<T> serviceType,
@Nullable KernelFunction<?> function,
@Nullable KernelArguments arguments) {
return trySelectAIService(serviceType, function, arguments, services);
}
@Override
@Nullable
public <T extends AIService> AIServiceSelection<T> trySelectAIService(
Class<T> serviceType,
@Nullable KernelArguments arguments) {
return trySelectAIService(serviceType, arguments, services);
}
/**
* Resolves an {@link AIService} from the {@code services} argument using the specified
* {@code function} and {@code arguments} for selection.
*
* @param serviceType The type of service to select. This must be the same type with which the
* service was registered in the {@link AIServiceSelection}
* @param function The KernelFunction to use to select the service, or {@code null}.
* @param arguments The KernelFunctionArguments to use to select the service, or
* {@code null}.
* @param services The services to select from.
* @param <T> The type of service to select.
* @return The selected service, or {@code null} if no service could be selected.
*
* @deprecated Implement {@link #trySelectAIService(Class, KernelArguments)}
*/
@Deprecated
@Nullable
protected abstract <T extends AIService> AIServiceSelection<T> trySelectAIService(
Class<T> serviceType,
@Nullable KernelFunction<?> function,
@Nullable KernelArguments arguments,
Map<Class<? extends AIService>, AIService> services);
/**
* Resolves an {@link AIService} from the {@code services} argument using the specified
* {@code function} and {@code arguments} for selection.
*
* @param serviceType The type of service to select. This must be the same type with which the
* service was registered in the {@link AIServiceSelection}
* @param arguments The KernelArguments to use to select the service, or
* {@code null}.
* @param services The services to select from.
* @param <T> The type of service to select.
* @return The selected service, or {@code null} if no service could be selected.
*/
@Nullable
protected <T extends AIService> AIServiceSelection<T> trySelectAIService(
Class<T> serviceType,
@Nullable KernelArguments arguments,
Map<Class<? extends AIService>, AIService> services) {
throw new UnsupportedOperationException(
"This method is not implemented.");
}
}