Pythonista-Issues icon indicating copy to clipboard operation
Pythonista-Issues copied to clipboard

Access to OpenAI’s GPT4 not working

Open rafiyoeliaero opened this issue 1 year ago • 11 comments
trafficstars

I’m trying to hook onto GPT4 (of course I have an openAI key). A friend sent me the access code below but Pythonista does not seem to support (I get an error) on the second line ‘from openai import OpenAI’ . Any workarounds? import openai
from openai import OpenAI client = OpenAI(api_key="YOUR_KEY_HERE") def chat():
prompt = input('Please write your prompt here\n')
completion = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "user", "content": prompt}
]
)
return(print(completion.choices[0].message.content)) def main():
chat() if name == "main":
main()

please send copy of reply to: [email protected] (for some reason the OMZ forum doesn’t let me post this)

rafiyoeliaero avatar Jan 31 '24 06:01 rafiyoeliaero

Typo correction on the above: here’s the script (the error appears on: ‘
from openai import OpenAI‘) import openai 
from openai import OpenAI client = OpenAI(api_key="YOUR_KEY_HERE") def chat():
prompt = input('Please write your prompt here\n')
completion = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "user", "content": prompt}
]
)
return(print(completion.choices[0].message.content)) def main():
chat() if name == "main":
main()

rafiyoeliaero avatar Jan 31 '24 06:01 rafiyoeliaero

I get an error

What is the error???? When asking questions about software that involve error messages, please always include the full error messages, always. Otherwise people won't be able to help because it's unclear what exactly is wrong with the code. Another important thing is to format you code properly. Reading the messy code you posted is infuriating. People are going to get mad and skip your question instead of answering.

ForceBru avatar Feb 06 '24 21:02 ForceBru

Thanks for replying, here is a screenshot Regards,RafiRafi Yoeli, PhD.24 Dubnov StreetTel-Aviv 6495701, Israel Cell: +972-54-4446993E-mail: @.: www.linkedin.com/in/Rafi-YoeliThis e-mail message (including any accompanying attachments) is proprietary to Dr. Rafi Yoeli. If you receive this communication in error, please notify the sender immediately and delete it from your computer. Thank you.Sent from my iPadOn Feb 6, 2024, at 23:30, ForceBru @.> wrote:

I get an error

What is the error???? When asking questions about software that involve error messages, please always include the full error messages, always. Otherwise people won't be able to help because it's unclear what exactly is wrong with the code. Another important thing is to format you code properly. Reading the messy code you posted is infuriating. People are going to get mad and skip your question instead of answering.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

rafiyoeliaero avatar Feb 07 '24 05:02 rafiyoeliaero

Here’s the screenshot: Pythonista GPT4 error

rafiyoeliaero avatar Feb 10 '24 14:02 rafiyoeliaero

Thanks. But a code I have that is an API for GPT 3.5-turbo has no problem, imports OpenAI right away with no special tricks in Pythonista, looks like this (I use it all the time):import openaidef chat(prompt): openai.api_key = "... key name ..." completion = openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=[{"role": "user", "content": prompt}]) print(completion.choices[0].message["content"])   def main(): statement = "... prompt ..." prompt = ("..." + str(statement) + " ...") chat(prompt)if name == "main": main()Rafi Yoeli, PhD.24 Dubnov StreetTel-Aviv 6495701, Israel Cell: +972-54-4446993E-mail: @.: www.linkedin.com/in/Rafi-YoeliThis e-mail message (including any accompanying attachments) is proprietary to Dr. Rafi Yoeli. If you receive this communication in error, please notify the sender immediately and delete it from your computer. Thank you.Sent from my iPadOn Feb 10, 2024, at 16:21, Christian Clauss @.> wrote: openai is not a Pythonista built-in module.

https://omz-software.com/pythonista/docs-3.4/py3/ios/third-party-modules.html

pip install openai would be required after setting up StaSH but even then, it may not work.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

rafiyoeliaero avatar Feb 10 '24 18:02 rafiyoeliaero

Thank you! Question: where does GPT4 enter the picture (see my previous note)?RafiRafi Yoeli, PhD.24 Dubnov StreetTel-Aviv 6495701, Israel Cell: +972-54-4446993E-mail: @.: www.linkedin.com/in/Rafi-YoeliThis e-mail message (including any accompanying attachments) is proprietary to Dr. Rafi Yoeli. If you receive this communication in error, please notify the sender immediately and delete it from your computer. Thank you.Sent from my iPadOn Feb 10, 2024, at 16:36, Christian Clauss @.> wrote: import openai dir(openai)

from pathlib import Path print(Path(openai.file).read_text())

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

rafiyoeliaero avatar Feb 10 '24 18:02 rafiyoeliaero

openai is not a Pythonista built-in module

Well that's confusing.

App documentation: image

Website documentation: image

TFWol avatar Mar 02 '24 00:03 TFWol

Try this:

import openai


openai.api_key = "YOUR_API_KEY_HERE"


def chat():
    prompt = input("Please write your prompt here\n")
    completion = openai.ChatCompletion.create(
        model="gpt-4", messages=[{"role": "user", "content": prompt}]
    )
    return print(completion.choices[0].message.content)


def main():
    chat()


if __name__ == "__main__":
    main()

ChelsWin avatar Mar 09 '24 03:03 ChelsWin

Thanks! It seems to work technically but here’s my first question:

are you GPT4? No, I am not GPT4. I am an AI model created by OpenAI known as GPT-3. As of this conversation, a GPT-4 model does not exist.

Then I tried this (wanted to see if I’ll at least get Bard if not Gemini as an answer:

what is the name of Googe's Large Language Model that competes with OpenAI’s one? Google's Large Language Model that competes with OpenAI’s model is called LaMDA.

So what do you think? I think I’m still on GPT-3 . Any further ideas?

rafiyoeliaero avatar Mar 09 '24 09:03 rafiyoeliaero

I just looked into it a bit and apparently it is normal for it to say that because of the data it has been trained on. The web GPT-4 doesn't say it, but the API does.

To answer your second question about not recognising Bard or Gemini, it will not recognise them because the dataset used is cut off at 2021 according to the link below.

You can read more about it here: https://community.openai.com/t/gpt-4-through-api-says-its-gpt-3/286881

ChelsWin avatar Mar 09 '24 19:03 ChelsWin

Excellent. Thank you!

rafiyoeliaero avatar Mar 10 '24 05:03 rafiyoeliaero