Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-5-sonnet-20241022· AnthropicHugging Face LMArena Human Preference 140K

if (type === 'INTERNAL') { documentHeader = documentHeader as InternalDocumentHeader;…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Coherecommand-a-03-2025’s answer.
  1. User

    if (type === 'INTERNAL') { documentHeader = documentHeader as InternalDocumentHeader;

      const {
        senderList,
        recipientList,
        recipientsCount = 0,
        controllerComment,
        committee,
        approvalKind,
        assessmentProcessId,
        retellingProcessId,
      } = documentHeader;
    
      this.approvalKind = approvalKind;
      this.senders = senderList;
      this.recipients = recipientList;
      this.recipientsCount = recipientsCount;
      this.controllerComment = controllerComment ?? '';
      this.committee = committee;
    
      if (assessmentProcessId) {
        const {
          data: { processData },
        } = await getProcess({ path: { processId: assessmentProcessId } });
    
        this.documentAssessmentProcessText = processData;
      }
    
      if (retellingProcessId) {
        const {
          data: { processData },
        } = await getProcess({ path: { processId: retellingProcessId } });
    
        this.documentRetellingText = processData;
      }
    }
    
    if (type === 'OUTGOING') {
      documentHeader = documentHeader as OutgoingDocumentHeader;
    
      const {
        senderList,
        addresseeList = [],
        addresseesCount = 0,
        approvalKind,
        committee,
        isMedoDocument,
        retellingProcessId,
      } = documentHeader;
    
      this.isMedoDocument = isMedoDocument;
      this.senders = senderList;
      this.approvalKind = approvalKind;
      this.addresseeList = addresseeList;
      this.addresseesCount = addresseesCount;
      this.committee = committee;
    
      if (retellingProcessId) {
        const {
          data: { processData },
        } = await getProcess({ path: { processId: retellingProcessId } });
    
        this.documentRetellingText = processData;
      }
    }  Как сделать, чтобы await getProcess не повторялся так часто?
    
  2. Claude Assistant

    Можно вынести получение processData в отдельную функцию и переиспользовать её. Вот как можно улучшить код:

    private async getProcessData(processId: string | null): Promise<string | null> {
      if (!processId) return null;
      
      const {
        data: { processData },
      } = await getProcess({ path: { processId } });
      
      return processData;
    }
    
    // Основной код
    if (type === 'INTERNAL') {
      documentHeader = documentHeader as InternalDocumentHeader;
    
      const {
        senderList,
        recipientList,
        recipientsCount = 0,
        controllerComment,
        committee,
        approvalKind,
        assessmentProcessId,
        retellingProcessId,
      } = documentHeader;
    
      this.approvalKind = approvalKind;
      this.senders = senderList;
      this.recipients = recipientList;
      this.recipientsCount = recipientsCount;
      this.controllerComment = controllerComment ?? '';
      this.committee = committee;
    
      this.documentAssessmentProcessText = await this.getProcessData(assessmentProcessId);
      this.documentRetellingText = await this.getProcessData(retellingProcessId);
    }
    
    if (type === 'OUTGOING') {
      documentHeader = documentHeader as OutgoingDocumentHeader;
    
      const {
        senderList,
        addresseeList = [],
        addresseesCount = 0,
        approvalKind,
        committee,
        isMedoDocument,
        retellingProcessId,
      } = documentHeader;
    
      this.isMedoDocument = isMedoDocument;
      this.senders = senderList;
      this.approvalKind = approvalKind;
      this.addresseeList = addresseeList;
      this.addresseesCount = addresseesCount;
      this.committee = committee;
    
      this.documentRetellingText = await this.getProcessData(retellingProcessId);
    }
    

    Преимущества такого подхода:

    1. Уменьшается дублирование кода
    2. Логика получения processData инкапсулирована в отдельном методе
    3. Код становится более читаемым
    4. Если понадобится изменить логику получения processData, это нужно будет сделать только в одном месте

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.