본문 바로가기

기타

[기타] ChatGPT 사용법(chatgpt)

반응형

ChatGPT 사용법

 GPT-3 = Generative Pre-trained Transformer 3

ChatGPT 사이트 : https://chat.openai.com

 

가입(Sign up)하기

 

 

 

 

 

예시)

- what is are name?

 

- 파이션으로 구구단 코드 생성해줘

 

ChatGPT

- Release Notes


OpenAI ChatGPT API

Welcome to OpenAI : https://platform.openai.com

API 키 생성

 

 

 

OPENAI_API_KEY 환경 변수 등록

export OPENAI_API_KEY="sk-cFsdfsdbsdkflserjofwekfjowefkwerHfeefwq25uGuuoXV"
echo $OPENAI_API_KEY
$ echo $OPENAI_API_KEY
sk-cFsdfsdbsdkflserjofwekfjowefkwerHfeefwq25uGuuoXV

 

 

curl 명령

what is are name?

curl -s --insecure https://api.openai.com/v1/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
  "model": "text-davinci-003",
  "prompt": "what is are name?\nAI:",
  "temperature": 0.9,
  "max_tokens": 150,
  "top_p": 1,
  "frequency_penalty": 0.0,
  "presence_penalty": 0.6,
  "stop": [" Human:", " AI:"]
}' | jq .

My name is AI.

{
  "id": "cmpl-6gV5jaX29jDYf8RZNfFUDBGYrCrfW",
  "object": "text_completion",
  "created": 1675587311,
  "model": "text-davinci-003",
  "choices": [
    {
      "text": "\nMy name is AI.",
      "index": 0,
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 8,
    "completion_tokens": 6,
    "total_tokens": 14
  }
}

jq 명령으로 결괏값만 뽑아내기

curl -s --insecure https://api.openai.com/v1/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
  "model": "text-davinci-003",
  "prompt": "what is are name?\nAI:",
  "temperature": 0.9,
  "max_tokens": 150,
  "top_p": 1,
  "frequency_penalty": 0.0,
  "presence_penalty": 0.6,
  "stop": [" Human:", " AI:"]
}' | jq '.choices[].text'

728x90
반응형