提交 c65d8936 编写于 作者: D DebugIsFalse

feature: 添加支持search_web的action

上级 edc023f4
<template>
<ULink v-for="(item, index) in limitSource" :to="item.link" :title="item.link" target="_blank">
<ULink v-for="(item, index) in limitSource" :to="item.url" :title="item.url" target="_blank">
<UCard :ui="cardUI">
<div class="flex flex-col gap-1">
<div class="items-center flex gap-1">
<UIcon name="i-simple-icons-github" />
<div class="truncate flex flex-grow">{{ item.repo }}</div>
<UIcon v-if="getIconPath(item.url) === 'github'" name="i-simple-icons-github" />
<UAvatar v-else :src="getIconPath(item.url)" />
<div class="truncate flex flex-grow">{{ item.title }}</div>
<div class="text-gray-200">{{ index + 1 }}</div>
</div>
<div class="text-blue-500 truncate">{{ item.label }}</div>
<div class="text-blue-500 truncate">{{ item.description }}</div>
</div>
</UCard>
</ULink>
......@@ -40,7 +41,12 @@ const limitSource = computed(() => {
else if (showAllSource.value) return props.source
else return props.source.slice(0, 5)
})
function getIconPath (url) {
if (!url || !url.startsWith('http')) return ''
var uri = new URL(url)
if (uri.origin.endsWith('github.com')) return 'github'
return `https://www.google.com/s2/favicons?sz=128&domain=${url}`
}
const handleToggleShowAll = () => {
showAllSource.value = !showAllSource.value
}
......
......@@ -97,6 +97,8 @@ function initSearchRecords (records) {
historyItem.description = child.output
} else if (childAction === 'search_file') {
historyItem.source = handleFormatSource(child.output)
} else if (childAction === 'search_web') {
historyItem.source = handleFormatWebSource(child.output)
}
})
return historyItem
......@@ -182,12 +184,19 @@ function handleFormatSource (source) {
return source.split('\n').map((item) => {
const isLink = item.indexOf('http') === 0
return {
repo: state.repo,
link: isLink ? item : `${gitUrl}/blob/${state.branch}/${item}`,
label: item
title: state.repo,
url: isLink ? item : `${gitUrl}/blob/${state.branch}/${item}`,
description: ''
}
})
}
function handleFormatWebSource (source) {
let sources = []
try {
sources = JSON.parse(source)
} catch (error) {}
return sources
}
function handleSetNoPermission () {
askingData.value = {}
useRequestError(403)
......@@ -226,6 +235,13 @@ const handleFormFetchData = (fetchData) => {
source = handleFormatSource(source)
Object.assign(askingData.value, { desLoading: true, source, searchLoading: true, desLoading: false })
resetAutoBottom()
return
}
if (meta.action === 'search_web') {
let source = choices[0].message.content
source = handleFormatWebSource(source)
Object.assign(askingData.value, { desLoading: true, source, searchLoading: true, desLoading: false })
resetAutoBottom()
}
}
const handleCreateAiTitle = () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册