Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

code.mdx 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ---
  2. sidebar_position: 13
  3. slug: /code_component
  4. ---
  5. # Code component
  6. A component that enables users to integrate Python or JavaScript codes into their Agent for dynamic data processing.
  7. ---
  8. ## Scenarios
  9. A **Code** component is essential when you need to integrate complex code logic (Python or JavaScript) into your Agent for dynamic data processing.
  10. ## Input variables
  11. You can specify multiple input sources for the **Code** component. Click **+ Add variable** in the **Input variables** section to include the desired input variables.
  12. After defining an input variable, you are required to select from the dropdown menu:
  13. - A component ID under **Component Output**, or
  14. - A global variable under **Begin input**, which is defined in the **Begin** component.
  15. ## Coding field
  16. ### A Python code example
  17. ```Python
  18. def main(arg1: str, arg2: str) -> dict:
  19. return {
  20. "result": arg1 + arg2,
  21. }
  22. ```
  23. ### A JavaScript code example
  24. ```JavaScript
  25. const axios = require('axios');
  26. async function main(args) {
  27. try {
  28. const response = await axios.get('https://github.com/infiniflow/ragflow');
  29. console.log('Body:', response.data);
  30. } catch (error) {
  31. console.error('Error:', error.message);
  32. }
  33. }
  34. ```