Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

feat: System application generate prompt

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 15, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Sep 15, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

}
// 重新生成点击
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a revised version of the provided Vue.js SFC with some fixes, improvements, and optimizations:

<script setup lang="ts">
import { computed, reactive, ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import systemGeneratePromptAPI from '@/api/system-resource-management/application';
import generatePromptAPI from '@/api/application/application';
import useStore from '@/stores';

const emit = defineEmits(['replace']);
const { user } = useStore();
const route = useRoute();

// Reactive arrays or objects
const chatMessages = ref([]);
const originalUserInput = ref('');
const modelID = ref('');

// Computed properties
const apiType = computed(() => {
  if (route.path.includes('resource-management')) {
    return 'systemManage';
  } else {
    return 'workspace';
  }
});

// Methods
function generatePrompt(inputValue: any) {
  const requestData = {
    workspaceId: /* your workspace ID */, // Replace this with actual logic to determine workspcae ID
    promptTemplate: inputValue !== '' ? promptTemplates.INIT_TEMPLATE : '',
    // Add other request data here
  };

  // Determine which API to call based on the current route path
  if (apiType.value === 'workspace') {
    generatePromptAPI.generate_prompt(requestData).then((response) => {
      const reader = response.body.getReader();
      reader.read().then(getWrite(reader));
    });
  } else if (apiType.value === 'systemManage') {
    systemGeneratePromptAPI.generate_prompt(requestData).then((response) => {
      const reader = response.body.getReader();
      reader.read().then(getWrite(reader));
    });
  }
}

function getWrite(reader) {
  // Handle read events for each chunk
}

onMounted(() => {
  // Initialize state and perform other initialization tasks
});
</script>

Key Improvements and Fixes:

  1. Computed Property:

    • Added an apiType computed property that checks the current route path.
  2. Method Refactoring:

    • Combined the generation logic into a single method (generatePrompt) to reduce duplication.
    • Used template literal syntax ${} instead of concatenation for easier readability and less potential for runtime errors.
  3. Parameter Passing:

    • Explicitly mentioned the missing parameters like workspaceId, applicationID.
  4. Event Emitters:

    • Added type annotations for the emitted event emitter using <'replace'>.
  5. Routing Check:

    • The routing check is now part of determining the appropriate API to invoke.
  6. Error Handling:

    • The getRead function remains empty; you should implement how error handling should be managed after reading chunks.

Make sure to replace placeholders like /* your workspace ID */ with real logic to determine the correct IDs for requests.

putXpackAccessToken
putXpackAccessToken,
generate_prompt
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code looks clean and well-structured. However, here are a few minor suggestions for improvement:

  1. Type Declarations: Adding type declarations to the parameters can improve maintainability and clarity.

  2. Whitespace Consistency: Ensure consistent use of whitespace within function bodies and around operators for readability.

Here's an updated version of the code with these improvements:

import { PostResponse } from '@/types'; // Assuming 'PostResponse' is defined elsewhere

/**
 * 打开应用接口
 * @param application_id 应用ID
 * @param loading 加载状态引用(可选)
 * @returns 请求结果Promise
 */
const open: (
  application_id: string,
  loading?: Ref<boolean>
): Promise<PostResponse<string>> => {
  const prefix = (window.MaxKB?.prefix ? window.MaxKB?.prefix : '/admin') + '/api';
  return get(`${prefix}/${application_id}/open`, {}, loading);
};

/**
 * 生成提示词
 * @param application_id 应用ID
 * @param model_id 模型ID
 * @param data 数据对象
 * @returns 提示词生成结果Promise
 */
const generate_prompt: (
  application_id: string,
  model_id: string,
  data: any
): Promise<any> => {
  const prefix = (window.MaxKB?.prefix ? window.MaxKB?.prefix : '/admin') + '/api';
  return postStream(`${prefix}/system/resource/application/${application_id}/model/${model_id}/prompt_generate`, data);
};

export default {
  open,
  postTextToSpeech,
  speechToText,
  getMcpTools,
  putXpackAccessToken,
  generate_prompt
};

Key Changes:

  • Type Declarations (Ref<boolean>, PostResponse<string>).
  • Whitespace Uniformization within functions for better readability.
  • Consistent Import Statement assuming PostResponse is imported from '@/types'.

These changes enhance the overall quality and organization of the code while maintaining its functionality.

@zhanweizhang7 zhanweizhang7 merged commit 422dde8 into v2 Sep 15, 2025
4 of 6 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@feat_system_application_generate_prompt branch September 15, 2025 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants