Skip to content

Commit 0760b19

Browse files
committed
feat: can select model provider in chat provider
1 parent 5a5e74e commit 0760b19

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

web/src/ProviderEditPage.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ProviderEditPage extends React.Component {
3939
providerName: props.match.params.providerName,
4040
provider: null,
4141
originalProvider: null,
42+
modelProviders: [],
4243
refreshButtonLoading: false,
4344
isNewProvider: props.location?.state?.isNewProvider || false,
4445
};
@@ -48,6 +49,31 @@ class ProviderEditPage extends React.Component {
4849
this.getProvider();
4950
}
5051

52+
getModelProviders() {
53+
if (this.state.modelProviders.length > 0) {
54+
return;
55+
}
56+
ProviderBackend.getProviders("admin")
57+
.then((res) => {
58+
if (res.status === "ok") {
59+
this.setState({
60+
modelProviders: res.data.filter(provider => provider.category === "Model"),
61+
});
62+
}
63+
});
64+
}
65+
66+
renderModelProviderOption(provider, index) {
67+
return (
68+
<Option key={index} value={provider.name}>
69+
<img width={20} height={20} style={{marginBottom: "3px", marginRight: "10px"}}
70+
src={Setting.getProviderLogoURL({category: provider.category, type: provider.type})}
71+
alt={provider.name} />
72+
{provider.displayName || provider.name}
73+
</Option>
74+
);
75+
}
76+
5177
getProvider() {
5278
ProviderBackend.getProvider("admin", this.state.providerName)
5379
.then((res) => {
@@ -566,7 +592,7 @@ class ProviderEditPage extends React.Component {
566592
(this.state.provider.category === "Storage" && this.state.provider.type !== "OpenAI File System")) ||
567593
(this.state.provider.category === "Blockchain" && !["ChainMaker", "Ethereum"].includes(this.state.provider.type)) ||
568594
((this.state.provider.category === "Model" || this.state.provider.category === "Embedding") && this.state.provider.type === "Azure") ||
569-
(!(["Storage", "Model", "Embedding", "Text-to-Speech", "Speech-to-Text", "Agent", "Blockchain"].includes(this.state.provider.category)))
595+
(!(["Storage", "Model", "Embedding", "Text-to-Speech", "Speech-to-Text", "Agent", "Blockchain", "Chat"].includes(this.state.provider.category)))
570596
) ? (
571597
<Row style={{marginTop: "20px"}} >
572598
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
@@ -580,6 +606,27 @@ class ProviderEditPage extends React.Component {
580606
</Row>
581607
) : null
582608
}
609+
{
610+
this.state.provider.category === "Chat" ? (
611+
<Row style={{marginTop: "20px"}} >
612+
<Col style={{marginTop: "5px"}} span={(Setting.isMobile()) ? 22 : 2}>
613+
{this.getClientIdLabel(this.state.provider)} :
614+
</Col>
615+
<Col span={22} >
616+
<Select virtual={false} disabled={isRemote} style={{width: "100%"}} value={this.state.provider.clientId}
617+
onChange={(value) => this.updateProviderField("clientId", value)}
618+
onDropdownVisibleChange={(open) => {if (open) {this.getModelProviders();}}}
619+
showSearch
620+
filterOption={(input, option) =>
621+
option.children[1].toLowerCase().includes(input.toLowerCase())
622+
}
623+
>
624+
{this.state.modelProviders.map((provider, index) => this.renderModelProviderOption(provider, index))}
625+
</Select>
626+
</Col>
627+
</Row>
628+
) : null
629+
}
583630
{
584631
(this.state.provider.type === "Local") ? (
585632
<>

0 commit comments

Comments
 (0)