mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 12:05:54 +00:00
feat: model editing
This commit is contained in:
@@ -19,7 +19,7 @@ class LLMModelsRouterGroup(group.RouterGroup):
|
||||
|
||||
return self.success(data={'uuid': model_uuid})
|
||||
|
||||
@self.route('/<model_uuid>', methods=['GET', 'DELETE'])
|
||||
@self.route('/<model_uuid>', methods=['GET', 'PUT', 'DELETE'])
|
||||
async def _(model_uuid: str) -> str:
|
||||
if quart.request.method == 'GET':
|
||||
model = await self.ap.model_service.get_llm_model(model_uuid)
|
||||
@@ -28,12 +28,12 @@ class LLMModelsRouterGroup(group.RouterGroup):
|
||||
return self.http_status(404, -1, 'model not found')
|
||||
|
||||
return self.success(data={'model': model})
|
||||
# elif quart.request.method == 'PUT':
|
||||
# json_data = await quart.request.json
|
||||
elif quart.request.method == 'PUT':
|
||||
json_data = await quart.request.json
|
||||
|
||||
# await self.ap.model_service.update_llm_model(model_uuid, json_data)
|
||||
await self.ap.model_service.update_llm_model(model_uuid, json_data)
|
||||
|
||||
# return self.success()
|
||||
return self.success()
|
||||
elif quart.request.method == 'DELETE':
|
||||
await self.ap.model_service.delete_llm_model(model_uuid)
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ export default function LLMForm({
|
||||
}: {
|
||||
editMode: boolean;
|
||||
initLLMId?: string;
|
||||
onFormSubmit: (value: z.infer<typeof formSchema>) => void;
|
||||
onFormSubmit: () => void;
|
||||
onFormCancel: () => void;
|
||||
onLLMDeleted: () => void;
|
||||
}) {
|
||||
@@ -222,20 +222,7 @@ export default function LLMForm({
|
||||
}
|
||||
|
||||
function handleFormSubmit(value: z.infer<typeof formSchema>) {
|
||||
if (editMode) {
|
||||
// 暂不支持更改模型
|
||||
// onSaveEdit(value)
|
||||
} else {
|
||||
onCreateLLM(value);
|
||||
}
|
||||
form.reset();
|
||||
}
|
||||
|
||||
function onCreateLLM(value: z.infer<typeof formSchema>) {
|
||||
console.log('create llm', value);
|
||||
// 转换extra_args为对象格式
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const extraArgsObj: Record<string, any> = {};
|
||||
const extraArgsObj: Record<string, string | number | boolean> = {};
|
||||
value.extra_args?.forEach((arg) => {
|
||||
if (arg.type === 'number') {
|
||||
extraArgsObj[arg.key] = Number(arg.value);
|
||||
@@ -246,8 +233,8 @@ export default function LLMForm({
|
||||
}
|
||||
});
|
||||
|
||||
const requestParam: LLMModel = {
|
||||
uuid: UUID.generate(),
|
||||
const llmModel: LLMModel = {
|
||||
uuid: editMode ? initLLMId || '' : UUID.generate(),
|
||||
name: value.name,
|
||||
description: '',
|
||||
requester: value.model_provider,
|
||||
@@ -259,15 +246,36 @@ export default function LLMForm({
|
||||
api_keys: [value.api_key],
|
||||
abilities: value.abilities,
|
||||
};
|
||||
httpClient
|
||||
.createProviderLLMModel(requestParam)
|
||||
.then(() => {
|
||||
onFormSubmit(value);
|
||||
toast.success('创建成功');
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error('创建失败:' + err.message);
|
||||
|
||||
if (editMode) {
|
||||
onSaveEdit(llmModel).then(() => {
|
||||
form.reset();
|
||||
});
|
||||
} else {
|
||||
onCreateLLM(llmModel).then(() => {
|
||||
form.reset();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function onCreateLLM(llmModel: LLMModel) {
|
||||
try {
|
||||
await httpClient.createProviderLLMModel(llmModel);
|
||||
onFormSubmit();
|
||||
toast.success('创建成功');
|
||||
} catch (err) {
|
||||
toast.error('创建失败:' + (err as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
async function onSaveEdit(llmModel: LLMModel) {
|
||||
try {
|
||||
await httpClient.updateProviderLLMModel(initLLMId || '', llmModel);
|
||||
onFormSubmit();
|
||||
toast.success('保存成功');
|
||||
} catch (err) {
|
||||
toast.error('保存失败:' + (err as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteModel() {
|
||||
@@ -524,7 +532,6 @@ export default function LLMForm({
|
||||
</FormItem>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
{!editMode && <Button type="submit">提交</Button>}
|
||||
{editMode && (
|
||||
<Button
|
||||
type="button"
|
||||
@@ -534,6 +541,9 @@ export default function LLMForm({
|
||||
删除
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<Button type="submit">{editMode ? '保存' : '提交'}</Button>
|
||||
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
|
||||
@@ -256,6 +256,13 @@ class HttpClient {
|
||||
return this.delete(`/api/v1/provider/models/llm/${uuid}`);
|
||||
}
|
||||
|
||||
public updateProviderLLMModel(
|
||||
uuid: string,
|
||||
model: LLMModel,
|
||||
): Promise<object> {
|
||||
return this.put(`/api/v1/provider/models/llm/${uuid}`, model);
|
||||
}
|
||||
|
||||
// ============ Pipeline API ============
|
||||
public getGeneralPipelineMetadata(): Promise<GetPipelineMetadataResponseData> {
|
||||
// as designed, this method will be deprecated, and only for developer to check the prefered config schema
|
||||
@@ -431,8 +438,8 @@ class HttpClient {
|
||||
}
|
||||
|
||||
// export const httpClient = new HttpClient("https://version-4.langbot.dev");
|
||||
// export const httpClient = new HttpClient('http://localhost:5300');
|
||||
export const httpClient = new HttpClient('/');
|
||||
export const httpClient = new HttpClient('http://localhost:5300');
|
||||
// export const httpClient = new HttpClient('/');
|
||||
|
||||
// 临时写法,未来两种Client都继承自HttpClient父类,不允许共享方法
|
||||
export const spaceClient = new HttpClient('https://space.langbot.app');
|
||||
|
||||
Reference in New Issue
Block a user