Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 파이썬
- euc-kr
- dataset
- 달력
- swift
- VBA
- insert into
- 유성
- 스위프트
- 대전 자전거
- file move
- mdb table 합치기
- EXIF data
- C#
- 자전거
- exifread
- python
- Xcode
- Exif
- StreamReader
- 대전
- 엑셀
- swift html parser
- kanna parser
- kanna html parser
- 대전 업힐
- 딴지일보 자유게시판 파씽
- MDB
- 노은
- html parser
Archives
- Today
- Total
Fly to the sky & Return
chatGPT api 이용 sample code 본문
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
To use the OpenAI GPT API in Python, you can use the openai library, which provides a simple Python interface to interact with the OpenAI GPT API. Here's a basic example of how you could generate text using the GPT API:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import openai
# Set the OpenAI API key
openai.api_key = "YOUR_API_KEY"
# Define the model and prompt to use
model_engine = "text-davinci-002"
prompt = "What is the capital of France?"
# Generate a response to the prompt
completion = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
message = completion.choices[0].text
print(message)
|
cs |
In this example, you first set your OpenAI API key using the openai.api_key property. Then, you specify the model engine to use (in this case, text-davinci-002) and the prompt you want to generate a response for. Finally, you use the openai.Completion.create method to generate a response, passing in the model engine, prompt, and other parameters as required. The generated response is then stored in the message variable, which you can print or use as desired.
Note that you'll need to sign up for an OpenAI API key to use the GPT API. You can sign up for an API key at the OpenAI website: https://beta.openai.com/signup/.
'프로그래밍 > 파이썬' 카테고리의 다른 글
[Pygame] Sudoku solution with backtracking (0) | 2023.09.24 |
---|---|
Ubuntu에서 아나콘다 설치하기 (0) | 2023.02.06 |
Exfread를 이용한 EXIF data 추출 및 날짜별 폴더 생성해서 사진 옮기기 .....2 (0) | 2018.03.19 |
파이썬으로 엑셀 다루기.......2 엑셀로 달력을 만들어보자.. (0) | 2017.12.28 |
파이썬으로 Excel 다루기 ..........1 (0) | 2017.12.22 |