Skip to content

Commit

Permalink
update tutorial with API changes (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
brysonjones authored Dec 6, 2023
1 parent 10dc053 commit 420650f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions docs/tutorial/final-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ def chat1() -> rx.Component:
def show_code_using_the_api():
# state.py
import os
import openai
from openai import OpenAI

openai.api_key = os.environ["OPENAI_API_KEY"]

...

def answer(self):
# Our chatbot has some brains now!
session = openai.ChatCompletion.create(
client = OpenAI()
session = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": self.question}
Expand All @@ -64,6 +65,9 @@ def show_code_using_the_api():

for item in session:
if hasattr(item.choices[0].delta, "content"):
if item.choices[0].delta.content is None:
# presence of 'None' indicates the end of the response
break
answer += item.choices[0].delta.content
self.chat_history[-1] = (self.chat_history[-1][0], answer)
yield
Expand Down Expand Up @@ -172,7 +176,8 @@ def show_final_state():

def answer(self):
# Our chatbot has some brains now!
session = openai.ChatCompletion.create(
client = OpenAI()
session = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": self.question}
Expand All @@ -193,6 +198,9 @@ def show_final_state():

for item in session:
if hasattr(item.choices[0].delta, "content"):
if item.choices[0].delta.content is None:
# presence of 'None' indicates the end of the response
break
answer += item.choices[0].delta.content
self.chat_history[-1] = (self.chat_history[-1][0], answer)
yield
Expand Down

0 comments on commit 420650f

Please sign in to comment.