Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Commit cd2be86

Browse files
aaronuu大名(张瑜)
andauthored
New features: token calculation logic and account information query logic. (#311)
* feat: Tool for calculating token consumption quantity. API for querying account balance * feat: * feat: update jtokkit --------- Co-authored-by: 大名(张瑜) <[email protected]>
1 parent 47ee441 commit cd2be86

14 files changed

Lines changed: 597 additions & 0 deletions

File tree

api/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ apply plugin: "com.vanniktech.maven.publish"
44
dependencies {
55
api libs.jacksonAnnotations
66
api libs.jacksonDatabind
7+
api libs.jtokkit
78
compileOnly libs.lombok
89
annotationProcessor libs.lombok
910

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.theokanning.openai.billing;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
6+
import java.math.BigDecimal;
7+
import java.util.List;
8+
9+
/**
10+
* Amount consumption information
11+
*
12+
*/
13+
@Data
14+
public class BillingUsage {
15+
16+
@JsonProperty("object")
17+
private String object;
18+
/**
19+
* Account expenditure details
20+
*/
21+
@JsonProperty("daily_costs")
22+
private List<DailyCost> dailyCosts;
23+
/**
24+
* Total usage amount: cents
25+
*/
26+
@JsonProperty("total_usage")
27+
private BigDecimal totalUsage;
28+
29+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.theokanning.openai.billing;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
6+
import java.io.Serializable;
7+
import java.math.BigDecimal;
8+
9+
/**
10+
* Return value of balance inquiry interface
11+
*
12+
*/
13+
@Data
14+
public class CreditGrantsResponse implements Serializable {
15+
private String object;
16+
/**
17+
* Total amount: US dollars
18+
*/
19+
@JsonProperty("total_granted")
20+
private BigDecimal totalGranted;
21+
/**
22+
* Total usage amount: US dollars
23+
*/
24+
@JsonProperty("total_used")
25+
private BigDecimal totalUsed;
26+
/**
27+
* Total remaining amount: US dollars
28+
*/
29+
@JsonProperty("total_available")
30+
private BigDecimal totalAvailable;
31+
/**
32+
* Balance details
33+
*/
34+
private Grants grants;
35+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.theokanning.openai.billing;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
6+
import java.util.List;
7+
8+
/**
9+
* List of amount consumption
10+
*
11+
*/
12+
@Data
13+
public class DailyCost {
14+
/**
15+
*
16+
*/
17+
@JsonProperty("timestamp")
18+
private long timestamp;
19+
/**
20+
* Model consumption amount details
21+
*/
22+
@JsonProperty("line_items")
23+
private List<LineItem> lineItems;
24+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.theokanning.openai.billing;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
6+
import java.math.BigDecimal;
7+
8+
/**
9+
*
10+
*
11+
*/
12+
@Data
13+
public class Datum {
14+
private String object;
15+
private String id;
16+
/**
17+
* Gift amount: US dollars
18+
*/
19+
@JsonProperty("grant_amount")
20+
private BigDecimal grantAmount;
21+
/**
22+
* Usage amount: US dollars
23+
*/
24+
@JsonProperty("used_amount")
25+
private BigDecimal usedAmount;
26+
/**
27+
* Effective timestamp
28+
*/
29+
@JsonProperty("effective_at")
30+
private Long effectiveAt;
31+
/**
32+
* Expiration timestamp
33+
*/
34+
@JsonProperty("expires_at")
35+
private Long expiresAt;
36+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.theokanning.openai.billing;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
6+
import java.util.List;
7+
8+
/**
9+
*
10+
*
11+
*/
12+
@Data
13+
public class Grants {
14+
private String object;
15+
@JsonProperty("data")
16+
private List<Datum> data;
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.theokanning.openai.billing;
2+
3+
import lombok.Data;
4+
5+
import java.math.BigDecimal;
6+
7+
/**
8+
* List of amount consumption
9+
*
10+
*/
11+
@Data
12+
public class LineItem {
13+
/**
14+
* model name
15+
*/
16+
private String name;
17+
/**
18+
* Expenditure amount
19+
*/
20+
private BigDecimal cost;
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.theokanning.openai.billing;
2+
3+
import lombok.Data;
4+
5+
/**
6+
*
7+
*
8+
*/
9+
@Data
10+
public class Plan {
11+
private String title;
12+
private String id;
13+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.theokanning.openai.billing;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Data;
5+
6+
/**
7+
* Account information
8+
*
9+
*
10+
*/
11+
@Data
12+
public class Subscription {
13+
@JsonProperty("object")
14+
private String object;
15+
@JsonProperty("has_payment_method")
16+
private boolean hasPaymentMethod;
17+
@JsonProperty("canceled")
18+
private boolean canceled;
19+
@JsonProperty("canceled_at")
20+
private Object canceledAt;
21+
@JsonProperty("delinquent")
22+
private Object delinquent;
23+
@JsonProperty("access_until")
24+
private long accessUntil;
25+
@JsonProperty("soft_limit")
26+
private long softLimit;
27+
@JsonProperty("hard_limit")
28+
private long hardLimit;
29+
@JsonProperty("system_hard_limit")
30+
private long systemHardLimit;
31+
@JsonProperty("soft_limit_usd")
32+
private double softLimitUsd;
33+
@JsonProperty("hard_limit_usd")
34+
private double hardLimitUsd;
35+
@JsonProperty("system_hard_limit_usd")
36+
private double systemHardLimitUsd;
37+
@JsonProperty("plan")
38+
private Plan plan;
39+
@JsonProperty("account_name")
40+
private String accountName;
41+
@JsonProperty("po_number")
42+
private Object poNumber;
43+
@JsonProperty("billing_email")
44+
private Object billingEmail;
45+
@JsonProperty("tax_ids")
46+
private Object taxIds;
47+
@JsonProperty("billing_address")
48+
private Object billingAddress;
49+
@JsonProperty("business_address")
50+
private Object businessAddress;
51+
}

0 commit comments

Comments
 (0)