XWorker AI Integration Solution Documentation

XWorker is suitable for writing symbiotic systems of human-computer collaboration, that is, systems that can be modified by humans and AI together.

1. Metamodel New Attributes

Attribute Name Type Description
ai_needGenerate Boolean Marks whether content needs to be generated. When the value is true, the AI ​​generation task is executed
ai_promptContainsVars Boolean Controls whether the prompt word contains context variables (such as SWT button event variables in the Groovy script model)
ai_content_attribute String Specify the name of the attribute that stores the AI ​​generated results
ai_promptSystem String System-level role prompt words, placed at the beginning of the role=system message
ai_promptRequirement String User requirement description, placed in the middle of the role=system message
ai_getPromptFormat String Output format requirements, placed at the end of the role=system message

2. Metamodel New Methods

Core Control Methods

  • boolean ai_isNeedGenerate()

    Check whether content needs to be generated. By default, read the value of the ai_needGenerate attribute
  • void ai_generate()

    Execute content generation:

     

    1. When ai_isNeedGenerate() returns true, it is triggered
    2. By default, ChatService is called (stream mode)
    3. The result is passed to ai_onResult(content)processing

Prompt word processing method

  • String ai_getPrompt()

    Generate a complete system prompt word, default splicing:
    System prompt + user requirements + format requirements + variable inclusion identifier

     

  • String ai_getPromptSystem()

    Get role settings, default return ai_promptSystem value

     

  • String ai_getPromptRequirement()

    Get user requirements, default return ai_promptRequirement value

     

  • String ai_getPromptFormat()

    Get format requirements, default return ai_getPromptFormat value

     

Result processing method

  • void ai_onResult(String content)
    Process AI return results:
    By default, save to the specified attribute of ai_content_attribute

Service configuration method

  • ChatService ai_getChatService()

    Get the chat service instance, and use the system default service when null is returned

     

  • String ai_getContent()

    Get the edited content, and return ai_content_attribute specifies the value of the attribute

     

III. Typical application scenarios

1. AI automatic generation mode

Applicable scenarios: Multi-level content generation (such as novel generation system)
Execution process:

  1. Model tree traversal: deep traversal from the root node
  2. Generation detection: execute ai_isNeedGenerate()
  3. for each node
  4. Content generation: call ai_generate()
  5. for the node to be generated
  6. Loop detection: when generation occurs, wait for completion and then traverse again
  7. Termination condition: End the process when there is no generation demand in the whole tree

2. AI editing mode

Applicable scenarios: Single node content modification
Interaction process:

  1. Editor initialization:
    • System prompt = ai_getPrompt()
    • Edit content = ai_getContent()
  2. User interaction:
    • Enter the modification instruction as the user message
  3. Result processing:
    • After the user confirms, call ai_onResult() to save the result

Fourth, Extension Description

This solution achieves deep integration of AI capabilities by extending the metamodel, supporting two modes: fully automatic generation and interactive editing. Developers can flexibly customize AI behaviors through attribute configuration and method rewriting.

  • Custom Generation: You can achieve non-chat service generation (such as preset code injection) by rewriting ai_generate()
  • Variable Context: Automatically inject environment variable description when ai_promptContainsVars=true
  • Service Extension: You can access different AI service providers by implementing ai_getChatService()

Copyright ©  2007-2019 XWorker.org  版权所有  沪ICP备08000575号