Skip to content

Commit 5ec8a82

Browse files
authored
Merge pull request #65 from Lambdua/fileSearch_feat
feat: 更新文件搜索工具类及测试用例 #61
2 parents a7db34f + b682ba7 commit 5ec8a82

File tree

5 files changed

+68
-10
lines changed

5 files changed

+68
-10
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.theokanning.openai.assistants.assistant;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
/**
10+
* @author LiangTao
11+
* @date 2024年09月19 10:53
12+
**/
13+
@Data
14+
@NoArgsConstructor
15+
@AllArgsConstructor
16+
@Builder
17+
public class FileSearch {
18+
/**
19+
* The maximum number of results the file search tool should output. The default is 20 for gpt-4* models and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive.
20+
*/
21+
@JsonProperty("max_num_results")
22+
Integer maxNumResults;
23+
24+
/**
25+
* The ranking options for the file search. If not specified, the file search tool will use the auto ranker and a score_threshold of 0.
26+
*/
27+
@JsonProperty("ranking_options")
28+
FileSearchRankingOptions rankingOptions;
29+
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.theokanning.openai.assistants.assistant;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
import javax.validation.constraints.NotNull;
9+
10+
/**
11+
* @author LiangTao
12+
* @date 2024年09月19 10:36
13+
**/
14+
@Data
15+
@NoArgsConstructor
16+
@AllArgsConstructor
17+
public class FileSearchRankingOptions {
18+
/**
19+
* The ranker to use for the file search. If not specified will use the auto ranker.
20+
*/
21+
String ranker;
22+
23+
/**
24+
* The score threshold for the file search. All values must be a floating point number between 0 and 1.
25+
*/
26+
@NotNull
27+
@JsonProperty("score_threshold")
28+
Double scoreThreshold;
29+
30+
}

api/src/main/java/com/theokanning/openai/assistants/assistant/FileSearchTool.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
public class FileSearchTool implements Tool {
1717
final String type = "file_search";
1818

19-
/**
20-
* The maximum number of results the file search tool should output. The default is 20 for gpt-4* models and 5 for gpt-3.5-turbo. This number should be between 1 and 50 inclusive.
21-
*/
22-
@JsonProperty("max_num_results")
23-
Integer maxNumResults;
19+
20+
@JsonProperty("file_search")
21+
FileSearch fileSearch;
22+
23+
2424
}

example/src/main/java/example/AssistantExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static void fileSearchExample() throws UnsupportedEncodingException {
192192
.name("file search assistant")
193193
.instructions("你是一个中国传统音乐教授,负责根据用户的需求解答问题")
194194
//add file search tool to assistant
195-
.tools(Collections.singletonList(new FileSearchTool(1)))
195+
.tools(Collections.singletonList(new FileSearchTool()))
196196
.temperature(0D)
197197
.build();
198198
Assistant assistant = service.createAssistant(assistantRequest);

service/src/test/java/com/theokanning/openai/service/assistants/AssistantFileSearchTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.theokanning.openai.service.assistants;
22

33
import com.theokanning.openai.ListSearchParameters;
4-
import com.theokanning.openai.assistants.assistant.Assistant;
5-
import com.theokanning.openai.assistants.assistant.AssistantRequest;
6-
import com.theokanning.openai.assistants.assistant.FileSearchTool;
4+
import com.theokanning.openai.assistants.assistant.*;
75
import com.theokanning.openai.assistants.message.MessageListSearchParameters;
86
import com.theokanning.openai.assistants.message.MessageRequest;
97
import com.theokanning.openai.assistants.run.Run;
@@ -49,7 +47,7 @@ void fileSearchExample(){
4947
.name("file search assistant")
5048
.instructions("你是一个中国传统音乐教授,负责根据用户的需求解答问题")
5149
//add file search tool to assistant
52-
.tools(Collections.singletonList(new FileSearchTool()))
50+
.tools(Collections.singletonList(new FileSearchTool(new FileSearch(1,new FileSearchRankingOptions("auto", 0.5D)))))
5351
.temperature(0.3D)
5452
.build();
5553
Assistant assistant = service.createAssistant(assistantRequest);

0 commit comments

Comments
 (0)