Skip to content

Commit d45ad3d

Browse files
committed
feat: 添加LLM信息填写对话框及相关逻辑,更新依赖版本
1 parent 872a598 commit d45ad3d

File tree

5 files changed

+75
-9
lines changed

5 files changed

+75
-9
lines changed

examples/sites/env/.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ VITE_APP_MODE='pc'
66

77
VITE_APP_BUILD_BASE_URL='/'
88
VITE_PLAYGROUND_URL=/playground.html
9+
10+
VITE_LLM_API_KEY=
11+
VITE_LLM_URL=https://api.deepseek.com/v1

examples/sites/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@docsearch/css": "^3.8.0",
2828
"@docsearch/js": "^3.8.0",
2929
"@docsearch/react": "npm:@docsearch/css",
30-
"@opentiny/next-sdk": "0.0.1-alpha.4",
30+
"@opentiny/next-sdk": "0.0.1-alpha.5",
3131
"@opentiny/tiny-robot": "0.3.0-alpha.3",
3232
"@opentiny/tiny-robot-kit": "0.3.0-alpha.3",
3333
"@opentiny/tiny-robot-svgs": "0.3.0-alpha.3",

examples/sites/src/App.vue

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,68 @@
1010
<div class="right-panel" :class="{ collapsed: !showTinyRobot }">
1111
<tiny-robot-chat />
1212
</div>
13-
<IconAi @click="showTinyRobot = !showTinyRobot" class="style-settings-icon"></IconAi>
13+
<IconAi @click="handleShowTinyRobot" class="style-settings-icon"></IconAi>
14+
<tiny-dialog-box
15+
v-model:visible="boxVisibility"
16+
:close-on-click-modal="false"
17+
title="请填写您的LLM信息, 否则无法体验智能化能力"
18+
width="30%"
19+
>
20+
<div>
21+
<tiny-form ref="formRef" :model="createData" label-width="120px">
22+
<tiny-form-item label="LLM URL" prop="llmUrl" :rules="{ required: true, messages: '必填', trigger: 'blur' }">
23+
<tiny-input v-model="createData.llmUrl"></tiny-input>
24+
</tiny-form-item>
25+
<tiny-form-item
26+
label="API Key"
27+
prop="llmApiKey"
28+
:rules="{ required: true, messages: '必填', trigger: 'blur' }"
29+
>
30+
<tiny-input v-model="createData.llmApiKey"></tiny-input>
31+
</tiny-form-item>
32+
<tiny-form-item>
33+
<tiny-button @click="submit" type="primary">保存</tiny-button>
34+
</tiny-form-item>
35+
</tiny-form>
36+
</div>
37+
</tiny-dialog-box>
1438
</div>
1539
</template>
1640

1741
<script setup lang="ts">
18-
import { onMounted, provide, ref } from 'vue'
19-
import { TinyConfigProvider, TinyModal } from '@opentiny/vue'
42+
import { onMounted, provide, ref, reactive } from 'vue'
43+
import {
44+
TinyConfigProvider,
45+
TinyModal,
46+
TinyDialogBox,
47+
TinyForm,
48+
TinyFormItem,
49+
TinyInput,
50+
TinyButton
51+
} from '@opentiny/vue'
2052
import useTheme from './tools/useTheme'
2153
import TinyRobotChat from './components/tiny-robot-chat.vue'
2254
import { IconAi } from '@opentiny/tiny-robot-svgs'
2355
import { showTinyRobot } from './composable/utils'
2456
import { createServer, createInMemoryTransport } from '@opentiny/next-sdk'
25-
2657
import { createGlobalMcpTool } from './tools/globalMcpTool'
58+
import { $local, isEnvLLMDefined, isLocalLLMDefined } from './composable/utils'
59+
60+
const boxVisibility = ref(false)
61+
const formRef = ref()
62+
const createData = reactive({
63+
llmUrl: $local.llmUrl || import.meta.env.VITE_LLM_URL,
64+
llmApiKey: $local.llmApiKey || import.meta.env.VITE_LLM_API_KEY
65+
})
66+
67+
const submit = () => {
68+
formRef.value.validate().then(() => {
69+
$local.llmUrl = createData.llmUrl
70+
$local.llmApiKey = createData.llmApiKey
71+
boxVisibility.value = false
72+
window.location.reload()
73+
})
74+
}
2775
2876
const previewUrl = ref(import.meta.env.VITE_PLAYGROUND_URL)
2977
const modalSHow = ref(false)
@@ -65,6 +113,14 @@ provide('showPreview', (url) => {
65113
previewUrl.value = url
66114
modalSHow.value = true
67115
})
116+
117+
const handleShowTinyRobot = () => {
118+
if (!isEnvLLMDefined && !isLocalLLMDefined) {
119+
boxVisibility.value = true
120+
} else {
121+
showTinyRobot.value = !showTinyRobot.value
122+
}
123+
}
68124
</script>
69125

70126
<style scoped lang="less">

examples/sites/src/composable/agentModelProvider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { StreamHandler } from '@opentiny/tiny-robot-kit'
55
import { BaseModelProvider } from '@opentiny/tiny-robot-kit'
66
import type { AIModelConfig } from '@opentiny/tiny-robot-kit'
77
import { reactive } from 'vue'
8+
import { $local, isEnvLLMDefined } from './utils'
89

910
// 创建nextClient
1011
const nextClient = createClient(
@@ -57,8 +58,8 @@ const onToolCallChain = (extra: any, handler: StreamHandler) => {
5758

5859
const mcpHost = createMCPHost({
5960
llmOption: {
60-
url: 'https://api.deepseek.com/v1',
61-
apiKey: 'xxx',
61+
url: isEnvLLMDefined ? import.meta.env.VITE_LLM_URL : $local.llmUrl || '',
62+
apiKey: isEnvLLMDefined ? import.meta.env.VITE_LLM_API_KEY : $local.llmApiKey || '',
6263
dangerouslyAllowBrowser: true,
6364
model: 'deepseek-chat',
6465
llm: 'deepseek'

examples/sites/src/composable/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
import { ref } from 'vue'
77

8-
export { $local, $session } from './storage'
8+
import { $local, $session } from './storage'
99

10-
export const showTinyRobot = ref(true)
10+
export { $local, $session }
11+
12+
export const showTinyRobot = ref(false)
13+
14+
// 如果环境变量和本地变量都未定义,则提示用户填写
15+
export const isEnvLLMDefined = Boolean(import.meta.env.VITE_LLM_API_KEY && import.meta.env.VITE_LLM_URL)
16+
export const isLocalLLMDefined = Boolean($local.llmUrl && $local.llmApiKey)

0 commit comments

Comments
 (0)