Skip to content

Commit

Permalink
feat: sd setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Dogtiti committed Jul 23, 2024
1 parent 908ee00 commit 3935c72
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 5 deletions.
41 changes: 41 additions & 0 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
ServiceProvider,
SlotID,
UPDATE_URL,
Stability,
} from "../constant";
import { Prompt, SearchService, usePromptStore } from "../store/prompt";
import { ErrorBoundary } from "./error";
Expand Down Expand Up @@ -1041,6 +1042,45 @@ export function Settings() {
</>
);

const stabilityConfigComponent = accessStore.provider ===
ServiceProvider.Stability && (
<>
<ListItem
title={Locale.Settings.Access.Stability.Endpoint.Title}
subTitle={
Locale.Settings.Access.Stability.Endpoint.SubTitle +
Stability.ExampleEndpoint
}
>
<input
type="text"
value={accessStore.stabilityUrl}
placeholder={Stability.ExampleEndpoint}
onChange={(e) =>
accessStore.update(
(access) => (access.stabilityUrl = e.currentTarget.value),
)
}
></input>
</ListItem>
<ListItem
title={Locale.Settings.Access.Stability.ApiKey.Title}
subTitle={Locale.Settings.Access.Stability.ApiKey.SubTitle}
>
<PasswordInput
value={accessStore.stabilityApiKey}
type="text"
placeholder={Locale.Settings.Access.Stability.ApiKey.Placeholder}
onChange={(e) => {
accessStore.update(
(access) => (access.stabilityApiKey = e.currentTarget.value),
);
}}
/>
</ListItem>
</>
);

return (
<ErrorBoundary>
<div className="window-header" data-tauri-drag-region>
Expand Down Expand Up @@ -1324,6 +1364,7 @@ export function Settings() {
{baiduConfigComponent}
{byteDanceConfigComponent}
{alibabaConfigComponent}
{stabilityConfigComponent}
</>
)}
</>
Expand Down
3 changes: 2 additions & 1 deletion app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ export enum ModelProvider {
Qwen = "Qwen",
}

export const StabilityPath = {
export const Stability = {
GeneratePath: "v2beta/stable-image/generate",
ExampleEndpoint: "https://api.stability.ai",
};

export const Anthropic = {
Expand Down
11 changes: 11 additions & 0 deletions app/locales/cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,17 @@ const cn = {
SubTitle: "样例:",
},
},
Stability: {
ApiKey: {
Title: "接口密钥",
SubTitle: "使用自定义 Stability API Key",
Placeholder: "Stability API Key",
},
Endpoint: {
Title: "接口地址",
SubTitle: "样例:",
},
},
CustomModel: {
Title: "自定义模型名",
SubTitle: "增加自定义模型可选项,使用英文逗号隔开",
Expand Down
11 changes: 11 additions & 0 deletions app/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,17 @@ const en: LocaleType = {
SubTitle: "Example: ",
},
},
Stability: {
ApiKey: {
Title: "Stability API Key",
SubTitle: "Use a custom Stability API Key",
Placeholder: "Stability API Key",
},
Endpoint: {
Title: "Endpoint Address",
SubTitle: "Example: ",
},
},
CustomModel: {
Title: "Custom Models",
SubTitle: "Custom model options, seperated by comma",
Expand Down
6 changes: 4 additions & 2 deletions app/store/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const DEFAULT_ALIBABA_URL = isApp
? DEFAULT_API_HOST + "/api/proxy/alibaba"
: ApiPath.Alibaba;

console.log("DEFAULT_ANTHROPIC_URL", DEFAULT_ANTHROPIC_URL);

const DEFAULT_ACCESS_STATE = {
accessCode: "",
useCustomConfig: false,
Expand Down Expand Up @@ -80,6 +78,10 @@ const DEFAULT_ACCESS_STATE = {
alibabaUrl: DEFAULT_ALIBABA_URL,
alibabaApiKey: "",

//stability
stabilityUrl: "",
stabilityApiKey: "",

// server config
needCode: true,
hideUserApiKey: false,
Expand Down
4 changes: 2 additions & 2 deletions app/store/sd.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StabilityPath, StoreKey } from "@/app/constant";
import { Stability, StoreKey } from "@/app/constant";
import { getHeaders } from "@/app/client/api";
import { createPersistStore } from "@/app/utils/store";
import { nanoid } from "nanoid";
Expand Down Expand Up @@ -63,7 +63,7 @@ export const useSdStore = createPersistStore<
}
const headers = getHeaders();
delete headers["Content-Type"];
fetch(`/api/stability/${StabilityPath.GeneratePath}/${data.model}`, {
fetch(`/api/stability/${Stability.GeneratePath}/${data.model}`, {
method: "POST",
headers: {
...headers,
Expand Down

0 comments on commit 3935c72

Please sign in to comment.