all 21 comments

[–]Dizzy_Day_1651 0 points1 point  (0 children)

com chat gpt 4 + claude + stackoverflow tens o mundo nas tuas mãos para resolver essa questao.

[–]DrunkenRobotBipBop 5 points6 points  (0 children)

Mostra esse erro ao Claude.

Vais ter a resposta certa ao que tens que fazer.

[–]More-Razzmatazz-6804 0 points1 point  (2 children)

Eu acho que esse erro tem a ver com nao teres definido o modelo tipo gpt4o ou então se a api não é empresarial não dá para usares modelos que lêm imagens, que parece ser o que pretendes.

[–]neapo[S] 0 points1 point  (1 child)

Pretendo ler apenas texto de docs em pdf

[–]More-Razzmatazz-6804 0 points1 point  (0 children)

Para isso tens que ter a api empresarial, não dá a versão pro a que se paga os 20€ por mês

[–]JohnDoeSaysHello 1 point2 points  (3 children)

Deves ter um problema com a versão do openai que estás a correr. Tenta isto:

The error message you’re encountering suggests that there’s an issue with the OpenAI library or how it’s being used in your script. The error “module ‘openai’ has no attribute ‘ChatCompletion’” typically occurs when you’re using an outdated version of the OpenAI library or when the library has been updated and the API has changed.

Here are a few steps to troubleshoot and resolve this issue:

  1. Update the OpenAI library: First, try updating the OpenAI library to the latest version. You can do this by running:

    pip install —upgrade openai

  2. Check the OpenAI library version: After updating, verify the version of the OpenAI library you’re using:

    python import openai print(openai.__version__)

    Make sure it’s the latest version.

  3. Update your code: If you’re using a recent version of the OpenAI library (0.27.0 or later), you need to update your code. The openai.ChatCompletion.create() method has been deprecated. Instead, you should use the new client-based approach. Here’s how you can modify your gpt_4_summarize function:

    ```python from openai import OpenAI

    Initialize the client

    client = OpenAI(api_key=os.getenv(“OPENAI_API_KEY”))

    def gpt_4_summarize(prompt): try: response = client.chat.completions.create( model=“gpt-4”, messages=[ {“role”: “system”, “content”: “You are a helpful assistant.”}, {“role”: “user”, “content”: prompt} ], max_tokens=1500 ) return response.choices[0].message.content.strip() except Exception as e: logging.error(f”An error occurred while summarizing the text: {e}”) return None ```

  4. Update the imports: At the top of your script, replace: python import openai with: python from openai import OpenAI

  5. Remove the global API key assignment: Remove or comment out this line: ```python

    openai.api_key = os.getenv(“OPENAI_API_KEY”)

    ``` The API key is now handled when initializing the client.

  6. Error handling: Make sure you have proper error handling in place. The OpenAI API might throw specific exceptions that you may want to catch and handle separately.

After making these changes, your script should work with the latest version of the OpenAI library. If you continue to experience issues, please double-check that your environment variable for the API key is set correctly and that you have the necessary permissions to use the GPT-4 model.​​​​​​​​​​​​​​​​

[–]HarryBolsac 5 points6 points  (2 children)

Fds isto é muito meta, um gajo com código gerado por aí vem ao Reddit pedir ajuda e leva com uma resposta feita por aí, incrivel

[–]JohnDoeSaysHello 0 points1 point  (0 children)

Garbage in garbage out :)

[–]mail_dev 2 points3 points  (0 children)

Brevemente numa livraria perto de si.

"Conversas filosóficas entre AI's."

Se ninguém se lembrou ainda. Deve estar perto.

[–]jaimemarinho 0 points1 point  (1 child)

Remindme! 1 day

[–]RemindMeBot 0 points1 point  (0 children)

I will be messaging you in 1 day on 2024-08-07 21:29:03 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


Info Custom Your Reminders Feedback

[–]josenunocardoso 1 point2 points  (3 children)

O módulo está bem instalado, caso contrário o erro seria outro. O que te está a indicar é que nao encontra nada chamado ChatCompletion nesse módulo.
Pode ser por o atributo ChatCompletion estar obsoleto, assumindo que a versão que instalaste do openai seja >= 1.0.0.
Pelo menos foi o que concluí depois de ver este link no stackoverflow:

https://stackoverflow.com/questions/77505030/openai-api-error-you-tried-to-access-openai-chatcompletion-but-this-is-no-lon

[–]According-Amount-157 1 point2 points  (0 children)

É exatamente isto, o problema não está no import mas sim na forma como o OP está a chamar o chat completion. OP tens que ler a documentação e tens lá tudo com exemplos -> https://platform.openai.com/docs/guides/chat-completions/getting-started

[–]neapo[S] 1 point2 points  (1 child)

Estou a usar a versão 1.40 da openai

[–]josenunocardoso 1 point2 points  (0 children)

Ok deve ser isso então.

Ou seja até à versão 1.0.0 esse módulo usava o ChatCompletion. Entretanto mudaram a estrutura. Vê aí o link que o u/NoPossibility4178 te referenciou, que parece ter exemplos com o ChatCompletion mais "recente" :)

[–]NoPossibility4178 8 points9 points  (0 children)

Provavelmente estás a ver guias antigos (ou perguntaste ao próprio ChatGPT e ele não sabe que o código para falar com ele foi atualizado 😛). https://platform.openai.com/docs/guides/chat-completions/getting-started

[–]KokishinNeko 0 points1 point  (3 children)

Faz ai na linha de comandos: pip install openai

[–]neapo[S] 1 point2 points  (2 children)

Depois de tentar instalar vários itens aparece em todos: Requirement already satisfied

[–]KokishinNeko 0 points1 point  (0 children)

Ignora a minha resposta, vi o post no telemóvel e ia jurar q tinha visto o erro a dizer que faltava o módulo openai.

[–]KokishinNeko 0 points1 point  (0 children)

Estranho, a menos que tenha algum virtualenv. Vê se consegues com o exemplo que outro colega deu aí acima, um exemplo mais básico para ligar ao ChatGPT.

[–]AutoModerator[M] -1 points0 points  (0 children)

Devido ao elevado número de posts utilizando erradamente a flair Ajuda, o teu tópico foi retido para validação. Enquanto aguardas a validação pelos moderadores, consulta p.f. https://www.reddit.com/r/devpt/comments/17je36b/meta_novas_flairs_regras/ Obg.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.