-
Notifications
You must be signed in to change notification settings - Fork 59.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add tts #5459
add tts #5459
Changes from 12 commits
2f410fc
93f1762
f86b220
e9f90a4
ed5aea0
d8b1781
318e098
c5168c2
212605a
3ae8ec1
dfaafe3
a3b6647
10d7a64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { | |
LLMApi, | ||
LLMModel, | ||
MultimodalContent, | ||
SpeechOptions, | ||
} from "../api"; | ||
import Locale from "../../locales"; | ||
import { | ||
|
@@ -77,6 +78,10 @@ export class DoubaoApi implements LLMApi { | |
return res.choices?.at(0)?.message?.content ?? ""; | ||
} | ||
|
||
speech(options: SpeechOptions): Promise<ArrayBuffer> { | ||
throw new Error("Method not implemented."); | ||
} | ||
Comment on lines
+81
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Speech method added but not implemented. The Consider the following suggestions:
|
||
|
||
async chat(options: ChatOptions) { | ||
const messages = options.messages.map((v) => ({ | ||
role: v.role, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
import { ApiPath, Google, REQUEST_TIMEOUT_MS } from "@/app/constant"; | ||
import { ChatOptions, getHeaders, LLMApi, LLMModel, LLMUsage } from "../api"; | ||
import { | ||
ChatOptions, | ||
getHeaders, | ||
LLMApi, | ||
LLMModel, | ||
LLMUsage, | ||
SpeechOptions, | ||
} from "../api"; | ||
import { useAccessStore, useAppConfig, useChatStore } from "@/app/store"; | ||
import { getClientConfig } from "@/app/config/client"; | ||
import { DEFAULT_API_HOST } from "@/app/constant"; | ||
|
@@ -56,6 +63,10 @@ export class GeminiProApi implements LLMApi { | |
"" | ||
); | ||
} | ||
speech(options: SpeechOptions): Promise<ArrayBuffer> { | ||
throw new Error("Method not implemented."); | ||
} | ||
Comment on lines
+66
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Complete the implementation of the The Consider the following:
|
||
|
||
async chat(options: ChatOptions): Promise<void> { | ||
const apiClient = this; | ||
let multimodal = false; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,7 +14,13 @@ import { | |||||||||||||||
usePluginStore, | ||||||||||||||||
} from "@/app/store"; | ||||||||||||||||
import { stream } from "@/app/utils/chat"; | ||||||||||||||||
import { ChatOptions, getHeaders, LLMApi, LLMModel } from "../api"; | ||||||||||||||||
import { | ||||||||||||||||
ChatOptions, | ||||||||||||||||
getHeaders, | ||||||||||||||||
LLMApi, | ||||||||||||||||
LLMModel, | ||||||||||||||||
SpeechOptions, | ||||||||||||||||
} from "../api"; | ||||||||||||||||
import { getClientConfig } from "@/app/config/client"; | ||||||||||||||||
import { getMessageTextContent } from "@/app/utils"; | ||||||||||||||||
import { RequestPayload } from "./openai"; | ||||||||||||||||
|
@@ -53,6 +59,10 @@ export class MoonshotApi implements LLMApi { | |||||||||||||||
return res.choices?.at(0)?.message?.content ?? ""; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
speech(options: SpeechOptions): Promise<ArrayBuffer> { | ||||||||||||||||
throw new Error("Method not implemented."); | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+62
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Complete the implementation of the The Consider adding a TODO comment to track the pending implementation: + // TODO: Implement speech function
speech(options: SpeechOptions): Promise<ArrayBuffer> {
throw new Error("Method not implemented.");
} Committable suggestion
Suggested change
|
||||||||||||||||
|
||||||||||||||||
async chat(options: ChatOptions) { | ||||||||||||||||
const messages: ChatOptions["messages"] = []; | ||||||||||||||||
for (const v of options.messages) { | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ import { | |
LLMModel, | ||
LLMUsage, | ||
MultimodalContent, | ||
SpeechOptions, | ||
} from "../api"; | ||
import Locale from "../../locales"; | ||
import { getClientConfig } from "@/app/config/client"; | ||
|
@@ -78,7 +79,7 @@ export interface DalleRequestPayload { | |
export class ChatGPTApi implements LLMApi { | ||
private disableListModels = true; | ||
|
||
path(path: string): string { | ||
path(path: string, model?: string): string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. θΏιmodelηζδΉζ―οΌε₯½ε沑η¨ε°οΌ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. δΈι’ speech ιη¨ε°δΊ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pathθΏδΈͺε½ζ°ιι’ε₯½ε沑η¨ε°ε§οΌζ²‘ηε°ε |
||
const accessStore = useAccessStore.getState(); | ||
|
||
let baseUrl = ""; | ||
|
@@ -141,6 +142,44 @@ export class ChatGPTApi implements LLMApi { | |
return res.choices?.at(0)?.message?.content ?? res; | ||
} | ||
|
||
async speech(options: SpeechOptions): Promise<ArrayBuffer> { | ||
const requestPayload = { | ||
model: options.model, | ||
input: options.input, | ||
voice: options.voice, | ||
response_format: options.response_format, | ||
speed: options.speed, | ||
}; | ||
|
||
console.log("[Request] openai speech payload: ", requestPayload); | ||
|
||
const controller = new AbortController(); | ||
options.onController?.(controller); | ||
|
||
try { | ||
const speechPath = this.path(OpenaiPath.SpeechPath, options.model); | ||
const speechPayload = { | ||
method: "POST", | ||
body: JSON.stringify(requestPayload), | ||
signal: controller.signal, | ||
headers: getHeaders(), | ||
}; | ||
|
||
// make a fetch request | ||
const requestTimeoutId = setTimeout( | ||
() => controller.abort(), | ||
REQUEST_TIMEOUT_MS, | ||
); | ||
|
||
const res = await fetch(speechPath, speechPayload); | ||
clearTimeout(requestTimeoutId); | ||
return await res.arrayBuffer(); | ||
} catch (e) { | ||
console.log("[Request] failed to make a speech request", e); | ||
throw e; | ||
} | ||
} | ||
|
||
async chat(options: ChatOptions) { | ||
const modelConfig = { | ||
...useAppConfig.getState().modelConfig, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
LLMApi, | ||
LLMModel, | ||
MultimodalContent, | ||
SpeechOptions, | ||
} from "../api"; | ||
import Locale from "../../locales"; | ||
import { | ||
|
@@ -89,6 +90,10 @@ export class HunyuanApi implements LLMApi { | |
return res.Choices?.at(0)?.Message?.Content ?? ""; | ||
} | ||
|
||
speech(options: SpeechOptions): Promise<ArrayBuffer> { | ||
throw new Error("Method not implemented."); | ||
} | ||
Comment on lines
+93
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement the The Please consider the following:
|
||
|
||
async chat(options: ChatOptions) { | ||
const visionModel = isVisionModel(options.config.model); | ||
const messages = options.messages.map((v, index) => ({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement the
speech
method.The
speech
method has been added to theClaudeApi
class, but it is not yet implemented and throws an error. To provide the intended speech functionality, please implement the method body to handle theSpeechOptions
parameter and return aPromise<ArrayBuffer>
.Do you want me to generate a sample implementation for the
speech
method or open a GitHub issue to track this task?