Skip to content

Commit 0022664

Browse files
committed
Resolve Copilot comments
1 parent 8c11e21 commit 0022664

4 files changed

Lines changed: 15 additions & 16 deletions

File tree

internal/api/chat/create_conversation_message_stream_v2.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,9 @@ func (s *ChatServerV2) CreateConversationMessageStream(
281281
var llmProvider *models.LLMProviderConfig
282282
var customModel *models.CustomModel
283283
customModel = nil
284-
for _, m := range settings.CustomModels {
285-
if m.Slug == modelSlug {
286-
customModel = &m
287-
break
284+
for i := range settings.CustomModels {
285+
if settings.CustomModels[i].Slug == modelSlug {
286+
customModel = &settings.CustomModels[i]
288287
}
289288
}
290289

internal/api/mapper/user.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ func MapProtoSettingsToModel(settings *userv1.Settings) *models.Settings {
1313
for i, m := range settings.CustomModels {
1414
var id bson.ObjectID
1515

16-
if m.Id == "" {
16+
id, err := bson.ObjectIDFromHex(m.Id)
17+
if err != nil {
1718
id = bson.NewObjectID()
18-
} else {
19-
id, _ = bson.ObjectIDFromHex(m.Id)
2019
}
2120

2221
customModels[i] = models.CustomModel{

internal/models/llm_provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package models
22

33
// LLMProviderConfig holds the configuration for LLM API calls.
44
// If both Endpoint and APIKey are empty, the system default will be used.
5+
// If IsCustomModel is true, the user-requested slug with corresponding
6+
// API keys and endpoint should be used.
57
type LLMProviderConfig struct {
68
Endpoint string
79
APIKey string

webapp/_webapp/src/views/settings/sections/api-key-settings.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { Fragment, useState } from "react";
22
import { Icon } from "@iconify/react";
33
import { Modal } from "../../../components/modal";
44
import { SettingsSectionContainer, SettingsSectionTitle } from "./components";
@@ -10,15 +10,15 @@ export const ApiKeySettings = () => {
1010

1111
const [isShowModal, setIsShowModal] = useState<boolean>(false);
1212

13-
const handleCustomModelChange = (newModel: CustomModel, isDelete: boolean) => {
13+
const handleCustomModelChange = async (newModel: CustomModel, isDelete: boolean) => {
1414
const otherCustomModels = Array.from(settings?.customModels || []).filter((model) => model.id != newModel.id);
1515

1616
if (isDelete) {
17-
updateSettings({
17+
await updateSettings({
1818
customModels: otherCustomModels,
1919
});
2020
} else {
21-
updateSettings({
21+
await updateSettings({
2222
customModels: [
2323
...otherCustomModels,
2424
{
@@ -50,12 +50,11 @@ export const ApiKeySettings = () => {
5050
<div className="flex flex-col h-[80vh] gap-4 p-4 overflow-y-auto">
5151
<CustomModelSection key={"new_custom_model"} isNew onChange={handleCustomModelChange} />
5252
{Array.from(settings?.customModels || []).map((m) => (
53-
<>
53+
<Fragment key={m.id}>
5454
<hr></hr>
5555
<CustomModelSection
5656
isNew={false}
5757
onChange={handleCustomModelChange}
58-
key={m.id}
5958
model={{
6059
id: m.id,
6160
name: m.name,
@@ -68,7 +67,7 @@ export const ApiKeySettings = () => {
6867
outputPrice: m.outputPrice,
6968
}}
7069
/>
71-
</>
70+
</Fragment>
7271
))}
7372
</div>
7473
}
@@ -126,7 +125,7 @@ const CustomModelSection = ({ isNew, onChange, model: customModel }: CustomModel
126125
const detailInputClassName = `${baseClassName} ${isEditing || isNew ? borderedInputClassName : ""} flex-1 noselect focus:outline-none text-xs text-default-700 placeholder:text-default-400`;
127126
const errorInputClassName = "!border-red-500 focus:!border-red-500";
128127

129-
const handleOnChange = (isDelete: boolean) => {
128+
const handleOnChange = async (isDelete: boolean) => {
130129
if (
131130
modelName.trim().length < 1 ||
132131
slug.trim().length < 1 ||
@@ -140,7 +139,7 @@ const CustomModelSection = ({ isNew, onChange, model: customModel }: CustomModel
140139
return;
141140
}
142141

143-
onChange(
142+
await onChange(
144143
{
145144
id: id,
146145
name: modelName.trim(),

0 commit comments

Comments
 (0)