Skip to content

Forum in maintenance, we will back soon 🙂

Building UIs With S...
 
Notifications
Clear all

Building UIs With Streamlit - The Base Template errors

3 Posts
3 Users
3 Reactions
15 Views
Deee
 Deee
(@dfby999)
Posts: 10
Eminent Member Customer Registered
Topic starter
 

Hello,

the function def openAI_generate_text(prompt, model, api_key): provided @ https://learnwithhasan.com/lessons/the-base-template/ is still outdated.

To rectify, first run

pip install --upgrade openai

then replace

completion = openai.ChatCompletion.create(

with

completion = openai.chat.completions.create(

Worked for me.


This aside, @admin Hasan, in the OpenAI migration guide , they mentioned using a new Initialization like the one below:

# old
import openai

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

# new
from openai import OpenAI

client = OpenAI(
  api_key=os.environ['OPENAI_API_KEY'],  # this is also the default, it can be omitted
)

So is it better practice to initial openai in the new way? Or is my understanding lacking? How does this affect calling the api_key in our scripts?

I also believe this part is important? But I cannot fully comprehend yet given my level. 😥 😥 

 

 
Posted : 01/08/2024 4:40 pm
SSAdvisor
(@ssadvisor)
Posts: 1139
Noble Member
 

Posted by: @dfby999

Hello,

the function def openAI_generate_text(prompt, model, api_key): provided @ https://learnwithhasan.com/lessons/the-base-template/ is still outdated.

To rectify, first run

pip install --upgrade openai

then replace

completion = openai.ChatCompletion.create(

with

completion = openai.chat.completions.create(

Worked for me.


This aside, @admin Hasan, in the OpenAI migration guide , they mentioned using a new Initialization like the one below:

# old
import openai

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

# new
from openai import OpenAI

client = OpenAI(
  api_key=os.environ['OPENAI_API_KEY'],  # this is also the default, it can be omitted
)

So is it better practice to initial openai in the new way? Or is my understanding lacking? How does this affect calling the api_key in our scripts?

I also believe this part is important? But I cannot fully comprehend yet given my level. 😥 😥 

-- attachment is not available --

 

 

Or downgrade the openai module to 0.28 like so

pip install --upgrade openai==0.28

this will allow the code to run without changing the code.

Regards,
Earnie Boyd, CEO
Seasoned Solutions Advisor LLC
Schedule 1-on-1 help
Join me on Slack

 
Posted : 01/08/2024 8:51 pm
Hasan Aboul Hasan
(@admin)
Posts: 1276
Member Admin
 

Thanks for your feedback, I will update this code soon.

and yes, I will be also using the new Initialization in my new updates

 
Posted : 01/09/2024 12:08 pm
Share:
[the_ad_group id="312"]