Python을 활용한 프리셋 API
이 예제 코드는 LaaS에서 preset API를 활용하는 방법을 설명합니다.
1. 배포된 프리셋 조회
- 배포된 프리셋의 정보를 조회 할 때 사용
 
import requests
def request_preset_info():
    project = "YOUR_PROJECT_CODE"
    api_key = "YOUR_API_KEY"
    hash = "YOUR_PRESET_HASH"
    # Set request url
    laas_preset_url = f"https://api-laas.wanted.co.kr/api/preset/{hash}"
    # Set the headers
    headers = {
        "project": project,
        "apiKey": api_key
    }
    try:
        # Make the GET request
        response = requests.get(laas_preset_url, headers=headers)
        # Print the response or handle it as needed
        print("Response:", response.text)
    except Exception as e:
        # Handle any exceptions
        print("An error occurred:", e)
2. Chat 호출
- 배포된 프리셋을 사용하여 LLM의 chat API를 호출
 
case1) 기본 프리셋 호출
import requests
def request_chat_completion():
    project_code = "YOUR_PROJECT_CODE"
    api_key = "YOUR_API_KEY"
    hash = "YOUR_PRESET_HASH"
    # Set request url
    laas_chat_url = "https://api-laas.wanted.co.kr/api/preset/v2/chat/completions"
    # Set the headers
    headers = {
        "project": project_code,
        "apiKey": api_key,
        "Content-Type": "application/json; charset=utf-8"
    }
    # Set the request
    data = {
        "hash": hash
    }
    try:
        # Make the POST request
        response = requests.post(laas_chat_url, headers=headers, json=data)
        # Print the response or handle it as needed
        print("Response:", response.text)
    except Exception as e:
        # Handle any exceptions
        print("An error occurred:", e)
위의 코드는 에디터를 다음과 같이 설정 했을 때와 동일하게 처리됩니다.

case2) 가변 포함 프리셋 호출
- 가변값 
question을원티 드랩으로 설정한 예시입니다. 
import requests
def request_chat_completion_with_question():
    project_code = "YOUR_PROJECT_CODE"
    api_key = "YOUR_API_KEY"
    hash = "YOUR_PRESET_HASH"
    # Set request url
    laas_chat_url = "https://api-laas.wanted.co.kr/api/preset/v2/chat/completions"
    # Set the headers
    headers = {
        "project": project_code,
        "apiKey": api_key,
        "Content-Type": "application/json; charset=utf-8"
    }
    # Set the request
    data = {
        "hash": hash,
        "params": {
            "question": "원티드랩"
        }
    }
    try:
        # Make the POST request
        response = requests.post(laas_chat_url, headers=headers, json=data)
        # Print the response or handle it as needed
        print("Response:", response.text)
    except Exception as e:
        # Handle any exceptions
        print("An error occurred:", e)
API 호출시 프리셋의 가변값이, params에 전달한 값으로 설정되어 호출됩니다.
에디터에서 설정한 값은 API 호출시 사용 되지 않기 때문에 params를 설정하지 않을 경우, 빈 값으로 설정되어 호출됩니다.
