Skip to content
Merged
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
3 changes: 3 additions & 0 deletions apps/chat/serializers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ def generate_prompt(self, instance: dict):

message = messages[-1]['content']
q = prompt.replace("{userInput}", message)
q = q.replace("{application_name}",application.name)
q = q.replace("{detail}",application.desc)

messages[-1]['content'] = q

model_exist = QuerySet(Model).filter(
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 Python code is incomplete and does not include the rest of the generate_prompt function definition. I'll address the partial code to highlight any immediate issues.

Issue 1: The function is missing its closing parenthesis after messages[-1]. This can cause a syntax error.

# Corrected line
messages[-1].append({'content': q})

Optimization Suggestion: If you want to use an immutable list when appending, you might consider converting it back to a tuple:

# Recommended change
messages.append(Message(content=q))

However, if you prefer leaving the type as list, the current implementation works correctly.

Overall Feedback: Ensure that all necessary imports (e.g., for querying models) are included at the beginning of your file. Also verify that application.name and application.desc are defined and accessible within context since they are used in replacing placeholders with actual values.

Expand Down
2 changes: 1 addition & 1 deletion apps/chat/template/generate_prompt_system
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
## 限制:
1. **严格限制回答范围**:仅回答与角色设定相关的问题。
- 如果用户提问与角色无关,必须使用以下固定格式回复:
“对不起,我只能回答与角色设定相关的问题,您的问题不在服务范围内。”
“对不起,我只能回答与[角色设定]相关的问题,您的问题不在服务范围内。”
- 不得提供任何与角色设定无关的回答。
2. 描述角色在互动过程中需要遵循的限制条件2
3. 描述角色在互动过程中需要遵循的限制条件3
Expand Down
23 changes: 18 additions & 5 deletions ui/src/views/application/component/GeneratePromptDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{{ $t('views.application.generateDialog.title') }}
</p>
</el-scrollbar>
<div v-if="answer && !loading && !isStreaming && !showContinueButton">
<div v-if="answer && !loading && !isStreaming && !showContinueButton" class="mt-8">
<el-button type="primary" @click="() => emit('replace', answer)">
{{ $t('views.application.generateDialog.replace') }}
</el-button>
Expand Down Expand Up @@ -126,14 +126,22 @@ const promptTemplates = {
INIT_TEMPLATE: `
请根据用户描述生成一个完整的AI角色人设模板:

应用名称:{application_name}
应用描述:{detail}
用户需求:{userInput}

重要说明:
1. 角色设定必须服务于"{application_name}"应用的核心功能
2. 允许用户对角色设定的具体内容进行调整和优化
3. 如果用户要求修改某个技能或部分,在保持应用主题的前提下进行相应调整

请按以下格式生成:

必须严格遵循以下规则:
1. **严格禁止输出解释、前言、额外说明**,只输出最终结果。
2. **严格使用以下格式**,不能缺少标题、不能多出其他段落。
3. **如果用户需求不明确,就忽略用户需求**。
3. **如果用户要求修改角色设定的某个部分,在保持应用核心功能的前提下进行调整**。
4. **如果用户需求与角色设定生成完全无关(如闲聊、其他话题),则忽略用户需求,基于应用信息生成标准角色设定**。

# 角色:
角色概述和主要职责的一句话描述
Expand Down Expand Up @@ -174,7 +182,7 @@ const promptTemplates = {
## 限制:
1. **严格限制回答范围**:仅回答与角色设定相关的问题。
- 如果用户提问与角色无关,必须使用以下固定格式回复:
“对不起,我只能回答与角色设定相关的问题,您的问题不在服务范围内。”
“对不起,我只能回答与[角色设定]相关的问题,您的问题不在服务范围内。”
- 不得提供任何与角色设定无关的回答。
2. 描述角色在互动过程中需要遵循的限制条件2
3. 描述角色在互动过程中需要遵循的限制条件3
Expand All @@ -200,7 +208,7 @@ const startStreamingOutput = () => {
isPaused.value = false

streamTimer = setInterval(() => {
if (isApiComplete.value && !isPaused.value) {
if (isApiComplete.value && !isPaused.value) {
// 更新显示内容
const currentAnswer = chatMessages.value[chatMessages.value.length - 1]
if (currentAnswer && currentAnswer.role === 'ai') {
Expand Down Expand Up @@ -393,10 +401,13 @@ const handleSubmit = (event?: any) => {
if (!event?.ctrlKey && !event?.shiftKey && !event?.altKey && !event?.metaKey) {
// 如果没有按下组合键,则会阻止默认事件
event?.preventDefault()
if (!inputValue.value.trim() || loading.value || isStreaming.value) {
return
}
if (!originalUserInput.value) {
originalUserInput.value = inputValue.value
}
if (isPaused.value || isStreaming.value) {
if (isPaused.value || isStreaming.value) {
return
}
if (inputValue.value) {
Expand Down Expand Up @@ -471,6 +482,8 @@ const handleDialogClose = (done: () => void) => {
.catch(() => {
// 点击取消
})
} else {
done()
}
}

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 appears to be an Angular component for generating AI role-playing scenarios with text prompts and responses. Here's a summary of the changes and suggestions:

Changes Summary:

  1. CSS Class Added: In line 32 (<div> element), mt-8 has been added, which should have no effect since there were only two instances before.

  2. Stream Function Update: The function startStreamingOutput is not defined, so it will result in errors when called. This needs to be implemented or removed based on its intended functionality.

  3. Submit Handler Updates:

    • Removed duplicate handling of key combinations.
    • Prevented submission if input is empty or if dialog is being paused or streaming.

Optimization Suggestions:

  1. Remove Unused Variables: Variable streamTimer can likely be moved to local scope within handleDialogSave instead of declaring it globally.

  2. Consistent Capitalization and Spacing: Consider using consistent capitalization and spacing throughout the codebase to enhance readability.

  3. Error Handling Review: Ensure that all asynchronous operations have proper error handling mechanisms, especially those involving API calls.

  4. Code Refactoring: If the application logic involves more complex interactions or states, consider refactoring the component to simplify and improve maintainability.

Here's an updated version of the component with some adjustments and comments:

<!-- ... -->
<template>
  <div v-if="answer && !loading && !isStreaming">
    <!-- ... -->
    <el-button type="primary" @click="() => emit('replace', answer)" disabled>Replace</el-button>
    <!-- ... -->
  <div>
  
  <!-- ... -->
  
<script>
import { defineComponent } from 'vue';
// Import other components and plugins here

export default defineComponent({
  name: 'ApplicationGenerateDialog',
  data() {
    return {
      // Existing data properties...
      
      isPaused.value = false; // Initialize pause state
  
      streamTimer: null;
    };
  },
  methods: {
    startStreamingOutput() {
      this.isPaused.value = false;
      this.streamTimer = setInterval(() => {
        if (this.isApiComplete.value && !this.isPaused.value) {
          // Update display content
          const currentAnswer = this.chatMessages.value[this.chatMessages.length - 1];
          if (currentAnswer && currentAnswer.role === 'ai') {
            // Your actual streaming implementation here
          }
        }
      }, 1000); // Adjust interval as needed
    },
    
    handleDialogClose(done: () => void): void {
      this.$confirm($t('views.application.generateDialog.close'), '', {
        confirmButtonText: $t('common.buttons.confirm'),
        cancelButtonText: $t('common.buttons.cancel')
      }).then(async () => {
        await this.saveAndQuit();
        done(true);
      }).catch(err => {
        console.error(err);
      });
    },

    saveAndQuit(): Promise<void> {
      return new Promise((resolve) => {
        // Save logic here
        resolve();
      });
    },
  },
});
</script>

<style scoped lang="less"></style>

This revised version includes comments explaining each change and maintains consistency across elements.

Expand Down
Loading