์ธ์ ์ฒ๋ฆฌ ์ค **๋ชจ๋ ๋ฉ์์ง(user, interlocutor ํฌํจ)**์ ๋ํด ์ธ๋ถ AI ์๋ฒ์์ ๊ทธ๋ฃน๋ณ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์์ต๋๋ค.
relationship: ๋ํ ์๋์์ ๊ด๊ณ๋ฅผ ๋ํ๋ด๋ ๋ฌธ์์ด์ ๋๋ค.
- ์์:
"FRIEND","SUPERIOR","COWORKER","LOVER"๋ฑ - ํด๋ผ์ด์ธํธ์์ ์์ ๋กญ๊ฒ ์ ์ ๊ฐ๋ฅ
relationship_info: ๊ด๊ณ์ ๋ํ ์ถ๊ฐ ์ ๋ณด๋ฅผ ๋ด๋ ๋ฌธ์์ด์ ๋๋ค.
- ์์:
"2๋ ์ง๊ธฐ","์ ์ ์ฌ์","๊ฐ์ ๋์๋ฆฌ","3๊ฐ์ ์ฌ๊ท"๋ฑ - AI ์๋ฒ๊ฐ ๋ํ ๋งฅ๋ฝ์ ๋ ์ ํํ ์ดํดํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
๊ฐ์ ๋ฐํ์๊ฐ ์ฐ์์ผ๋ก ๋ณด๋ธ ๋ฉ์์ง ๊ทธ๋ฃน์ ๋ํ๋ ๋๋ค.
์์:
[๊ทธ๋ฃน 1] ์ฌ์ฉ์: "๋ด์ผ ํ์ ์ ์ ๊ฒฐ๊ณผ ์ ๋ฆฌํด์ ๊ณต์ ํด ์ฃผ์ธ์"
[๊ทธ๋ฃน 1] ์ฌ์ฉ์: "ํ์๊ฐ ์ค์ 9์๋๊น 9์ ์ ์ ์ฃผ์ธ์"
[๊ทธ๋ฃน 2] ์๋๋ฐฉ: "๋ค ์๊ฒ ์ต๋๋ค"
[๊ทธ๋ฃน 3] ์ฌ์ฉ์: "๋ค์๋ถํฐ๋ ๋์น์๊ฒ ์ผ์ฒ๋ฆฌ ํด์ฃผ์ธ์"
- ๊ทธ๋ฃน 1: ์ฌ์ฉ์๊ฐ ์ฐ์์ผ๋ก ๋ณด๋ธ 2๊ฐ ๋ฉ์์ง
- ๊ทธ๋ฃน 2: ์๋๋ฐฉ ๋ฉ์์ง (interlocutor)
- ๊ทธ๋ฃน 3: ์ฌ์ฉ์๊ฐ ๋ค์ ๋ณด๋ธ ๋ฉ์์ง (์ ๊ทธ๋ฃน)
AI ์๋ฒ๋ ๊ทธ๋ฃน ๋จ์๋ก ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค.
POST AI_BASE_URL/api/analyze-messages
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY (์ ํ์ฌํญ){
"relationship": "FRIEND",
"relationship_info": "2๋
์ง๊ธฐ",
"messages": [
{
"message_id": "uuid-string",
"text": "์ฌ์ฉ์๊ฐ ๋ณด๋ธ ๋ฉ์์ง ํ
์คํธ",
"speaker": "user",
"confidence": 0.95,
"group_id": 1
},
{
"message_id": "another-uuid",
"text": "๋ ๋ค๋ฅธ ์ฌ์ฉ์ ๋ฉ์์ง",
"speaker": "user",
"confidence": 0.87,
"group_id": 1
},
{
"message_id": "third-uuid",
"text": "์๋๋ฐฉ์ด ๋ณด๋ธ ๋ฉ์์ง",
"speaker": "interlocutor",
"confidence": 0.92,
"group_id": 2
},
{
"message_id": "fourth-uuid",
"text": "๋ค์ ์ฌ์ฉ์๊ฐ ๋ณด๋ธ ๋ฉ์์ง",
"speaker": "user",
"confidence": 0.89,
"group_id": 3
}
]
}| ํ๋ | ํ์ | ์ค๋ช |
|---|---|---|
relationship |
String | [ํ์] ๋ํ ์๋์์ ๊ด๊ณ (์: "FRIEND", "SUPERIOR", "COWORKER" ๋ฑ) |
relationship_info |
String | [ํ์] ๊ด๊ณ์ ๋ํ ์ถ๊ฐ ์ ๋ณด (์: "2๋ ์ง๊ธฐ", "์ ์ ์ฌ์" ๋ฑ) |
messages |
Array | [ํ์] ๋ชจ๋ ๋ฉ์์ง ๋ชฉ๋ก (user, interlocutor ๋ชจ๋ ํฌํจ) |
messages[].message_id |
String | ๋ฉ์์ง ๊ณ ์ ID (UUID) |
messages[].text |
String | ๋ฉ์์ง ์๋ฌธ |
messages[].speaker |
String | ๋ฐํ์ ("user" ๋๋ "interlocutor") |
messages[].confidence |
Float | OCR ์ ๋ขฐ๋ (0.0 ~ 1.0) |
messages[].group_id |
Integer | ์ฐ์ ๋ฉ์์ง ๊ทธ๋ฃน ID (๊ฐ์ ๊ทธ๋ฃน = ์ฐ์์ผ๋ก ๋ณด๋ธ ๋ฉ์์ง) |
HTTP 200 ์๋ต์ด๋ฉด ์ฑ๊ณต์ผ๋ก ์ฒ๋ฆฌ๋ฉ๋๋ค. status ํ๋๋ ์ ํ์ฌํญ์
๋๋ค.
์ค์: ์๋ต์ ๊ทธ๋ฃน ๋จ์๋ก ๋ฐํ๋ฉ๋๋ค. ๊ฐ ๊ทธ๋ฃน์ ๋ชจ๋ ๋ฉ์์ง์ ๋์ผํ ๋ถ์ ๊ฒฐ๊ณผ๊ฐ ์ ์ฉ๋ฉ๋๋ค.
[
{
"group_id": 1,
"emotional_tone": "NEUTRAL",
"score": 75,
"impact_score": 2,
"review_comment": "์๋๋ฐฉ์ ๋ฐฐ๋ คํ๋ ์ข์ ํํ์
๋๋ค.",
"suggested_alternative": null
},
{
"group_id": 2,
"emotional_tone": "NEGATIVE",
"score": 20,
"impact_score": -2,
"review_comment": "๋ค์ ๊ณต๊ฒฉ์ ์ผ๋ก ๋ค๋ฆด ์ ์์ด์.",
"suggested_alternative": "'๊ทธ ๋ถ๋ถ์ด ์กฐ๊ธ ์์ํ๋๋ฐ, ๋ค ์๊ฐ์ ์ข ๋ ๋ฃ๊ณ ์ถ์ด.'๋ผ๊ณ ๋งํด๋ณด์ธ์."
}
]{
"status": "success",
"response": [
{
"group_id": 1,
"emotional_tone": "NEUTRAL",
"score": 75,
"impact_score": 2,
"review_comment": "์๋๋ฐฉ์ ๋ฐฐ๋ คํ๋ ์ข์ ํํ์
๋๋ค.",
"suggested_alternative": null
}
]
}| ํ๋ | ํ์ | ์ค๋ช |
|---|---|---|
status |
String | (์ ํ) ์๋ต ์ํ ("success" ๋๋ "error") |
response |
Array | (์ต์ 2 ์ฌ์ฉ ์) ๊ฐ ๊ทธ๋ฃน์ ๋ํ ๋ถ์ ๊ฒฐ๊ณผ ๋ฐฐ์ด |
[].group_id |
Integer | [ํ์] ๋ถ์ ๋์ ๊ทธ๋ฃน ID (์์ฒญํ messages์ group_id์ ๋งค์นญ) |
[].emotional_tone |
String | [ํ์] ๊ฐ์ ํค ("POSITIVE", "NEUTRAL", "NEGATIVE" ๋ฑ) |
[].score |
Integer | [ํ์] AI๊ฐ ํ๊ฐํ ์ ์ (0 ~ 100) |
[].impact_score |
Integer | [ํ์] ์ํฅ ์ ์ (-5 ~ +5) |
[].review_comment |
String | [ํ์] AI์ ํผ๋๋ฐฑ ๋ฉ์์ง |
[].suggested_alternative |
String | null | (์ ํ) ๋์ ํํ ์ ์ (์์ผ๋ฉด null) |
{
"status": "error",
"error_code": "RATE_LIMIT_EXCEEDED",
"message": "API rate limit exceeded. Please try again later."
}external_service.py ํ์ผ์์ ์ค์ :
from external_service import get_external_service
# ์ธ๋ถ API ์ฌ์ฉ
service = get_external_service(
api_url="https://your-ai-server.com/api/analyze-messages",
api_key="your_api_key_here"
)์ธ์ ์ฒ๋ฆฌ ์ relationship๊ณผ relationship_info ํ๋ผ๋ฏธํฐ๋ ํ์์ ๋๋ค:
import requests
# ์ธ์
์ฒ๋ฆฌ ํธ์ถ
response = requests.post(
"http://localhost:8000/sessions/{session_id}/process",
params={
"relationship": "FRIEND", # ํ์: ๊ด๊ณ
"relationship_info": "2๋
์ง๊ธฐ" # ํ์: ์ถ๊ฐ ์ ๋ณด
}
)# ์ธ๋ถ ์๋ฒ ์ฐ๋
external_service = get_external_service(
api_url="https://your-ai-server.com/api/analyze-messages",
api_key="your_api_key"
)
score_results = await external_service.get_scores_for_messages(
merged_messages,
relationship="FRIEND",
relationship_info="2๋
์ง๊ธฐ"
)์ธ๋ถ API URL์ ์ค์ ํ์ง ์์ผ๋ฉด ์๋์ผ๋ก ๋๋ฏธ ๋ชจ๋๋ก ๋์ํฉ๋๋ค:
# api_url=None์ด๋ฉด ๋๋ฏธ ๋ฐ์ดํฐ ์์ฑ
service = get_external_service() # ๋๋ฏธ ๋ชจ๋๋๋ฏธ ๋ชจ๋์์๋:
- ๋๋ค score (20 ~ 95)
- ๋๋ค emotional_tone (POSITIVE, NEUTRAL, NEGATIVE)
- ๋๋ค impact_score (-3 ~ 3)
- ๋ฏธ๋ฆฌ ์ ์๋ review_comment ์ค ๋๋ค ์ ํ
- ๋๋ค suggested_alternative (์๊ฑฐ๋ null)
- 0.5์ด ์ง์ฐ ์๋ฎฌ๋ ์ด์
curl -X POST https://your-ai-server.com/api/analyze-messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"relationship": "SUPERIOR",
"relationship_info": "์ ์
์ฌ์",
"messages": [
{
"message_id": "123e4567-e89b-12d3-a456-426614174000",
"text": "๋ด์ผ ํ์ ์ ์ ๊ฒฐ๊ณผ ์ ๋ฆฌํด์ ๊ณต์ ํด ์ฃผ์ธ์",
"speaker": "user",
"confidence": 0.95,
"group_id": 1
},
{
"message_id": "223e4567-e89b-12d3-a456-426614174001",
"text": "๋ค ์๊ฒ ์ต๋๋ค",
"speaker": "interlocutor",
"confidence": 0.92,
"group_id": 2
}
]
}'import requests
response = requests.post(
"https://your-ai-server.com/api/analyze-messages",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
},
json={
"relationship": "FRIEND", # ํ์
"relationship_info": "2๋
์ง๊ธฐ", # ํ์
"messages": [
{
"message_id": "123e4567-e89b-12d3-a456-426614174000",
"text": "๋ด์ผ ํ์ ์ ์ ๊ฒฐ๊ณผ ์ ๋ฆฌํด์ ๊ณต์ ํด ์ฃผ์ธ์",
"speaker": "user",
"confidence": 0.95,
"group_id": 1
},
{
"message_id": "223e4567-e89b-12d3-a456-426614174001",
"text": "ํ์๊ฐ ์ค์ 9์๋๊น 9์ ์ ์ ์ฃผ์ธ์",
"speaker": "user",
"confidence": 0.92,
"group_id": 1 # ๊ฐ์ ๊ทธ๋ฃน (์ฐ์ ๋ฉ์์ง)
},
{
"message_id": "323e4567-e89b-12d3-a456-426614174002",
"text": "๋ค ์๊ฒ ์ต๋๋ค",
"speaker": "interlocutor",
"confidence": 0.89,
"group_id": 2 # ์๋๋ฐฉ ๋ฉ์์ง
}
]
},
timeout=30
)
if response.status_code == 200:
data = response.json()
# ๋ฐฐ์ด์ด๋ฉด ๊ทธ๋๋ก ์ฌ์ฉ, ๊ฐ์ฒด๋ฉด 'response' ํค์์ ์ถ์ถ
results = data if isinstance(data, list) else data.get('response', [])
for result in results:
print(f"Group {result['group_id']}: Score={result['score']}, Comment={result['review_comment']}")- ํ์์์: 30์ด
- ์คํจ ์: ์๋์ผ๋ก ๋๋ฏธ ๋ฐ์ดํฐ๋ก fallback
- ์ฌ์๋: ์์ (1ํ๋ง ์๋)
- HTTPS ์ฌ์ฉ ํ์
- API ํค๋ ํ๊ฒฝ๋ณ์๋ก ๊ด๋ฆฌ (.env ํ์ผ ์ฌ์ฉ ๊ถ์ฅ)
- Rate Limiting ๊ณ ๋ ค (๋๋ฌด ๋ง์ ๋ฉ์์ง ํ ๋ฒ์ ์ ์ก ๋ฐฉ์ง)
.env ํ์ผ ์์ฑ:
EXTERNAL_API_URL=https://your-ai-server.com/api/analyze-messages
EXTERNAL_API_KEY=your_secret_api_key_here์ฝ๋์์ ์ฌ์ฉ:
import os
from dotenv import load_dotenv
load_dotenv()
service = get_external_service(
api_url=os.getenv("EXTERNAL_API_URL"),
api_key=os.getenv("EXTERNAL_API_KEY")
)์๋ต๋ฐ์ ๋ฐ์ดํฐ๋ ๋ค์๊ณผ ๊ฐ์ด ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅ๋ฉ๋๋ค:
- group_id: ํด๋น ๊ทธ๋ฃน์ ๋ชจ๋ ๋ฉ์์ง์ ๋์ผํ ๋ถ์ ๊ฒฐ๊ณผ๊ฐ ์ ์ฉ๋จ
- score: ์ ์ (0 ~ 100)
- emotional_tone: ๊ฐ์ ํค
- impact_score: ์ํฅ ์ ์
- review_comment: ํผ๋๋ฐฑ ๋ฉ์์ง
- suggested_alternative: ๋์ ํํ (์๋ ๊ฒฝ์ฐ)
๊ฐ์ group_id๋ฅผ ๊ฐ์ง ๋ชจ๋ ๋ฉ์์ง๋ ๋์ผํ ๋ถ์ ๊ฒฐ๊ณผ๋ฅผ ๊ณต์ ํฉ๋๋ค.