新增AI操作分类,支持AI对话(预设翻译、总结、shell生成)

This commit is contained in:
fofolee
2025-02-17 17:44:01 +08:00
parent 89a2e07b13
commit d7508c36a7
9 changed files with 502 additions and 5 deletions

View File

@@ -2512,4 +2512,100 @@ interface quickcomposerApi {
*/
waitForElement(selector: string, timeout?: number): Promise<void>;
};
/**
* AI 相关功能
*/
ai: {
/**
* 与 AI 进行对话
* @param apiConfig API配置
* @param content 对话内容
* @example
* // OpenAI 示例
* const response = await quickcomposer.ai.chat(
* {
* modelType: "openai",
* apiUrl: "https://api.openai.com/v1/chat/completions",
* apiToken: "your-api-token",
* model: "gpt-3.5-turbo"
* },
* {
* prompt: "你好",
* presetPrompt: "" // 使用预设提示词translate/shell/summarize
* }
* );
*
* // Ollama 示例
* const response = await quickcomposer.ai.chat(
* {
* modelType: "ollama",
* apiUrl: "http://localhost:11434/api/generate",
* model: "qwen2.5:32b"
* },
* {
* prompt: "查找进程名为chrome的进程并关闭",
* presetPrompt: "shell"
* }
* );
*/
chat(
apiConfig: {
/** 模型类型openai/ollama */
modelType: "openai" | "ollama";
/** API地址 */
apiUrl: string;
/** API令牌仅 OpenAI 需要) */
apiToken?: string;
/** 模型名称 */
model: string;
},
content: {
/** 提示词 */
prompt: string;
/** 预设提示词类型 */
presetPrompt?: "" | "translate" | "shell" | "summarize";
}
): Promise<{
/** 是否成功 */
success: boolean;
/** AI 响应内容 */
result?: string;
/** 错误信息 */
error?: string;
}>;
/**
* 获取 API 支持的模型列表
* @param apiConfig API配置
* @example
* // OpenAI 示例
* const models = await quickcomposer.ai.getModels({
* modelType: "openai",
* apiUrl: "https://api.openai.com/v1/models",
* apiToken: "your-api-token"
* });
*
* // Ollama 示例
* const models = await quickcomposer.ai.getModels({
* modelType: "ollama",
* apiUrl: "http://localhost:11434"
* });
*/
getModels(apiConfig: {
/** 模型类型openai/ollama */
modelType: "openai" | "ollama";
/** API地址 */
apiUrl: string;
/** API令牌仅 OpenAI 需要) */
apiToken?: string;
}): Promise<{
/** 是否成功 */
success: boolean;
/** 模型名称列表 */
result?: string[];
/** 错误信息 */
error?: string;
}>;
};
}