세오 (121.♡.44.169)
2024년 6월 17일 PM 08:01 · 수정됨(20:31)
안녕하세요.
제 웹사이트의 게시글을 Rest API를 이용해 불러온 후 gpt api를 이용해 번역해 게시하는 코드를 작성하려고 합니다.
기존에 claude 용으로 작성한 코드는 문제 없지 잘 작동합니다만.. GPT 용으로 코드를 여러번 변경해봐도 작동이 안됩니다.
```
클로드용
translated_title = get_text(client.messages.create(
model="claude-3-opus-20240229",
max_tokens=50,
temperature=0.0,
system="You will be provided with a sentence in Korean, and your task is to translate it into Japanese.",
messages=[
{"role": "user", "content": post_title},
{"role": "assistant", "content": ""}
]
).content)
GPT용
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": "You will be provided with a sentence in Korean, and your task is to translate it into Japanese."
},
{
"role": "user",
"content": f"{post_title}"
}
],
temperature=0.7,
max_tokens=64,
top_p=1
)
translated_title = response.choices[0].message['content'].strip()
```
클로드의 경우 SYSTEM에 프롬프트를 입력 후 결과물을 바로 받을 수 있었습니다만…
GPT에서는 이런 식으로 활용하는게 안되는 건가요?
GPT 웹사이트에서 사용하는 것처럼 채팅을 주고 받는 방식으로 활용해야되는건지 아니면 단순히 제가 잘못 사용하고 있는건지 궁금합니다.
감사합니다.
댓글 (1)
-
아아이폰점보
24.06.17 · 210.♡.239.38
댓글을 작성하려면 이 필요합니다.
[code=bash]
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}'
[/code]