struct-gpt
struct-gpt copied to clipboard
Update to support OpenAI Python SDK v1.1.1 and JSON mode
I've found this package extremely useful - thanks for putting it together.
OpenAI have released a new version of the Python SDK (openai==1.1.1). This version is incompatible with struct-gpt v2.2.7.
Are there plans of updating compatibility? OpenAI also released a new JSON mode. Could this further enhance performance?
$ pip freeze | grep -E "(openai|struct-gpt)"
openai==1.1.1
struct-gpt==2.2.7
$ cat t.py
from struct_gpt import OpenAiBase
from pydantic import Field
class SentimentSchema(OpenAiBase):
"""
Determine the sentiment of the given text:
{content}
"""
# 👆this becomes the prompt
sentiment: str = Field(description="Either -1, 0, or 1.")
result = SentimentSchema.from_openai(content="I love pizza!").json()
# 👆this ends up in the prompt
print(result)
$ python t.py
AttributeError: module 'openai' has no attribute 'ChatCompletion'
AttributeError: module 'openai' has no attribute 'ChatCompletion'
AttributeError: module 'openai' has no attribute 'ChatCompletion'
Traceback (most recent call last):
File "/home/henrik/gemini-gpt/t.py", line 16, in <module>
result = SentimentSchema.from_openai(content="I love pizza!").json()
File "/home/henrik/.pyenv/versions/3.10.4/lib/python3.10/site-packages/struct_gpt/models.py", line 149, in from_openai
raise last_exception
File "/home/henrik/.pyenv/versions/3.10.4/lib/python3.10/site-packages/struct_gpt/models.py", line 114, in from_openai
content = openai.ChatCompletion.create(
AttributeError: module 'openai' has no attribute 'ChatCompletion'