您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. ## Configurations
  11. ### Input
  12. You can specify multiple input sources for the **Code** component. Click **+ Add variable** in the **Input variables** section to include the desired input variables.
  13. ### Code
  14. This field allows you to enter and edit your source code.
  15. #### A Python code example
  16. ```Python
  17. def main(arg1: str, arg2: str) -> dict:
  18. return {
  19. "result": arg1 + arg2,
  20. }
  21. ```
  22. #### A JavaScript code example
  23. ```JavaScript
  24. const axios = require('axios');
  25. async function main(args) {
  26. try {
  27. const response = await axios.get('https://github.com/infiniflow/ragflow');
  28. console.log('Body:', response.data);
  29. } catch (error) {
  30. console.error('Error:', error.message);
  31. }
  32. }
  33. ```
  34. ### Return values
  35. You define the output variable(s) of the **Code** component here.
  36. ### Output
  37. The defined output variable(s) will be auto-populated here.