11import uuid
22
3- import openai
43import streamlit as st
4+ from openai import OpenAI
55from trubrics_utils import trubrics_config
66
77from trubrics .integrations .streamlit import FeedbackCollector
@@ -78,18 +78,18 @@ def init_trubrics(email, password):
7878 st .info ("Please add your OpenAI API key to continue." )
7979 st .stop ()
8080 else :
81- openai . api_key = openai_api_key
81+ client = OpenAI ( api_key = openai_api_key )
8282
8383 with st .chat_message ("assistant" ):
8484 if stream :
8585 message_placeholder = st .empty ()
8686 generation = ""
87- for response in openai . ChatCompletion .create (model = model , messages = messages , stream = True ):
88- generation += response .choices [0 ].delta .get ( " content" , "" )
87+ for part in client . chat . completions .create (model = model , messages = messages , stream = True ):
88+ generation += part .choices [0 ].delta .content or ""
8989 message_placeholder .markdown (generation + "▌" )
9090 message_placeholder .markdown (generation )
9191 else :
92- response = openai . ChatCompletion .create (model = model , messages = messages )
92+ response = client . chat . completions .create (model = model , messages = messages )
9393 generation = response .choices [0 ].message .content
9494 st .write (generation )
9595
@@ -103,4 +103,4 @@ def init_trubrics(email, password):
103103 )
104104 st .session_state .prompt_ids .append (logged_prompt .id )
105105 messages .append ({"role" : "assistant" , "content" : generation })
106- st .experimental_rerun () # force rerun of app, to load last feedback component
106+ st .rerun () # force rerun of app, to load last feedback component
0 commit comments