-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
37 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
import org.springframework.aot.hint.RuntimeHintsRegistrar; | ||
|
||
/** | ||
* The TongYiRuntimeHints class is responsible for registering runtime hints for TongYiAI. | ||
* | ||
* @author yuluo | ||
* @author [email protected] | ||
*/ | ||
|
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 |
---|---|---|
|
@@ -43,6 +43,9 @@ | |
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* | ||
* {@link ChatClient} and {@link StreamingChatClient} implementation for {@literal Alibaba DashScope} | ||
* backed by {@link Generation}. | ||
* @author yuluo | ||
* @author [email protected] | ||
*/ | ||
|
@@ -51,13 +54,26 @@ public class TongYiChatClient implements ChatClient, StreamingChatClient { | |
|
||
private static final Logger logger = LoggerFactory.getLogger(TongYiChatClient.class); | ||
|
||
/** | ||
* DashScope generation client. | ||
*/ | ||
private final Generation generation; | ||
|
||
/** | ||
* The TongYi models default chat completion api. | ||
*/ | ||
private TongYiChatOptions defaultOptions; | ||
|
||
/** | ||
* User role message manager. | ||
*/ | ||
@Autowired | ||
private MessageManager msgManager; | ||
|
||
/** | ||
* Initializes an instance of the TongYiChatClient. | ||
* @param generation DashScope generation client. | ||
*/ | ||
public TongYiChatClient(Generation generation) { | ||
|
||
this(generation, | ||
|
@@ -69,6 +85,11 @@ public TongYiChatClient(Generation generation) { | |
); | ||
} | ||
|
||
/** | ||
* Create a TongYi models client. | ||
* @param generation DashScope model generation client. | ||
* @param options TongYi default chat completion api. | ||
*/ | ||
public TongYiChatClient(Generation generation, TongYiChatOptions options) { | ||
|
||
this.generation = generation; | ||
|
@@ -142,6 +163,11 @@ public Flux<ChatResponse> stream(Prompt prompt) { | |
|
||
} | ||
|
||
/** | ||
* Configuration properties to Qwen model params. | ||
* @param prompt {@link Prompt} | ||
* @return Qwen models params {@link QwenParam} | ||
*/ | ||
private QwenParam toTongYiChatParams(Prompt prompt) { | ||
|
||
Constants.apiKey = getKey(); | ||
|
@@ -173,7 +199,7 @@ private ChatGenerationMetadata generateChoiceMetadata(GenerationOutput.Choice ch | |
/** | ||
* Get TongYi model api_key . | ||
* todo: Get key from env and env_file. | ||
* @return api_key | ||
* @return api_key. | ||
*/ | ||
private String getKey() { | ||
|
||
|
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 |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
import com.alibaba.dashscope.aigc.generation.Generation; | ||
|
||
/** | ||
* TongYi models constants. | ||
* | ||
* @author yuluo | ||
* @author [email protected] | ||
*/ | ||
|
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 |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
package com.alibaba.cloud.ai.tongyi.exception; | ||
|
||
/** | ||
* TongYi models runtime exception. | ||
* | ||
* @author yuluo | ||
* @author [email protected] | ||
*/ | ||
|
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 |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
import org.springframework.util.Assert; | ||
|
||
/** | ||
* {@link ChatResponseMetadata} implementation for {@literal Alibaba DashScope}. | ||
* | ||
* @author yuluo | ||
* @author [email protected] | ||
*/ | ||
|
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 |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
import org.springframework.util.Assert; | ||
|
||
/** | ||
* {@link Usage} implementation for {@literal Alibaba DashScope}. | ||
* | ||
* @author yuluo | ||
* @author [email protected] | ||
*/ | ||
|