修复无法进行离线 OCR 的问题

This commit is contained in:
锦恢 2025-05-02 21:02:33 +08:00
parent e206b502b5
commit b7015d7532
3 changed files with 30 additions and 55 deletions

View File

@ -6,6 +6,8 @@
- 插件模式下左侧管理面板中的「MCP连接工作区」视图可以进行增删改查了
- 新增「安装的 MCP 服务器」,用于安装全局范围的 mcp server
- 增加引导页面
- 修复无法进行离线 OCR 的问题
- 修复全局安装的 mcp 服务器 name 更新的问题
## [main] 0.0.5
- 支持对已经打开过的文件项目进行管理

View File

@ -1,41 +1,18 @@
import { ToolCallContent, ToolItem } from "@/hook/type";
import { Ref, ref } from "vue";
import { ToolItem } from "@/hook/type";
import { ref } from "vue";
import type { OpenAI } from 'openai';
type ChatCompletionChunk = OpenAI.Chat.Completions.ChatCompletionChunk;
export enum MessageState {
ServerError = 'server internal error',
ReceiveChunkError = 'receive chunk error',
Timeout = 'timeout',
MaxEpochs = 'max epochs',
Unknown = 'unknown error',
Abort = 'abort',
ToolCall = 'tool call failed',
None = 'none',
Success = 'success',
ParseJsonError = 'parse json error'
}
export interface IExtraInfo {
created: number,
state: MessageState,
serverName: string,
usage?: ChatCompletionChunk['usage'];
[key: string]: any;
[key: string]: any
}
export interface ToolMessage {
role: 'tool';
content: ToolCallContent[];
tool_call_id?: string
name?: string // 工具名称,当 role 为 tool
tool_calls?: ToolCall[],
extraInfo: IExtraInfo
}
export interface TextMessage {
role: 'user' | 'assistant' | 'system';
export interface ChatMessage {
role: 'user' | 'assistant' | 'system' | 'tool';
content: string;
tool_call_id?: string
name?: string // 工具名称,当 role 为 tool
@ -43,8 +20,6 @@ export interface TextMessage {
extraInfo: IExtraInfo
}
export type ChatMessage = ToolMessage | TextMessage;
// 新增状态和工具数据
interface EnableToolItem {
name: string;
@ -78,15 +53,6 @@ export interface ToolCall {
export const allTools = ref<ToolItem[]>([]);
export interface IRenderMessage {
role: 'user' | 'assistant/content' | 'assistant/tool_calls' | 'tool';
content: string;
toolResult?: ToolCallContent[];
tool_calls?: ToolCall[];
showJson?: Ref<boolean>;
extraInfo: IExtraInfo;
}
export function getToolSchema(enableTools: EnableToolItem[]) {
const toolsSchema = [];
for (let i = 0; i < enableTools.length; i++) {
@ -105,4 +71,3 @@ export function getToolSchema(enableTools: EnableToolItem[]) {
}
return toolsSchema;
}

View File

@ -8,8 +8,13 @@ export class HookController {
@RegisterCommand('openmcp.hook.test-ocr')
async testOcr(context: vscode.ExtensionContext) {
try {
const testImage = path.join(context.extensionPath, 'icons/openmcp.resource.png');
console.log('test ocr begin');
console.log('cachePath', context.extensionPath);
const { data: { text } } = await Tesseract.recognize(
testImage,
'eng+chi_sim',
@ -22,7 +27,10 @@ export class HookController {
}
);
vscode.window.showInformationMessage('ocr result: ' + text);
console.log('ocr result: ' + text);
} catch (error) {
vscode.window.showErrorMessage(error as string);
}
}
}