# GenOS 라이브러리 활용

업로드한 PyPI 패키지를 코드 스페이스, 워크플로우에서 어떻게 사용하는지 알아보겠습니다.

## 1. 코드스페이스 활용

### 1.1. pip install <라이브러리명>

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

코드스페이스 환경은 제노스 내부 PyPI 서버를 참조하도록 사전 설정되어 있어, 추가 설정 없이 `pip install <라이브러리명>` 명령어로 모듈을 즉시 설치할 수 있습니다

### 1.2. 코드 작성

```python
from simple_add import add

result = add('3','5')

print(result)
```

입력된 문자열 인자를 숫자 타입형으로 자동 변환하여 연산한 뒤, 결과값을 다시 문자열로 반환하는 `add` 함수 활용 예시입니다

### 1.3. 출력 확인

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

* 만약 라이브러리를 찾을 수 없다는 에러(`ModuleNotFoundError`)가 발생한다면, 아래 명령어를 통해 가상환경(venv)이 활성화되어 있는지 확인해 주세요

```
source /.venv/bin/activate
```

## 2. 워크플로우 활용

워크플로우에서도 필요한 라이브러리를 import 할 수 있습니다.

### 2.1. 워크플로우 생성

[워크플로우 만들기](/default/v1.7.5.1/basic-tutorials/guides/workflow.md)를 참고하시길 바랍니다.

### 2.2. 워크플로우 상세

#### 2.2.1. 첫번째 Flowise Step

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

간단하게 start와 Custom Function 노드로 구성된 flowise step입니다.

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

start 노드에서 nums 변수를 만들었습니다.

<figure><img src="/files/4VjbWsJo8WJ9NiE9Mecr" alt=""><figcaption></figcaption></figure>

Custom Function 노드에서 nums 변수를 입력인 question으로 업데이트하였습니다.

#### 2.2.2. 두번째 Python Step

```python
async def run(data: dict) -> dict:
    from util.genos_utils import genos_import
    simple_add = genos_import("simple_add")
    a,b = data['agentFlowExecutedData'][1]['data']['state']['nums'].split()
    result = simple_add.add(a,b)
    data['question'] = result
    return data
```

작성 예시입니다.

워크플로우 python step에서 `import genos`를 할 땐 다음과 같이

`from util.genos_utils import genos_import`를 한 이후

`클래스명 = genos_import("라이브러리명")` 을 이용해야 합니다.

#### 2.2.3. 세번째 Flowise Step

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

세번째 flowise step 역시 start와 Direct Reply 노드로 구성된 간단한 step입니다. Direct Reply에서

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

입력값인 question을 그대로 출력하게 하였습니다.

### 2.3. 출력 확인

워크플로우를 토대로 채팅을 만들었습니다. 만드는 방법은 [채팅 애플리케이션 만들기](/default/v1.7.5.1/basic-tutorials/guides/application/dev-chat.md)를 참고하시길 바랍니다.

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

다음과 같이 정확한 결과를 출력하는 걸 볼 수 있습니다.


---

# 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/basic-tutorials/guides/development/import-genos/use_to_genos_library.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.
