# 커스텀 워크플로우 전처리 코드 사용

### 사용 예시

<figure><img src="/files/TndkooiX9OtDiwzVoAL0" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/kX3T37RMXiglhKexJqxR" alt=""><figcaption></figcaption></figure>

* 전처리 코드를 활용하여 Flowise 수행 전에 다른 작업을 수행하거나, 다른 워크플로우 간의 연결을 할 수 있습니다.
  * 위 사용 예시는 다른 워크플로우의 응답을 받아서 해당 워크플로우의 응답을 LLM으로 평가해보는 예시입니다.
  * 즉, 다른 워크플로우 수행 후 현재 워크플로우를 수행하는 예시입니다.

### 전처리 코드 추가

<figure><img src="/files/ZNFUUF7q70r3V1Rz9aOI" alt=""><figcaption></figcaption></figure>

* 워크플로우 리비전 정보 탭의 수정하기 버튼을 눌러 코드창을 활성화합니다.
* 전처리 코드창에 아래와 같은 코드를 추가합니다.
* `async/await` 비동기 함수를 지원합니다.

```python
async def run(data: dict) -> dict:
    data.setdefault('overrideConfig', {})
    data['overrideConfig'].setdefault('functionInputVariables', {})

    import requests
    import re
    import json

    workflow_id = 253 # 평가 대상 워크플로우 ID
    bearer_token = 'ebbff88bd6a948278cba98155da68f1e' # 평가 대상 워크플로우 info 호출 후 발급받은 Bearer Token 값
    genos_url = 'https://genos.mnc.ai:3443'
    url = f'{genos_url}/api/gateway/workflow/{workflow_id}'
    headers = dict(Authorization=f'Bearer {bearer_token}')

    res = requests.post(f'{url}/run/v2' , json=data , headers=headers)
    result = res.json()

    data['overrideConfig']["functionInputVariables"]["api_answer"] = result['data']['text']
    return data
```

* API를 호출 하고, API의 응답 중 `"text"`의 값을 `"api_answer"`에 추가합니다.
  * key 값은 원하는 값으로 추가 가능합니다. flowise에서 같은 이름의 변수를 추가해야 합니다.
* 위 예시 코드는 GenOS 워크플로우 API 응답 데이터를 기반으로 동작합니다. GenOS 워크플로우 API 를 사용하는 방법은 [예시](/default/v1.7.5.1/advanced-tutorials/guides/api.md)를 참고하세요.

### 노드 편집

<figure><img src="/files/GA3fPDrHtGD2A1F3l32C" alt=""><figcaption></figcaption></figure>

* Custom JS Function 노드의 Input variables를 클릭합니다.

<figure><img src="/files/ddhp25QSr5QVFES4dmWL" alt=""><figcaption></figcaption></figure>

* 전처리 노드에서 전달하는 key값과 동일한 변수를 추가합니다.
  * Input값은 전처리 코드 실행 후 전달 받은 값으로 변경되기 때문에 어떠한 값이든 넣어줍니다.

<figure><img src="/files/BroPF398c5kdpusYcE5N" alt=""><figcaption></figcaption></figure>

* Prompt Template 노드의 Format Prompt Values 버튼을 클릭합니다.

<figure><img src="/files/CQpLdC2cH8BE72cB0iCV" alt=""><figcaption></figcaption></figure>

* Key값으로 `api_answer`를 추가하고, 값은 Custom JS Function 노드를 선택합니다.

<figure><img src="/files/dNtxLJU9xJOC7OvRiLDZ" alt=""><figcaption></figcaption></figure>

* 프롬프트 편집창을 확대합니다.

<figure><img src="/files/xqOJrddEIgZBHT53p7rK" alt=""><figcaption></figcaption></figure>

* 프롬프트에 `{question}` 과 전처리 코드에서 전달 받은 `{api_answer}` 를 포함하여 원하는 값을 입력합니다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://genos-docs.gitbook.io/default/v1.7.5.1/advanced-tutorials/guides/workflow/preprocess.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
