-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: System application generate prompt #4034
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
feat: System application generate prompt #4034
Conversation
|
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. DetailsInstructions 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. |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| } | ||
| // 重新生成点击 |
There was a problem hiding this comment.
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:
-
Computed Property:
- Added an
apiTypecomputed property that checks the current route path.
- Added an
-
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.
- Combined the generation logic into a single method (
-
Parameter Passing:
- Explicitly mentioned the missing parameters like
workspaceId,applicationID.
- Explicitly mentioned the missing parameters like
-
Event Emitters:
- Added type annotations for the emitted event emitter using
<'replace'>.
- Added type annotations for the emitted event emitter using
-
Routing Check:
- The routing check is now part of determining the appropriate API to invoke.
-
Error Handling:
- The
getReadfunction remains empty; you should implement how error handling should be managed after reading chunks.
- The
Make sure to replace placeholders like /* your workspace ID */ with real logic to determine the correct IDs for requests.
| putXpackAccessToken | ||
| putXpackAccessToken, | ||
| generate_prompt | ||
| } |
There was a problem hiding this comment.
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:
-
Type Declarations: Adding type declarations to the parameters can improve maintainability and clarity.
-
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
PostResponseis imported from'@/types'.
These changes enhance the overall quality and organization of the code while maintaining its functionality.
feat: System application generate prompt