Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. This field allows you to enter and edit your source code.
  17. ### A Python code example
  18. ```Python
  19. def main(arg1: str, arg2: str) -> dict:
  20. return {
  21. "result": arg1 + arg2,
  22. }
  23. ```
  24. ### A JavaScript code example
  25. ```JavaScript
  26. const axios = require('axios');
  27. async function main(args) {
  28. try {
  29. const response = await axios.get('https://github.com/infiniflow/ragflow');
  30. console.log('Body:', response.data);
  31. } catch (error) {
  32. console.error('Error:', error.message);
  33. }
  34. }
  35. ```