-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 新增对DeepSeek平台的支持、新增stream_options可以直接统计usage、新增错误拦截器`ErrorInter…
…ceptor.java`、发布0.3.0版本
- Loading branch information
Showing
24 changed files
with
835 additions
and
54 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
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
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
40 changes: 40 additions & 0 deletions
40
ai4j-spring-boot-stater/src/main/java/io/github/lnyocly/ai4j/DeepSeekConfigProperties.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,40 @@ | ||
package io.github.lnyocly.ai4j; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
/** | ||
* @Author cly | ||
* @Description TODO | ||
* @Date 2024/8/29 15:01 | ||
*/ | ||
@ConfigurationProperties(prefix = "ai.deepseek") | ||
public class DeepSeekConfigProperties { | ||
|
||
private String apiHost = "https://api.deepseek.com/"; | ||
private String apiKey = ""; | ||
private String chat_completion = "chat/completions"; | ||
|
||
public String getApiHost() { | ||
return apiHost; | ||
} | ||
|
||
public void setApiHost(String apiHost) { | ||
this.apiHost = apiHost; | ||
} | ||
|
||
public String getChat_completion() { | ||
return chat_completion; | ||
} | ||
|
||
public void setChat_completion(String chat_completion) { | ||
this.chat_completion = chat_completion; | ||
} | ||
|
||
public String getApiKey() { | ||
return apiKey; | ||
} | ||
|
||
public void setApiKey(String apiKey) { | ||
this.apiKey = apiKey; | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
ai4j/src/main/java/io/github/lnyocly/ai4j/config/DeepSeekConfig.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,21 @@ | ||
package io.github.lnyocly.ai4j.config; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* @Author cly | ||
* @Description DeepSeek 配置文件 | ||
* @Date 2024/8/29 10:31 | ||
*/ | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class DeepSeekConfig { | ||
|
||
private String apiHost = "https://api.deepseek.com/"; | ||
private String apiKey = ""; | ||
private String chat_completion = "chat/completions"; | ||
} |
39 changes: 39 additions & 0 deletions
39
ai4j/src/main/java/io/github/lnyocly/ai4j/interceptor/ErrorInterceptor.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,39 @@ | ||
package io.github.lnyocly.ai4j.interceptor; | ||
|
||
import io.github.lnyocly.ai4j.exception.CommonException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* @Author cly | ||
* @Description 错误处理器 | ||
* @Date 2024/8/29 14:55 | ||
*/ | ||
@Slf4j | ||
public class ErrorInterceptor implements Interceptor { | ||
@NotNull | ||
@Override | ||
public Response intercept(@NotNull Chain chain) throws IOException { | ||
Request original = chain.request(); | ||
|
||
Response response = chain.proceed(original); | ||
|
||
if(!response.isSuccessful()){ | ||
//response.close(); | ||
String errorMsg = response.body().string(); | ||
|
||
log.error("AI服务请求异常:{}", errorMsg); | ||
throw new CommonException(errorMsg); | ||
|
||
|
||
} | ||
|
||
|
||
return response; | ||
} | ||
} |
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.