Skip to content

Commit 656a134

Browse files
authored
Merge pull request #7 from muverystrong/feat/put-get-level
feat: task put protocol add getQueueLevel method
2 parents b21cdb6 + 1ef0774 commit 656a134

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>top.bella</groupId>
88
<artifactId>openai-java</artifactId>
9-
<version>0.23.44</version>
9+
<version>0.23.45</version>
1010
</parent>
1111
<packaging>jar</packaging>
1212
<artifactId>openai-api</artifactId>

api/src/main/java/com/theokanning/openai/queue/Put.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import lombok.NoArgsConstructor;
99

1010
import java.util.Map;
11+
import java.util.Optional;
1112

1213
/**
1314
* Represents a queue put operation for task queuing
@@ -63,4 +64,36 @@ public class Put {
6364
public String getFullQueueName() {
6465
return String.format("%s:%d", queue, level);
6566
}
67+
68+
/**
69+
* Determines the effective queue level based on the response mode and level
70+
*
71+
* @return the effective queue level
72+
*/
73+
@JsonIgnore
74+
public Integer getQueueLevel() {
75+
if("blocking".equals(responseMode) || "streaming".equals(responseMode)) {
76+
return 0;
77+
} else if("callback".equals(responseMode) || "batch".equals(responseMode)) {
78+
return getLevel() != null && getLevel() >= 0 ? getLevel() : 1;
79+
} else {
80+
throw new IllegalArgumentException("Unsupported response mode: " + responseMode);
81+
}
82+
}
83+
84+
/**
85+
* Determines the task timeout based on the response mode and specified timeout
86+
*
87+
* @return the task timeout in seconds
88+
*/
89+
@JsonIgnore
90+
public int getTaskTimeout() {
91+
if("blocking".equals(responseMode) || "streaming".equals(responseMode)) {
92+
return timeout > 0 ? Math.min(timeout, 300) : 300;
93+
} else if("callback".equals(responseMode) || "batch".equals(responseMode)) {
94+
return timeout > 0 ? timeout : 24 * 60 * 60;
95+
} else {
96+
throw new IllegalArgumentException("Unsupported response mode: " + responseMode);
97+
}
98+
}
6699
}

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>top.bella</groupId>
88
<artifactId>openai-java</artifactId>
9-
<version>0.23.44</version>
9+
<version>0.23.45</version>
1010
</parent>
1111
<packaging>jar</packaging>
1212

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>top.bella</groupId>
77
<artifactId>openai-java</artifactId>
8-
<version>0.23.44</version>
8+
<version>0.23.45</version>
99
<packaging>pom</packaging>
1010
<description>openai java 版本</description>
1111
<name>openai-java</name>

service/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>top.bella</groupId>
88
<artifactId>openai-java</artifactId>
9-
<version>0.23.44</version>
9+
<version>0.23.45</version>
1010
</parent>
1111
<packaging>jar</packaging>
1212

0 commit comments

Comments
 (0)