-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from yuluo-yx/1207-yuluo/add-json-mode
feat: add response_format params
- Loading branch information
Showing
7 changed files
with
308 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...libaba-core/src/main/java/com/alibaba/cloud/ai/dashscope/api/DashScopeResponseFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.cloud.ai.dashscope.api; | ||
|
||
import java.util.Objects; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* Lets you specify the format of the returned content. Valid values: {"type": "text"} or | ||
* {"type": "json_object"}. When set to {"type": "json_object"}, a JSON string in standard | ||
* format is output. Params reference: | ||
* <a href="https://help.aliyun.com/zh/dashscope/developer-reference/qwen-api">...</a> | ||
* | ||
* @author yuluo | ||
* @author <a href="mailto:yuluo08290126@gmail.com">yuluo</a> | ||
*/ | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class DashScopeResponseFormat { | ||
|
||
/** | ||
* Parameters must be one of 'text' or 'json_object'. | ||
*/ | ||
@JsonProperty("type") | ||
private Type type; | ||
|
||
public Type getType() { | ||
|
||
return type; | ||
} | ||
|
||
public void setType(Type type) { | ||
|
||
this.type = type; | ||
} | ||
|
||
public DashScopeResponseFormat() { | ||
} | ||
|
||
public DashScopeResponseFormat(Type type) { | ||
|
||
this.type = type; | ||
} | ||
|
||
public static Builder builder() { | ||
|
||
return new Builder(); | ||
} | ||
|
||
/** | ||
* Builder for {@link DashScopeResponseFormat}. | ||
*/ | ||
public static class Builder { | ||
|
||
private Type type; | ||
|
||
public Builder type(Type type) { | ||
|
||
this.type = type; | ||
return this; | ||
} | ||
|
||
public DashScopeResponseFormat build() { | ||
|
||
return new DashScopeResponseFormat(this.type); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
|
||
return "DashScopeResponseFormat { " + "type='" + type + '}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
DashScopeResponseFormat that = (DashScopeResponseFormat) o; | ||
return Objects.equals(type, that.type); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(type); | ||
} | ||
|
||
/** | ||
* ResponseFormat type. Valid values: {"type": "text"} or {"type": "json_object"}. | ||
*/ | ||
public enum Type { | ||
|
||
/** | ||
* Generates a text response. (default) | ||
*/ | ||
@JsonProperty("text") | ||
TEXT, | ||
|
||
/** | ||
* Enables JSON mode, which guarantees the message the model generates is valid | ||
* JSON string. | ||
*/ | ||
@JsonProperty("json_object") | ||
JSON_OBJECT, | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.