Skip to content

Commit

Permalink
Update the tinystruct framework version to be 1.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ver committed Dec 26, 2024
1 parent 10b542f commit 3b07398
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 56 deletions.
2 changes: 1 addition & 1 deletion bin/dispatcher
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh
ROOT="$(pwd)"
VERSION="1.4.1"
VERSION="1.4.5"
cd "$(dirname "$0")" || exit
cd "../"
# Navigate to the root directory
Expand Down
2 changes: 1 addition & 1 deletion bin/dispatcher.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ set "JAVA_CMD=%JAVA_HOME%\bin\java.exe"

@REM Consolidate classpath entries, initialize ROOT and VERSION
set "ROOT=%~dp0..\"
set "VERSION=1.4.2"
set "VERSION=1.4.5"
set "classpath=%ROOT%target\classes;%ROOT%lib\tinystruct-%VERSION%-jar-with-dependencies.jar;%ROOT%lib\tinystruct-%VERSION%.jar;%ROOT%lib\*;%ROOT%WEB-INF\lib\*;%ROOT%WEB-INF\classes;%USERPROFILE%\.m2\repository\org\tinystruct\tinystruct\%VERSION%\tinystruct-%VERSION%-jar-with-dependencies.jar;%USERPROFILE%\.m2\repository\org\tinystruct\tinystruct\%VERSION%\tinystruct-%VERSION%.jar"

@REM Run Java application
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/custom/ai/OpenAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ public class OpenAI extends AbstractApplication implements Provider {

@Action("openai")
public Builder call() throws ApplicationException {
if (this.context.getAttribute("api") == null) {
if (getContext().getAttribute("api") == null) {
throw new ApplicationException("API is required");
}
Builder payload = null;
String contentType = "application/json";
Object image = null, mask = null;
if (this.context.getAttribute("content-type") != null && this.context.getAttribute("content-type").toString().equalsIgnoreCase("multipart/form-data")) {
if (getContext().getAttribute("content-type") != null && getContext().getAttribute("content-type").toString().equalsIgnoreCase("multipart/form-data")) {
contentType = "multipart/form-data";

if ((image = this.context.getAttribute("image")) != null && image.toString().startsWith("data:image/png;base64,")) {
if ((image = getContext().getAttribute("image")) != null && image.toString().startsWith("data:image/png;base64,")) {
image = image.toString().substring("data:image/png;base64,".length());
}

if ((mask = this.context.getAttribute("mask")) != null && mask.toString().startsWith("data:image/png;base64,")) {
if ((mask = getContext().getAttribute("mask")) != null && mask.toString().startsWith("data:image/png;base64,")) {
mask = mask.toString().substring("data:image/png;base64,".length());
}
} else if (this.context.getAttribute("payload") == null) {
} else if (getContext().getAttribute("payload") == null) {
throw new ApplicationException("Payload is required");
}

String api = this.context.getAttribute("api").toString();
String api = getContext().getAttribute("api").toString();

// Replace YOUR_API_KEY with your actual API key
String API_KEY = this.config.get("openai.api_key");
Expand All @@ -52,8 +52,8 @@ public Builder call() throws ApplicationException {
HttpRequestBuilder builder = new HttpRequestBuilder();
builder.setHeaders(headers).setMethod(Method.POST);

if (this.context.getAttribute("payload") != null) {
payload = (Builder) this.context.getAttribute("payload");
if (getContext().getAttribute("payload") != null) {
payload = (Builder) getContext().getAttribute("payload");
if (contentType.equalsIgnoreCase("multipart/form-data")) {
builder.setParameter("prompt", payload.get("prompt").toString());
builder.setParameter("user", payload.get("user").toString());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/custom/ai/SearchAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class SearchAI extends AbstractApplication implements Provider {
@Action("search")
@Override
public Builder call() throws ApplicationException {
if (this.context.getAttribute("--query") == null) {
if (getContext().getAttribute("--query") == null) {
throw new ApplicationException("query is required");
}
String query = this.context.getAttribute("--query").toString().trim();
String query = getContext().getAttribute("--query").toString().trim();

HttpRequestBuilder builder = new HttpRequestBuilder();
Headers headers = new Headers();
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/custom/ai/StabilityAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ public class StabilityAI extends AbstractApplication implements Provider {

@Action("stability")
public Builder call() throws ApplicationException {
if (this.context.getAttribute("api") == null) {
if (getContext().getAttribute("api") == null) {
throw new ApplicationException("API is required");
}
Builder payload = null;
String contentType = "application/json";
Object image = null;
if (this.context.getAttribute("content-type") != null && this.context.getAttribute("content-type").toString().equalsIgnoreCase("multipart/form-data")) {
if (getContext().getAttribute("content-type") != null && getContext().getAttribute("content-type").toString().equalsIgnoreCase("multipart/form-data")) {
contentType = "multipart/form-data";

if ((image = this.context.getAttribute("image")) != null && image.toString().startsWith("data:image/png;base64,")) {
if ((image = getContext().getAttribute("image")) != null && image.toString().startsWith("data:image/png;base64,")) {
image = image.toString().substring("data:image/png;base64,".length());
}
} else if (this.context.getAttribute("payload") == null) {
} else if (getContext().getAttribute("payload") == null) {
throw new ApplicationException("Payload is required");
}

String api = this.context.getAttribute("api").toString();
String api = getContext().getAttribute("api").toString();

// Replace YOUR_API_KEY with your actual API key
String API_KEY = this.config.get("stability.api_key");
Expand All @@ -47,8 +47,8 @@ public Builder call() throws ApplicationException {
builder.setVersion(Version.HTTP1_1);
builder.setHeaders(headers).setMethod(Method.POST);

if (this.context.getAttribute("payload") != null) {
payload = (Builder) this.context.getAttribute("payload");
if (getContext().getAttribute("payload") != null) {
payload = (Builder) getContext().getAttribute("payload");
if (contentType.equalsIgnoreCase("multipart/form-data")) {
builder.setParameter("text_prompts[0][text]", payload.get("text_prompts[0][text]").toString());
builder.setParameter("cfg_scale", Float.parseFloat(payload.get("cfg_scale").toString()));
Expand Down
Loading

0 comments on commit 3b07398

Please sign in to comment.