forked from github/copilot-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSectionOverride.java
More file actions
138 lines (125 loc) · 4.45 KB
/
SectionOverride.java
File metadata and controls
138 lines (125 loc) · 4.45 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot.sdk.json;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Override operation for a single system prompt section in
* {@link SystemMessageMode#CUSTOMIZE} mode.
* <p>
* Each {@code SectionOverride} describes how one named section of the default
* system prompt should be modified. The section name keys come from
* {@link SystemPromptSections}.
*
* <h2>Static override example</h2>
*
* <pre>{@code
* var config = new SystemMessageConfig().setMode(SystemMessageMode.CUSTOMIZE).setSections(Map.of(
* SystemPromptSections.TONE,
* new SectionOverride().setAction(SectionOverrideAction.REPLACE).setContent("Be concise and formal."),
* SystemPromptSections.CODE_CHANGE_RULES, new SectionOverride().setAction(SectionOverrideAction.REMOVE)));
* }</pre>
*
* <h2>Transform callback example</h2>
*
* <pre>{@code
* var config = new SystemMessageConfig().setMode(SystemMessageMode.CUSTOMIZE)
* .setSections(Map.of(SystemPromptSections.IDENTITY, new SectionOverride().setTransform(
* content -> CompletableFuture.completedFuture(content + "\nAlways end replies with DONE."))));
* }</pre>
*
* @see SystemMessageConfig
* @see SectionOverrideAction
* @see SystemPromptSections
* @since 1.2.0
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SectionOverride {
@JsonProperty("action")
private SectionOverrideAction action;
@JsonProperty("content")
private String content;
/**
* Transform callback invoked by the SDK when the CLI requests a
* {@code systemMessage.transform} RPC call.
* <p>
* The function receives the current section content and returns the transformed
* content wrapped in a {@link CompletableFuture}. When a transform is set, it
* takes precedence over {@link #action}; the wire representation uses
* {@link SectionOverrideAction#TRANSFORM} automatically.
* <p>
* This field is not serialized — it is handled entirely by the SDK.
*/
@JsonIgnore
private Function<String, CompletableFuture<String>> transform;
/**
* Gets the override action.
*
* @return the action, or {@code null} if a transform callback is set
*/
public SectionOverrideAction getAction() {
return action;
}
/**
* Sets the override action.
*
* @param action
* the action to perform on this section
* @return this override for method chaining
*/
public SectionOverride setAction(SectionOverrideAction action) {
this.action = action;
return this;
}
/**
* Gets the content for the override.
*
* @return the content, or {@code null}
*/
public String getContent() {
return content;
}
/**
* Sets the content for the override.
* <p>
* Used for {@link SectionOverrideAction#REPLACE},
* {@link SectionOverrideAction#APPEND}, and
* {@link SectionOverrideAction#PREPEND}. Ignored for
* {@link SectionOverrideAction#REMOVE}.
*
* @param content
* the content string
* @return this override for method chaining
*/
public SectionOverride setContent(String content) {
this.content = content;
return this;
}
/**
* Gets the transform callback.
*
* @return the transform function, or {@code null} if not set
*/
public Function<String, CompletableFuture<String>> getTransform() {
return transform;
}
/**
* Sets the transform callback for this section.
* <p>
* The function receives the current section content as a {@code String} and
* returns the transformed content via a {@link CompletableFuture}. When set,
* this takes precedence over {@link #action}.
*
* @param transform
* a function that transforms the section content
* @return this override for method chaining
*/
public SectionOverride setTransform(Function<String, CompletableFuture<String>> transform) {
this.transform = transform;
return this;
}
}