Desktop client reads llm configuration from the config/config.toml file
This commit is contained in:
parent
7e42e4ccd2
commit
2d507c0bcf
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"OpenManus/src/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
@ -10,6 +11,12 @@ type App struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Result string `json:"result"`
|
||||
Error string `json:"error"`
|
||||
Callbackid string `json:"callbackid"`
|
||||
}
|
||||
|
||||
// NewApp creates a new App application struct
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
@ -25,3 +32,11 @@ func (a *App) startup(ctx context.Context) {
|
||||
func (a *App) Greet(name string) string {
|
||||
return fmt.Sprintf("Hello %s, It's show time!", name)
|
||||
}
|
||||
|
||||
// ReadAll reads file content
|
||||
func (a *App) ReadAll(filePath string) string {
|
||||
// 读取文件内容,得到一个含文件内容和callbackid的json字符串
|
||||
data := string(utils.ReadAll(filePath))
|
||||
utils.Log("ReadAll data: ", data)
|
||||
return data
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import utils from '@/assets/js/utils'
|
||||
import { ReadAll } from '@/../wailsjs/go/main/App.js'
|
||||
|
||||
// 临时缓存文件信息
|
||||
function cache(fileObj, $event) {
|
||||
@ -177,8 +178,11 @@ function fileIds(fileList) {
|
||||
return fileList.map(comp => comp.fileId).join(',')
|
||||
}
|
||||
|
||||
export default {
|
||||
function readAll(filePath) {
|
||||
return ReadAll(filePath)
|
||||
}
|
||||
|
||||
export default {
|
||||
// onChange时缓存
|
||||
cache,
|
||||
// 上传文件
|
||||
@ -196,6 +200,7 @@ export default {
|
||||
// 文件Java对象与js对象转换
|
||||
trans,
|
||||
// 从Comps中收集fileId
|
||||
fileIds
|
||||
|
||||
fileIds,
|
||||
// 读取文件
|
||||
readAll
|
||||
}
|
@ -494,6 +494,13 @@ function debounce(func, delay) {
|
||||
}
|
||||
}
|
||||
|
||||
function stringToLines(str) {
|
||||
if (str == undefined || str == null) {
|
||||
return []
|
||||
}
|
||||
return str.split('\n')
|
||||
}
|
||||
|
||||
export default {
|
||||
/**
|
||||
* http请求 GET请求
|
||||
@ -636,4 +643,6 @@ export default {
|
||||
|
||||
debounce,
|
||||
|
||||
stringToLines,
|
||||
|
||||
}
|
@ -3,30 +3,213 @@
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="title fxsb">
|
||||
<div>基本信息</div>
|
||||
<div>LLM Config</div>
|
||||
<div>
|
||||
<el-link type="primary" class="no-select plr-6" @click="clearCache()">清理缓存</el-link>
|
||||
<el-link type="primary" class="no-select plr-6" @click="toEdit('base')" v-show="baseShow">
|
||||
{{ t('edit') }}
|
||||
</el-link>
|
||||
<el-link type="primary" class="no-select plr-6" @click="toShow('base')" v-show="baseEdit">
|
||||
{{ t('cancel') }}
|
||||
</el-link>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 展示模块-无数据 -->
|
||||
<div class="no-data" v-show="baseNoData">{{ t('noData') }}</div>
|
||||
|
||||
<!-- 展示模块-有数据 -->
|
||||
<div class="card-row-wrap" v-show="baseShow">
|
||||
<div class="card-row-item">
|
||||
<el-text>model:</el-text>
|
||||
<el-text>{{ llmConfig.model }}</el-text>
|
||||
</div>
|
||||
|
||||
<div class="card-row-item">
|
||||
<el-text>base_url:</el-text>
|
||||
<el-text tag="p">{{ llmConfig.base_url }}</el-text>
|
||||
</div>
|
||||
|
||||
<div class="card-row-item">
|
||||
<el-text>api_key:</el-text>
|
||||
<el-text>{{ llmConfig.api_key }}</el-text>
|
||||
</div>
|
||||
|
||||
<div class="card-row-item">
|
||||
<el-text>max_tokens:</el-text>
|
||||
<el-text>{{ llmConfig.max_tokens }}</el-text>
|
||||
</div>
|
||||
|
||||
<div class="card-row-item">
|
||||
<el-text>temperature:</el-text>
|
||||
<el-text>{{ llmConfig.temperature }}</el-text>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 编辑模块 -->
|
||||
<el-form ref="ruleFormRef" :model="llmConfigUpd" status-icon :rules="rules" v-show="baseEdit">
|
||||
<div class="card-row-wrap">
|
||||
<div class="card-row-item">
|
||||
<el-text>model:</el-text>
|
||||
<el-form-item prop="model">
|
||||
<el-input v-model="llmConfigUpd.model" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<div class="card-row-item">
|
||||
<el-text>base_url:</el-text>
|
||||
<el-form-item prop="base_url">
|
||||
<el-input v-model="llmConfigUpd.base_url" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<div class="card-row-item">
|
||||
<el-text>api_key:</el-text>
|
||||
<el-form-item prop="api_key">
|
||||
<el-input v-model="llmConfigUpd.api_key" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<div class="card-row-item">
|
||||
<el-text>max_tokens:</el-text>
|
||||
<el-form-item prop="max_tokens">
|
||||
<el-input v-model="llmConfigUpd.max_tokens" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<div class="card-row-item">
|
||||
<el-text>temperature:</el-text>
|
||||
<el-form-item prop="temperature">
|
||||
<el-input v-model="llmConfigUpd.temperature" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<div class="card-row-aline fxc" v-show="baseEdit">
|
||||
<el-button class="mlr-10" @click="toShow('base')">{{ t('cancel') }}</el-button>
|
||||
<el-button type="primary" class="mlr-10" @click="submitForm">{{ t('submit') }}</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, inject, onMounted } from 'vue'
|
||||
import { ref, reactive, inject, onMounted, computed } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import {useConfig} from '@/store/config'
|
||||
import { useConfig } from '@/store/config'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const utils = inject('utils')
|
||||
const files = inject('files')
|
||||
const verify = inject('verify')
|
||||
const router = useRouter()
|
||||
const config = useConfig()
|
||||
const { t } = useI18n()
|
||||
|
||||
// 视图模式
|
||||
const viewModel = reactive({
|
||||
base: 'show',
|
||||
})
|
||||
|
||||
function toShow(model) {
|
||||
console.log("toShow:" + model)
|
||||
viewModel[model] = 'show'
|
||||
}
|
||||
|
||||
function toEdit(model) {
|
||||
console.log("toEdit:" + model)
|
||||
viewModel[model] = 'edit'
|
||||
}
|
||||
|
||||
const baseShow = computed(() => {
|
||||
return viewModel.base == 'show' || viewModel.base == 'showMore'
|
||||
})
|
||||
|
||||
const baseEdit = computed(() => {
|
||||
return viewModel.base == 'edit'
|
||||
})
|
||||
|
||||
const baseNoData = computed(() => {
|
||||
return baseShow && llmConfig.model == null
|
||||
})
|
||||
|
||||
const llmConfig = reactive({
|
||||
model: null,
|
||||
base_url: null,
|
||||
api_key: null,
|
||||
max_tokens: null,
|
||||
temperature: null,
|
||||
})
|
||||
|
||||
const llmConfigUpd = reactive({
|
||||
model: null,
|
||||
base_url: null,
|
||||
api_key: null,
|
||||
max_tokens: null,
|
||||
temperature: null,
|
||||
})
|
||||
|
||||
function clearCache() {
|
||||
config.$reset()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// 读取配置文件config/config.toml
|
||||
files.readAll("@/../../config/config.toml").then((fileContent) => {
|
||||
console.log("config/config.toml: ", fileContent)
|
||||
const lines = utils.stringToLines(fileContent)
|
||||
|
||||
// 读取[llm]
|
||||
const llmStart = lines.findIndex((line) => {
|
||||
return line.includes("[llm]")
|
||||
})
|
||||
for (let i = llmStart + 1; i < lines.length; i++) {
|
||||
console.log("line: ", lines[i])
|
||||
// 判定是否到了下个配置模块
|
||||
if (lines[i].startsWith("[")) {
|
||||
break
|
||||
}
|
||||
// 读取配置
|
||||
const line = lines[i]
|
||||
const lineArr = line.split("=")
|
||||
if (lineArr.length != 2) {
|
||||
continue
|
||||
}
|
||||
const key = lineArr[0].trim()
|
||||
const value = lineArr[1].trim()
|
||||
llmConfig[key] = value
|
||||
}
|
||||
console.log("llmConfig read from file: ", llmConfig)
|
||||
utils.copyProps(llmConfig, llmConfigUpd)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
const submitForm = async () => {
|
||||
try {
|
||||
await ruleFormRef.value.validate();
|
||||
if (!utils.hasDfProps(designSchemeDtl, designSchemeUpd)) {
|
||||
ElMessage.success('未发生更改!');
|
||||
toShow('base')
|
||||
return
|
||||
}
|
||||
ElMessage.success('验证通过,提交表单');
|
||||
// update()
|
||||
} catch (error) {
|
||||
ElMessage.error('参数验证失败');
|
||||
}
|
||||
}
|
||||
|
||||
const rules = reactive({
|
||||
model: [{ validator: verify.validator('notBlank'), trigger: 'blur' }],
|
||||
base_url: [{ validator: verify.validator('notBlank'), trigger: 'blur' }],
|
||||
api_key: [{ validator: verify.validator('notBlank'), trigger: 'blur' }],
|
||||
max_tokens: [{ validator: verify.validator('notBlank'), trigger: 'blur' }],
|
||||
temperature: [{ validator: verify.validator('notBlank'), trigger: 'blur' }],
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
|
2
desktop/frontend/wailsjs/go/main/App.d.ts
vendored
2
desktop/frontend/wailsjs/go/main/App.d.ts
vendored
@ -2,3 +2,5 @@
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export function Greet(arg1:string):Promise<string>;
|
||||
|
||||
export function ReadAll(arg1:string):Promise<string>;
|
||||
|
@ -5,3 +5,7 @@
|
||||
export function Greet(arg1) {
|
||||
return window['go']['main']['App']['Greet'](arg1);
|
||||
}
|
||||
|
||||
export function ReadAll(arg1) {
|
||||
return window['go']['main']['App']['ReadAll'](arg1);
|
||||
}
|
||||
|
29
desktop/src/utils/file.go
Normal file
29
desktop/src/utils/file.go
Normal file
@ -0,0 +1,29 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// 打开文件
|
||||
func ReadAll(filePath string) []byte {
|
||||
if IsBlank(filePath) {
|
||||
fmt.Println("File path is nil")
|
||||
return nil
|
||||
}
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
fmt.Println("Error opening file:", err)
|
||||
return nil
|
||||
}
|
||||
// 确保文件最后被关闭
|
||||
defer file.Close()
|
||||
|
||||
data, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
fmt.Println("Read file error:", err)
|
||||
return nil
|
||||
}
|
||||
return data
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package utils
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
@ -1,10 +1,11 @@
|
||||
package main
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// AnyToStr 任意类型数据转string
|
||||
@ -45,3 +46,19 @@ func AnyToStr(i interface{}) (string, error) {
|
||||
return "", fmt.Errorf("unable to cast %#v of type %T to string", i, i)
|
||||
}
|
||||
}
|
||||
|
||||
func IsEmpty(s string) bool {
|
||||
return len(s) == 0
|
||||
}
|
||||
|
||||
func IsNotEmpty(s string) bool {
|
||||
return len(s) > 0
|
||||
}
|
||||
|
||||
func IsBlank(s string) bool {
|
||||
return len(s) == 0 || strings.TrimSpace(s) == ""
|
||||
}
|
||||
|
||||
func IsNotBlank(s string) bool {
|
||||
return len(s) > 0 && strings.TrimSpace(s) != ""
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user