Skip to content

Commit

Permalink
chore: code format wit spring javaformat
Browse files Browse the repository at this point in the history
  • Loading branch information
linux-china committed Jul 19, 2024
1 parent 442e794 commit be34984
Show file tree
Hide file tree
Showing 5 changed files with 391 additions and 379 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,130 +13,133 @@
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ChatMessage {

private ChatMessageRole role;

private String content;

/**
* the name of the author of this message
*/
private String name;

@JsonProperty("tool_calls")
private List<ToolCall> toolCalls;

public ChatMessage() {
}

public ChatMessage(ChatMessageRole role, String content) {
this.role = role;
this.content = content;
}


public ChatMessageRole getRole() {
return role;
}

public void setRole(ChatMessageRole role) {
this.role = role;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<ToolCall> getToolCalls() {
return toolCalls;
}

public void setToolCalls(List<ToolCall> toolCalls) {
this.toolCalls = toolCalls;
}

public FunctionCall findFunctionCall() {
if (toolCalls != null && !toolCalls.isEmpty()) {
for (ToolCall toolCall : toolCalls) {
if (Objects.equals(toolCall.getType(), "function")) {
return toolCall.getFunction();
}
}
}
return null;
}

@JsonIgnore
public Mono<String> getReplyCombinedText() {
if (content != null) {
return Mono.just(content);
}
if (toolCalls != null) {
for (ToolCall toolCall : toolCalls) {
final FunctionCall functionCall = toolCall.getFunction();
if (functionCall.getFunctionStub() != null) {
try {
final Object result = functionCall.getFunctionStub().call();
if (result != null) {
if (result instanceof Mono) {
return ((Mono<?>) result).map(GPTFunctionUtils::toTextPlain);
} else {
return Mono.just(result).map(GPTFunctionUtils::toTextPlain);
}
}
} catch (Exception e) {
return Mono.error(e);
}
}
}

}
return Mono.empty();
}

@JsonIgnore
public <T> Mono<T> getFunctionResult() {
if (toolCalls != null) {
final FunctionCall functionCall = toolCalls.get(0).getFunction();
if (functionCall.getFunctionStub() != null) {
try {
final Object result = functionCall.getFunctionStub().call();
if (result != null) {
if (result instanceof Mono) {
return (Mono<T>) result;
} else {
return (Mono<T>) Mono.just(result);
}
}
} catch (Exception e) {
return Mono.error(e);
}
}
}
return Mono.empty();
}

public static ChatMessage systemMessage(@Nonnull String content) {
return new ChatMessage(ChatMessageRole.system, content);
}

public static ChatMessage userMessage(@Nonnull String content) {
return new ChatMessage(ChatMessageRole.user, content);
}

public static ChatMessage assistantMessage(@Nonnull String content) {
return new ChatMessage(ChatMessageRole.assistant, content);
}
private ChatMessageRole role;

private String content;

/**
* the name of the author of this message
*/
private String name;

@JsonProperty("tool_calls")
private List<ToolCall> toolCalls;

public ChatMessage() {
}

public ChatMessage(ChatMessageRole role, String content) {
this.role = role;
this.content = content;
}

public ChatMessageRole getRole() {
return role;
}

public void setRole(ChatMessageRole role) {
this.role = role;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<ToolCall> getToolCalls() {
return toolCalls;
}

public void setToolCalls(List<ToolCall> toolCalls) {
this.toolCalls = toolCalls;
}

public FunctionCall findFunctionCall() {
if (toolCalls != null && !toolCalls.isEmpty()) {
for (ToolCall toolCall : toolCalls) {
if (Objects.equals(toolCall.getType(), "function")) {
return toolCall.getFunction();
}
}
}
return null;
}

@JsonIgnore
public Mono<String> getReplyCombinedText() {
if (content != null) {
return Mono.just(content);
}
if (toolCalls != null) {
for (ToolCall toolCall : toolCalls) {
final FunctionCall functionCall = toolCall.getFunction();
if (functionCall.getFunctionStub() != null) {
try {
final Object result = functionCall.getFunctionStub().call();
if (result != null) {
if (result instanceof Mono) {
return ((Mono<?>) result).map(GPTFunctionUtils::toTextPlain);
}
else {
return Mono.just(result).map(GPTFunctionUtils::toTextPlain);
}
}
}
catch (Exception e) {
return Mono.error(e);
}
}
}

}
return Mono.empty();
}

@JsonIgnore
public <T> Mono<T> getFunctionResult() {
if (toolCalls != null) {
final FunctionCall functionCall = toolCalls.get(0).getFunction();
if (functionCall.getFunctionStub() != null) {
try {
final Object result = functionCall.getFunctionStub().call();
if (result != null) {
if (result instanceof Mono) {
return (Mono<T>) result;
}
else {
return (Mono<T>) Mono.just(result);
}
}
}
catch (Exception e) {
return Mono.error(e);
}
}
}
return Mono.empty();
}

public static ChatMessage systemMessage(@Nonnull String content) {
return new ChatMessage(ChatMessageRole.system, content);
}

public static ChatMessage userMessage(@Nonnull String content) {
return new ChatMessage(ChatMessageRole.user, content);
}

public static ChatMessage assistantMessage(@Nonnull String content) {
return new ChatMessage(ChatMessageRole.assistant, content);
}

}
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
package org.mvnsearch.chatgpt.model.completion.chat;


public class ChatTool {
private String type = "function";
private ChatFunction function;

public ChatTool() {
}
private String type = "function";

private ChatFunction function;

public ChatTool() {
}

public ChatTool(ChatFunction function) {
this.function = function;
}

public ChatTool(ChatFunction function) {
this.function = function;
}
public String getType() {
return type;
}

public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}

public void setType(String type) {
this.type = type;
}
public ChatFunction getFunction() {
return function;
}

public ChatFunction getFunction() {
return function;
}
public void setFunction(ChatFunction function) {
this.function = function;
}

public void setFunction(ChatFunction function) {
this.function = function;
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
package org.mvnsearch.chatgpt.model.completion.chat;

public class ToolCall {
private String id;
private String type;
private FunctionCall function;

public ToolCall() {
}
private String id;

public String getId() {
return id;
}
private String type;

public void setId(String id) {
this.id = id;
}
private FunctionCall function;

public String getType() {
return type;
}
public ToolCall() {
}

public void setType(String type) {
this.type = type;
}
public String getId() {
return id;
}

public FunctionCall getFunction() {
return function;
}
public void setId(String id) {
this.id = id;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public FunctionCall getFunction() {
return function;
}

public void setFunction(FunctionCall function) {
this.function = function;
}

public void setFunction(FunctionCall function) {
this.function = function;
}
}
Loading

0 comments on commit be34984

Please sign in to comment.