중요합니다
이 기능은 미리 보기로 제공됩니다.
이 문서에서는 OpenAI Python SDK 및 SynapseML을 사용하여 Fabric에서 Azure OpenAI를 사용하는 방법을 보여 줍니다.
필수 조건
OpenAI Python SDK는 기본 런타임에 설치되지 않으므로 먼저 설치해야 합니다. 환경을 런타임 버전 1.3 이상으로 변경합니다.
%pip install -U openai
채팅
이전 단계에서 설명한 셀과 별도로 이 코드를 사용하여 Fabric Notebook에 새 셀을 만들어 OpenAI 라이브러리를 설치합니다. GPT-4.1 및 GPT-4.1-mini는 대화형 인터페이스에 최적화된 언어 모델입니다. 여기에 제시된 예제는 간단한 채팅 완료 작업을 보여주며 자습서로 사용할 수 없습니다.
비고
OpenAI Python SDK의 버전에 따라 메서드 이름과 매개 변수가 다를 수 있습니다. 사용 중인 버전에 대한 공식 설명서를 참조하세요.
import openai
response = openai.ChatCompletion.create(
deployment_id="gpt-4.1",
messages=[
{
"role": "user",
"content": """Analyze the following text and return a JSON array of issue insights.
Each item must include:
- issue_brief (1 sentence)
- scenario
- severity (high | medium | low)
- verbatim_quotes (list)
- recommended_fix
Text:
We booked the hotel room in advance for our family trip. The check-in the great however the room service was slow and pool was closed
Return JSON only.
"""
}
],
)
print(f"{response.choices[0].message.role}: {response.choices[0].message.content}")
출력
assistant: [
{
"issue_brief": "Room service was slow during the stay.",
"scenario": "Guests experienced delays in receiving room service after check-in.",
"severity": "medium",
"verbatim_quotes": [
"the room service was slow"
],
"recommended_fix": "Improve staffing or training for room service to ensure timely delivery of services."
},
{
"issue_brief": "The hotel pool was unavailable during the stay.",
"scenario": "Guests were unable to use the pool because it was closed.",
"severity": "medium",
"verbatim_quotes": [
"pool was closed"
],
"recommended_fix": "Notify guests in advance about facility closures and provide alternative amenities or compensation if possible."
}
]
포함(Embeddings)
이전 단계에서 설명한 셀과 별도로 이 코드를 사용하여 Fabric Notebook에 새 셀을 만들어 openai 라이브러리를 설치합니다. 포함은 기계 학습 모델 및 알고리즘에서 쉽게 활용할 수 있는 특수한 형식의 데이터 표현입니다. 부동 소수점 숫자의 벡터로 표현되는 텍스트의 정보가 풍부한 의미 체계 의미를 포함합니다. 벡터 공간에서 두 포함 간의 거리는 두 원본 입력 간의 의미론적 유사성과 관련이 있습니다. 예를 들어 두 텍스트가 비슷한 경우 벡터 표현도 유사해야 합니다.
여기에 설명된 예제에서는 포함을 가져오는 방법을 보여주며 이는 자습서로 의도된 것은 아닙니다.
response = openai.embeddings.create(
input="The food was delicious and the waiter...",
model="text-embedding-ada-002" # Or another embedding model
)
print(response)
출력
CreateEmbeddingResponse(
data=[
Embedding(
embedding=[
0.0022756962571293116,
-0.009305915795266628,
0.01574261300265789,
...
-0.015387134626507759,
-0.019424352794885635,
-0.0028009789530187845
],
index=0,
object='embedding'
)
],
model='text-embedding-ada-002',
object='list',
usage=Usage(
prompt_tokens=8,
total_tokens=8
)
)