# 코드 서빙 활용

배포를 위해서는 `service.py` 파일이 존재해야 하며, 해당 파일 내에 `service` 함수가 반드시 정의되어 있어야 합니다.

* service.py

```python
from typing import Any, Dict

async def service(config: Dict[str, Any], data: Dict[str, Any]):
    data.update(config=config)
    return data
```

main 브랜치에 push를 합니다

```
[root@sangmin.lee-admin 2]$ git add .
[root@sangmin.lee-admin 2]$ git commit -m "함수명 테스트"
[main 287d51c] 함수명 테스트
 1 file changed, 1 insertion(+), 1 deletion(-)
[root@sangmin.lee-admin 2]$ git push origin main
Username for 'http://llmops-gitea-service:3000': sangmin.lee-admin
Password for 'http://sangmin.lee-admin@llmops-gitea-service:3000': 
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 104 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 331 bytes | 331.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: . Processing 1 references
remote: Processed 1 references in total
To http://llmops-gitea-service:3000/llmops/2.git
   0c064f6..287d51c  main -> main
```

바로 전 push한 커밋으로 배포를 진행합니다.

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

### 1. 로컬에서 코드서빙 활용

로컬 Bash에서 배포된 서버로 API 요청을 보내보겠습니다.

* input

```
curl --location 'https://genos.genon.ai/api/gateway/code_serving/코드서빙 번호/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer 발급반은 인증키 ' \
--data '{
    "question": "소금빵 레시피"
}'
```

* output

```
{"question":"소금빵 레시피","config":{}}%   
```

### 2. 워크플로우에서 코드서빙 활용

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

사진과 같이 Custom Function 노드를 가져옵니다.

* 함수 안의 코드
* ```javascript
  const axios = require('axios'); // axios 라이브러리 호출
  const url = 'https://genos.genon.ai/api/gateway/code_serving/코드서빙 번호/json';
  const token = '인증키';

  const requestData = {
      question: "소금빵 레시피"
      
  };

  try {
      const response = await axios.post(url, requestData, {
          headers: {
              'Content-Type': 'application/json',
              'Authorization': `Bearer ${token}`
          }
      });

      return response.data;

  } catch (error) {

      return { 
          error: error.message,
          details: error.response ? error.response.data : "No response from server"
      };
  }
  ```

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

정상적으로 API 요청된 것을 확인할 수 있습니다.


---

# 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/basic-tutorials/guides/development/code_serving/usage_code_serving.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.
