Skip to content

Commit 0171396

Browse files
authored
#6 Merge pull request from a-lab-nagoya/astropenguin/issue5
Update example code
2 parents 927b07a + 4e9ab7e commit 0171396

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

docs/index.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ backgroundImage: url('https://marp.app/assets/hero-background.jpg')
7777
# プログラミング言語Python
7878

7979
```python
80-
import tkinter as tk
81-
from datetime import datetime as dt
80+
import openai
8281

83-
root = tk.Tk()
84-
clock = tk.StringVar()
85-
label = tk.Label(textvariable=clock)
86-
label.pack()
82+
openai.api_key = "*****"
8783

88-
def update():
89-
clock.set(dt.now().strftime('%H:%M:%S'))
90-
root.after(1000, update)
84+
def answer(question: str) -> str:
85+
"""Return an answer of the question by GPT-3.5."""
86+
response = openai.ChatCompletion.create(
87+
model="gpt-3.5-turbo",
88+
messages=[{"role": "user", "content": question}],
89+
)
90+
return response["choices"][0]["message"]["content"]
9191

92-
update()
93-
root.mainloop()
92+
93+
print(answer("Pythonを学ぶには?"))
9494
```
9595

9696
---

0 commit comments

Comments
 (0)