-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notebook "prompt-templates-variables-jinja2" : still uses OpenAI v0 legacy API #3
Comments
Thanks for the heads up!
What I suggest is to add a line at the beginning of this tutorial pip
installing the relevant packages only for this one, and then applying your
changes.
I would love to accept your PR
…On Sun, Dec 15, 2024, 16:55 Knut Behrends ***@***.***> wrote:
I like the elegance of your Notebooks, using Jinja Templates and Langchain
from the very beginning.
However, I noticed that the get_get_completion() function in
all_prompt_engineering_techniques/prompt-templates-variables-jinja2.ipynb
still uses the OpenAI v0 legacy API. The requirements.txt file
installs/demands openai==1.51.1.
So when I run the the class PromptTemplate: ... code cell in that Jupyter
Notebook I get an error.
APIRemovedInV1:
You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.
You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface.
Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`
I replaced the current code cell defining get_get_completion() function
(not reproduced here) with the following code. So I know how to get along.
However I don't know how many Notebooks in this repo will be affected, And
I don't know if you prefer to fix everything yourself with the `openai
migrate' mechanism. That's wh< I'm not sending a pull request.
### my replacement of the `get_get_completion()` function - new openAI v1 interfaceimport osfrom openai import OpenAI from jinja2 import Templatefrom dotenv import load_dotenv
load_dotenv()
def get_completion(prompt, model="gpt-4o-mini"):
''' Get a completion from the OpenAI API Args: prompt (str): The prompt to send to the API model (str): The model to use for the completion Returns: str: The completion text '''
messages = [{"role": "user", "content": prompt}]
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
response = client.chat.completions.create(
model=model,
messages=messages,
temperature=0,
)
return response.choices[0].message.content
—
Reply to this email directly, view it on GitHub
<#3>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGYBJ4NF5U4AZ4MZTHRNJS32FWJ7LAVCNFSM6AAAAABTUTYJ7WVHI2DSMVQWIX3LMV43ASLTON2WKOZSG42DANRYGI3DKNI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like the elegance of your Notebooks, using Jinja Templates and Langchain from the very beginning.
However, I noticed that the
get_get_completion()
function inall_prompt_engineering_techniques/prompt-templates-variables-jinja2.ipynb
still uses the OpenAI v0 legacy API. Therequirements.txt
file installs/demandsopenai==1.51.1
.So when I run the the
class PromptTemplate: ...
code cell in that Jupyter Notebook I get an error.I replaced the current code cell defining
get_get_completion()
function (not reproduced here) with the following code. So I know how to get along. However I don't know how many Notebooks in this repo will be affected, And I don't know if you prefer to fix everything yourself with the `openai migrate' mechanism. That's wh< I'm not sending a pull request.The text was updated successfully, but these errors were encountered: