Skip to content

feat(core): support config VQA related model #1002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/core/src/ai-model/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {

import type { PlanningLocateParam } from '@/types';
import { NodeType } from '@midscene/shared/constants';
import { vlLocateMode } from '@midscene/shared/env';
import { type IModelPreferences, vlLocateMode } from '@midscene/shared/env';
import { treeToList } from '@midscene/shared/extractor';
import { compositeElementInfoImg } from '@midscene/shared/img';
import { getDebug } from '@midscene/shared/logger';
Expand All @@ -45,8 +45,13 @@ export enum AIActionType {
export async function callAiFn<T>(
msgs: AIArgs,
AIActionTypeValue: AIActionType,
modelPreferences?: IModelPreferences,
): Promise<{ content: T; usage?: AIUsageInfo }> {
const jsonObject = await callToGetJSONObject<T>(msgs, AIActionTypeValue);
const jsonObject = await callToGetJSONObject<T>(
msgs,
AIActionTypeValue,
modelPreferences,
);

return {
content: jsonObject.content,
Expand Down
21 changes: 15 additions & 6 deletions packages/core/src/ai-model/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import type {
UIContext,
} from '@/types';
import {
MIDSCENE_USE_QWEN_VL,
MIDSCENE_USE_VLM_UI_TARS,
getAIConfigInBoolean,
type IModelPreferences,
getIsUseQwenVl,
getIsUseVlmUiTars,
vlLocateMode,
} from '@midscene/shared/env';

import {
cropByRect,
paddingToMatchBlockByBase64,
Expand Down Expand Up @@ -364,7 +365,7 @@ export async function AiLocateSection(options: {
imageBase64 = await cropByRect(
screenshotBase64,
sectionRect,
getAIConfigInBoolean(MIDSCENE_USE_QWEN_VL),
getIsUseQwenVl(),
);
}

Expand All @@ -385,8 +386,15 @@ export async function AiExtractElementInfo<
multimodalPrompt?: TMultimodalPrompt;
context: UIContext<ElementType>;
extractOption?: InsightExtractOption;
modelPreferences?: IModelPreferences;
}) {
const { dataQuery, context, extractOption, multimodalPrompt } = options;
const {
dataQuery,
context,
extractOption,
multimodalPrompt,
modelPreferences,
} = options;
const systemPrompt = systemPromptToExtract();

const { screenshotBase64 } = context;
Expand Down Expand Up @@ -445,6 +453,7 @@ export async function AiExtractElementInfo<
const result = await callAiFn<AIDataExtractionResponse<T>>(
msgs,
AIActionType.EXTRACT_DATA,
modelPreferences,
);
return {
parseResult: result.content,
Expand All @@ -463,7 +472,7 @@ export async function AiAssert<
const { screenshotBase64 } = context;

const systemPrompt = systemPromptToAssert({
isUITars: getAIConfigInBoolean(MIDSCENE_USE_VLM_UI_TARS),
isUITars: getIsUseVlmUiTars(),
});

const assertionText = extraTextFromUserPrompt(assertion);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/ai-model/prompt/playwright-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ ${PLAYWRIGHT_EXAMPLE_CODE}`;

if (options.stream && options.onChunk) {
// Use streaming
return await callAi(prompt, AIActionType.EXTRACT_DATA, undefined, {
return await callAi(prompt, AIActionType.EXTRACT_DATA, {
stream: true,
onChunk: options.onChunk,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/ai-model/prompt/yaml-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ Respond with YAML only, no explanations.`,

if (options.stream && options.onChunk) {
// Use streaming
return await callAi(prompt, AIActionType.EXTRACT_DATA, undefined, {
return await callAi(prompt, AIActionType.EXTRACT_DATA, {
stream: true,
onChunk: options.onChunk,
});
Expand Down
Loading
Loading