用户结构修改以及openai获取客户端令牌
This commit is contained in:
@@ -13,6 +13,7 @@ import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
/**
|
||||
* 共同 信息 服务实现类
|
||||
@@ -24,13 +25,21 @@ import java.util.Map;
|
||||
@Service
|
||||
public class CommonServiceImpl implements ICommonService {
|
||||
|
||||
// OpenAI API密钥,需要替换为你自己的密钥
|
||||
@Value("${chatGpt.apiKey}")
|
||||
private String apiKey;
|
||||
// API端点URL
|
||||
@Value("${chatGpt.apiClientTokenUrl}")
|
||||
@Value("${whisper.apiClientTokenUrl}")
|
||||
private String apiClientTokenUrl;
|
||||
|
||||
@Value("${whisper.model}")
|
||||
private String MODEL;
|
||||
|
||||
@Value("${whisper.apiKey}")
|
||||
private String apiKey;
|
||||
|
||||
@Value("${whisper.language}")
|
||||
private String language;
|
||||
|
||||
@Value("${whisper.prompt}")
|
||||
private String prompt;
|
||||
|
||||
/**
|
||||
* 获取openAi客户端临时Key
|
||||
* @return
|
||||
@@ -46,8 +55,13 @@ public class CommonServiceImpl implements ICommonService {
|
||||
.build();
|
||||
|
||||
// 2. 构建请求体(空 JSON 对象)
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String requestBody = "";
|
||||
Map<String,Object> params = new HashMap<>();
|
||||
Map<String, String> bodyEntity = new HashMap<>();
|
||||
bodyEntity.put("model",MODEL);
|
||||
bodyEntity.put("prompt",prompt);
|
||||
bodyEntity.put("language",language);
|
||||
params.put("input_audio_transcription",bodyEntity);
|
||||
String requestBody = JSONUtil.toJsonStr(params);
|
||||
// 3. 构建 HTTP 请求
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(apiClientTokenUrl))
|
||||
@@ -65,8 +79,11 @@ public class CommonServiceImpl implements ICommonService {
|
||||
// 解析响应为实体类
|
||||
System.out.println(JSONUtil.toJsonStr(response.body()));
|
||||
Map entity = JSONUtil.toBean(response.body(), Map.class);
|
||||
dto.setClientSecret(entity.get("id").toString());
|
||||
// dto.setExpiresAt(Long.valueOf(entity.get("expires_at").toString()));
|
||||
if(entity.get("client_secret") != null) {
|
||||
Map data = (Map) entity.get("client_secret");
|
||||
dto.setClientSecret(data.get("value").toString());
|
||||
dto.setExpiresAt(Long.valueOf(data.get("expires_at").toString()));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -154,7 +154,10 @@ whisper:
|
||||
apiUrl: https://api.openai.com/v1/audio/transcriptions
|
||||
model: whisper-1
|
||||
apiKey: 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
|
||||
language: zh
|
||||
language: en
|
||||
apiClientTokenUrl: https://api.openai.com/v1/realtime/sessions
|
||||
prompt: This is a clear conversation in English. The user is speaking naturally through their device microphone. Please transcribe accurately with proper punctuation and natural speech patterns.
|
||||
|
||||
|
||||
# AI 聊天
|
||||
chatGpt:
|
||||
|
||||
@@ -159,9 +159,11 @@ elevenLabs:
|
||||
# 语音转文本
|
||||
whisper:
|
||||
apiUrl: https://api.openai.com/v1/audio/transcriptions
|
||||
model: gpt-4o-mini-transcribe
|
||||
model: whisper-1
|
||||
apiKey: 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
|
||||
language: en
|
||||
apiClientTokenUrl: https://api.openai.com/v1/realtime/sessions
|
||||
prompt: This is a clear conversation in English. The user is speaking naturally through their device microphone. Please transcribe accurately with proper punctuation and natural speech patterns.
|
||||
|
||||
# AI 聊天
|
||||
chatGpt:
|
||||
@@ -169,7 +171,7 @@ chatGpt:
|
||||
apiUrl: https://api.openai.com/v1/chat/completions
|
||||
model: ft:gpt-3.5-turbo-0125:vetti:construction-labourer-test:CWKBNvE2
|
||||
role: system
|
||||
apiClientTokenUrl: https://api.openai.com/v1/realtime/sessions
|
||||
|
||||
|
||||
|
||||
http:
|
||||
|
||||
@@ -159,9 +159,11 @@ elevenLabs:
|
||||
# 语音转文本
|
||||
whisper:
|
||||
apiUrl: https://api.openai.com/v1/audio/transcriptions
|
||||
model: gpt-4o-mini-transcribe
|
||||
model: whisper-1
|
||||
apiKey: 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
|
||||
language: en
|
||||
apiClientTokenUrl: https://api.openai.com/v1/realtime/sessions
|
||||
prompt: This is a clear conversation in English. The user is speaking naturally through their device microphone. Please transcribe accurately with proper punctuation and natural speech patterns.
|
||||
|
||||
# AI 聊天
|
||||
chatGpt:
|
||||
@@ -169,7 +171,7 @@ chatGpt:
|
||||
apiUrl: https://api.openai.com/v1/chat/completions
|
||||
model: ft:gpt-3.5-turbo-0125:vetti:construction-labourer-test:CWKBNvE2
|
||||
role: system
|
||||
apiClientTokenUrl: https://api.openai.com/v1/realtime/sessions
|
||||
|
||||
|
||||
|
||||
http:
|
||||
|
||||
Reference in New Issue
Block a user