Share via


빠른 시작: 근거 검색(미리 보기)

이 가이드에 따라 Azure AI 콘텐츠 보안 기반 검색을 사용하여 LLM(대규모 언어 모델)의 텍스트 응답이 사용자가 제공한 원본 자료에 기반을 두고 있는지 확인합니다.

필수 조건

  • Azure 구독 - 체험 구독 만들기
  • Azure 구독이 있으면 Azure Portal에서 콘텐츠 안전 리소스를 생성하여 키와 엔드포인트를 가져옵니다. 리소스의 고유한 이름을 입력하고, 구독을 선택하고, 리소스 그룹, 지원되는 지역(미국 동부 2, 미국 서부, 스웨덴 중부) 및 지원되는 가격 책정 계층을 선택합니다. 다음으로 만들기를 선택합니다.
    • 리소스를 배포하는 데 몇 분 정도 걸립니다. 완료되면 새 리소스로 이동하세요. 왼쪽 창의 리소스 관리에서 API 키 및 엔드포인트를 선택합니다. 나중에 사용할 수 있도록 구독 키 값 중 하나와 엔드포인트를 임시 위치에 복사합니다.
  • (선택 사항) 추론 기능을 사용하려면 GPT 모델이 배포된 Azure OpenAI Service 리소스를 만듭니다.
  • cURL 또는 Python이 설치되었습니다.

추론하지 않고 근거 있음 확인

추론 기능이 없는 간단한 경우 근거 검색 API는 제출된 콘텐츠의 근거 없음을 true 또는 false로 분류합니다.

다음 섹션에서는 cURL을 사용한 샘플 요청을 안내합니다. 아래 명령을 텍스트 편집기에 붙여넣고 다음과 같이 변경합니다.

  1. <endpoint>을(를) 리소스와 연결된 엔드포인트 URL로 바꾸세요.

  2. <your_subscription_key>를 리소스의 키 중 하나로 바꿉니다.

  3. 선택적으로 본문의 "query" 또는 "text" 필드를 분석하려는 텍스트로 바꿉니다.

    curl --location --request POST '<endpoint>/contentsafety/text:detectGroundedness?api-version=2024-02-15-preview' \
    --header 'Ocp-Apim-Subscription-Key: <your_subscription_key>' \
    --header 'Content-Type: application/json' \
    --data-raw '{
      "domain": "Generic",
      "task": "QnA",
      "qna": {
           "query": "How much does she currently get paid per hour at the bank?"
      },
      "text": "12/hour",
      "groundingSources": [
        "I'm 21 years old and I need to make a decision about the next two years of my life. Within a week. I currently work for a bank that requires strict sales goals to meet. IF they aren't met three times (three months) you're canned. They pay me 10/hour and it's not unheard of to get a raise in 6ish months. The issue is, **I'm not a salesperson**. That's not my personality. I'm amazing at customer service, I have the most positive customer service \"reports\" done about me in the short time I've worked here. A coworker asked \"do you ask for people to fill these out? you have a ton\". That being said, I have a job opportunity at Chase Bank as a part time teller. What makes this decision so hard is that at my current job, I get 40 hours and Chase could only offer me 20 hours/week. Drive time to my current job is also 21 miles **one way** while Chase is literally 1.8 miles from my house, allowing me to go home for lunch. I do have an apartment and an awesome roommate that I know wont be late on his portion of rent, so paying bills with 20hours a week isn't the issue. It's the spending money and being broke all the time.\n\nI previously worked at Wal-Mart and took home just about 400 dollars every other week. So I know i can survive on this income. I just don't know whether I should go for Chase as I could definitely see myself having a career there. I'm a math major likely going to become an actuary, so Chase could provide excellent opportunities for me **eventually**."
      ],
      "reasoning": False
    }'
    
  4. 명령 프롬프트 창을 열고 cURL 명령을 실행합니다.

QnA(질문 답변) 작업 대신 요약 작업을 테스트하려면 다음 샘플 JSON 본문을 사용합니다.

{
    "domain": "Medical",
    "task": "Summarization",
    "text": "Ms Johnson has been in the hospital after experiencing a stroke.",
    "groundingSources": ["Our patient, Ms. Johnson, presented with persistent fatigue, unexplained weight loss, and frequent night sweats. After a series of tests, she was diagnosed with Hodgkin’s lymphoma, a type of cancer that affects the lymphatic system. The diagnosis was confirmed through a lymph node biopsy revealing the presence of Reed-Sternberg cells, a characteristic of this disease. She was further staged using PET-CT scans. Her treatment plan includes chemotherapy and possibly radiation therapy, depending on her response to treatment. The medical team remains optimistic about her prognosis given the high cure rate of Hodgkin’s lymphoma."],
    "reasoning": false
}

URL에는 다음 필드가 포함되어야 합니다.

속성 필수 설명 Type
API 버전 Required 사용할 API 버전입니다. 현재 버전은 api-version=2024-02-15-preview입니다. 예: <endpoint>/contentsafety/text:detectGroundedness?api-version=2024-02-15-preview 문자열

요청 본문의 매개 변수는 다음 표에 정의되어 있습니다.

속성 Description Type
도메인 (선택 사항) MEDICAL 또는 GENERIC. 기본값: GENERIC. 열거형
작업 (선택 사항) 작업 형식: QnA, Summarization. 기본값: Summarization. 열거형
qna (선택 사항) 작업 종류가 QnA인 경우 QnA 데이터를 보관합니다. 문자열
- query (선택 사항) QnA 작업의 질문을 나타냅니다. 문자 제한: 7,500. 문자열
text (필수) 확인할 LLM 출력 텍스트입니다. 문자 제한: 7,500. 문자열
groundingSources (필수) 일련의 근거 있는 원본을 사용하여 AI 생성 텍스트의 유효성을 검사합니다. 단일 요청으로 최대 55,000자의 근거 있는 원본을 분석할 수 있습니다. 문자열 ARRAY
추론 (선택 사항) 추론 기능을 사용할지 여부를 지정합니다. 기본값은 false입니다. true인 경우 설명을 제공하려면 사용자 고유의 Azure OpenAI GPT-4 Turbo 리소스를 가져와야 합니다. 주의: 추론을 사용하면 처리 시간이 늘어나게 됩니다. Boolean

API 응답 해석

요청을 제출하면 수행된 근거 분석이 반영된 JSON 응답을 받게 됩니다. 일반적인 출력은 다음과 같습니다.

{
    "ungroundedDetected": true,
    "ungroundedPercentage": 1,
    "ungroundedDetails": [
        {
            "text": "12/hour."
        }
    ]
}

출력의 JSON 개체는 다음과 같이 정의됩니다.

속성 Description Type
ungroundedDetected 텍스트가 근거 없음을 나타내는지 여부를 나타냅니다. Boolean
ungroundedPercentage 0에서 1 사이의 숫자로 표현되는 근거 없음으로 식별되는 텍스트의 비율을 지정합니다. 여기서 0은 근거 없음 콘텐츠가 없음을 나타내고 1은 완전히 근거 없는 콘텐츠를 나타냅니다. Float
ungroundedDetails 구체적인 예와 비율을 통해 근거 없는 콘텐츠에 대한 인사이트를 제공합니다. Array
-text 근거 없는 특정 텍스트입니다. 문자열

추론을 통해 근거 있음 확인

근거 검색 API는 API 응답에 추론을 포함하는 옵션을 제공합니다. 추론이 사용하도록 설정되면 응답에는 검색된 근거 없음에 대한 특정 인스턴스와 설명을 자세히 설명하는 "reasoning" 필드가 포함됩니다. 주의: 추론을 사용하면 처리 시간이 늘어나고 추가 비용이 발생합니다.

자체 GPT 배포 가져오기

지금은 Azure OpenAI GPT-4 Turbo 리소스만 지원하며 다른 GPT 유형은 지원하지 않습니다. GPT-4 Turbo 리소스는 모든 지역에 배포될 수 있습니다. 그러나 잠재적인 대기 시간을 최소화하기 위해 콘텐츠 안전 리소스와 동일한 지역에 배치하는 것이 좋습니다.

Azure OpenAI GPT4-Turbo 리소스를 사용하여 추론 기능을 사용하도록 설정하려면 관리 ID를 사용하여 콘텐츠 보안 리소스가 Azure OpenAI 리소스에 액세스할 수 있도록 허용합니다.

  1. Azure AI 콘텐츠 보안을 위해 관리 ID를 사용하도록 설정합니다.

    Azure Portal에서 Azure AI 콘텐츠 보안 인스턴스로 이동합니다. 설정 범주에서 ID 섹션을 찾습니다. 시스템 할당 관리 ID를 사용하도록 설정합니다. 이 작업을 수행하면 다른 리소스에 액세스하기 위해 Azure 내에서 인식하고 사용할 수 있는 ID가 Azure AI 콘텐츠 보안 인스턴스에 부여됩니다.

    Azure Portal의 콘텐츠 보안 ID 리소스 스크린샷.

  2. 관리 ID에 역할을 할당합니다.

    Azure OpenAI 인스턴스로 이동하고 역할 할당 추가를 선택하여 Azure AI 콘텐츠 보안 ID에 Azure OpenAI 역할을 할당하는 프로세스를 시작합니다.

    Azure Portal에서 역할 할당을 추가하는 스크린샷.

    사용자 또는 기여자 역할을 선택합니다.

    기여자 및 사용자 역할이 목록에 표시된 Azure Portal의 스크린샷.

API 요청 만들기

Groundedness 검색 API에 대한 요청에서 "reasoning" 본문 매개 변수를 true로 설정하고 기타 필요한 매개 변수를 제공합니다.

 {
  "reasoning": true,
  "llmResource": {
    "resourceType": "AzureOpenAI",
    "azureOpenAIEndpoint": "<your_OpenAI_endpoint>",
    "azureOpenAIDeploymentName": "<your_deployment_name>"
  }
}

다음 섹션에서는 cURL을 사용한 샘플 요청을 안내합니다. 아래 명령을 텍스트 편집기에 붙여넣고 다음과 같이 변경합니다.

  1. <endpoint>을(를) 리소스와 연결된 엔드포인트 URL로 바꾸세요.

  2. <your_subscription_key>를 리소스의 키 중 하나로 바꿉니다.

  3. 선택적으로 본문의 "query" 또는 "text" 필드를 분석하려는 텍스트로 바꿉니다.

    curl --location --request POST '<endpoint>/contentsafety/text:detectGroundedness?api-version=2024-02-15-preview' \
    --header 'Ocp-Apim-Subscription-Key: <your_subscription_key>' \
    --header 'Content-Type: application/json' \
    --data-raw '{
      "domain": "Generic",
      "task": "QnA",
      "qna": {
           "query": "How much does she currently get paid per hour at the bank?"
      },
      "text": "12/hour",
      "groundingSources": [
        "I'm 21 years old and I need to make a decision about the next two years of my life. Within a week. I currently work for a bank that requires strict sales goals to meet. IF they aren't met three times (three months) you're canned. They pay me 10/hour and it's not unheard of to get a raise in 6ish months. The issue is, **I'm not a salesperson**. That's not my personality. I'm amazing at customer service, I have the most positive customer service \"reports\" done about me in the short time I've worked here. A coworker asked \"do you ask for people to fill these out? you have a ton\". That being said, I have a job opportunity at Chase Bank as a part time teller. What makes this decision so hard is that at my current job, I get 40 hours and Chase could only offer me 20 hours/week. Drive time to my current job is also 21 miles **one way** while Chase is literally 1.8 miles from my house, allowing me to go home for lunch. I do have an apartment and an awesome roommate that I know wont be late on his portion of rent, so paying bills with 20hours a week isn't the issue. It's the spending money and being broke all the time.\n\nI previously worked at Wal-Mart and took home just about 400 dollars every other week. So I know i can survive on this income. I just don't know whether I should go for Chase as I could definitely see myself having a career there. I'm a math major likely going to become an actuary, so Chase could provide excellent opportunities for me **eventually**."
      ],
      "reasoning": true,
      "llmResource": {
            "resourceType": "AzureOpenAI",
            "azureOpenAIEndpoint": "<your_OpenAI_endpoint>",
            "azureOpenAIDeploymentName": "<your_deployment_name>"
    }'
    
  4. 명령 프롬프트 창을 열고 cURL 명령을 실행합니다.

요청 본문의 매개 변수는 다음 표에 정의되어 있습니다.

속성 Description Type
도메인 (선택 사항) MEDICAL 또는 GENERIC. 기본값: GENERIC. 열거형
작업 (선택 사항) 작업 형식: QnA, Summarization. 기본값: Summarization. 열거형
qna (선택 사항) 작업 종류가 QnA인 경우 QnA 데이터를 보관합니다. 문자열
- query (선택 사항) QnA 작업의 질문을 나타냅니다. 문자 제한: 7,500. 문자열
text (필수) 확인할 LLM 출력 텍스트입니다. 문자 제한: 7,500. 문자열
groundingSources (필수) 일련의 근거 있는 원본을 사용하여 AI 생성 텍스트의 유효성을 검사합니다. 단일 요청으로 최대 55,000자의 근거 있는 원본을 분석할 수 있습니다. 문자열 ARRAY
추론 (선택 사항) true로 설정하면 서비스가 Azure OpenAI 리소스를 사용하여 설명을 제공합니다. 주의: 추론을 사용하면 처리 시간이 늘어나고 추가 비용이 발생합니다. Boolean
llmResource (필수) 고유한 Azure OpenAI GPT4-Turbo 리소스를 사용하여 추론을 사용하도록 설정하려면 이 필드를 추가하고 사용된 리소스에 대한 하위 필드를 포함합니다. 문자열
- resourceType 사용 중인 리소스 형식을 지정합니다. 현재는 AzureOpenAI만 허용합니다. Azure OpenAI GPT-4 Turbo 리소스만 지원하며 다른 GPT 유형은 지원하지 않습니다. GPT-4 Turbo 리소스는 모든 지역에 배포될 수 있습니다. 그러나 잠재적인 대기 시간을 최소화하기 위해 콘텐츠 안전 리소스와 동일한 지역에 배치하는 것이 좋습니다. 열거형
- azureOpenAIEndpoint Azure OpenAI 서비스에 대한 엔드포인트 URL입니다. 문자열
- azureOpenAIDeploymentName 사용할 특정 GPT 배포의 이름입니다. 문자열

API 응답 해석

요청을 제출하면 수행된 근거 분석이 반영된 JSON 응답을 받게 됩니다. 일반적인 출력은 다음과 같습니다.

{
    "ungroundedDetected": true,
    "ungroundedPercentage": 1,
    "ungroundedDetails": [
        {
            "text": "12/hour.",
            "offset": {
                "utF8": 0,
                "utF16": 0,
                "codePoint": 0
            },
            "length": {
                "utF8": 8,
                "utF16": 8,
                "codePoint": 8
            },
            "reason": "None. The premise mentions a pay of \"10/hour\" but does not mention \"12/hour.\" It's neutral. "
        }
    ]
}

출력의 JSON 개체는 다음과 같이 정의됩니다.

속성 Description Type
ungroundedDetected 텍스트가 근거 없음을 나타내는지 여부를 나타냅니다. Boolean
ungroundedPercentage 0에서 1 사이의 숫자로 표현되는 근거 없음으로 식별되는 텍스트의 비율을 지정합니다. 여기서 0은 근거 없음 콘텐츠가 없음을 나타내고 1은 완전히 근거 없는 콘텐츠를 나타냅니다. Float
ungroundedDetails 구체적인 예와 비율을 통해 근거 없는 콘텐츠에 대한 인사이트를 제공합니다. Array
-text 근거 없는 특정 텍스트입니다. 문자열
-offset 다양한 인코딩에서 근거 없는 텍스트의 위치를 설명하는 개체입니다. 문자열
- offset > utf8 UTF-8 인코딩에서 근거 없는 텍스트의 오프셋 위치입니다. 정수
- offset > utf16 UTF-16 인코딩에서 근거 없는 텍스트의 오프셋 위치입니다. 정수
- offset > codePoint 유니코드 코드 포인트 측면에서 근거 없는 텍스트의 오프셋 위치입니다. 정수
-length 다양한 인코딩에서 근거 없는 텍스트의 길이를 설명하는 개체입니다. (utf8, utf16, codePoint), 오프셋과 유사합니다. Object
- length > utf8 UTF-8 인코딩에서 근거 없는 텍스트의 길이입니다. 정수
- length > utf16 UTF-16 인코딩에서 근거 없는 텍스트의 길이입니다. 정수
- length > codePoint 유니코드 코드 포인트 측면에서 근거 없는 텍스트의 길이입니다. 정수
-reason 검색된 근거 없음에 대한 설명을 제공합니다. 문자열

리소스 정리

Azure AI 서비스 구독을 정리하고 제거하려면 리소스 또는 리소스 그룹을 삭제할 수 있습니다. 리소스 그룹을 삭제하면 해당 리소스 그룹에 연결된 다른 모든 리소스가 함께 삭제됩니다.

다음 단계

근거 검색을 Prompt Shields와 같은 다른 LLM 안전성 기능과 결합합니다.