Skip to content

Commit

Permalink
Merge pull request #83 from haesleinhuepf/openai_1.2.0_api_migration
Browse files Browse the repository at this point in the history
update to OpenAI API > 1.2.0
  • Loading branch information
haesleinhuepf authored Nov 13, 2023
2 parents e4a984a + ed211e0 commit 89fb87a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ project_urls =
packages = find:
install_requires =
numpy
openai
openai>=1.2.0
ipython

python_requires = >=3.8
Expand Down
18 changes: 11 additions & 7 deletions src/bia_bob/_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def generate_response_from_openai(model: str, system_prompt: str, user_prompt: s
"""A prompt helper function that sends a message to openAI
and returns only the text response.
"""
import openai
from openai import OpenAI
from ._machinery import Context

# assemble prompt
Expand All @@ -181,14 +181,17 @@ def generate_response_from_openai(model: str, system_prompt: str, user_prompt: s
# if it is not provided, the response will be
# cropped to half a sentence
kwargs['max_tokens'] = 3000


# init client
client = OpenAI()

# retrieve answer
response = openai.ChatCompletion.create(
response = client.chat.completions.create(
messages=system_message + chat_history + image_message + user_message,
model=model,
**kwargs
) # stream=True would be nice
reply = response['choices'][0]['message']['content']
reply = response.choices[0].message.content

# store question and answer in chat history
assistant_message = [{"role": "assistant", "content": reply}]
Expand Down Expand Up @@ -220,9 +223,10 @@ def is_image(potential_image):

def available_models():
"""Returns a list of available model names in openAI."""
import openai
models = openai.Model.list()
return sorted([model['id'] for model in models['data']])
from openai import OpenAI
client = OpenAI()
models = client.models.list()
return sorted([model.id for model in models.data])


def keep_available_packages(libraries):
Expand Down

0 comments on commit 89fb87a

Please sign in to comment.