From a4df943d343f762a1468d27842889ff07860ff4d Mon Sep 17 00:00:00 2001 From: Sparklight Date: Fri, 3 Mar 2023 19:04:42 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20du=20code=20de=20l'API=20et=20du=20mod?= =?UTF-8?q?=C3=A8le=20de=20r=C3=A9ponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SupportPC.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/SupportPC.py b/SupportPC.py index 8f90b86..fa8e06e 100644 --- a/SupportPC.py +++ b/SupportPC.py @@ -1,6 +1,8 @@ import sys import requests import json +import os +import openai from PyQt5.QtWidgets import QApplication, QMainWindow, QGridLayout, QTextEdit, QPushButton, QLineEdit, QWidget @@ -49,6 +51,40 @@ class MainWindow(QMainWindow): endpoint = 'https://api.openai.com/v1/completions' apiKey = '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' + # Load your API key from an environment variable or secret management service + openai.api_key = os.getenv("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") + + response = openai.Completion.create(model="gpt-3.5-turbo", prompt="Say this is a test", temperature=0, max_tokens=7) + + openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "Who won the world series in 2020?"}, + {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."}, + {"role": "user", "content": "Where was it played?"} + ] + ) + + """ + { + 'id': 'chatcmpl-6p9XYPYSTTRi0xEviKjjilqrWU2Ve', + 'object': 'chat.completion', + 'created': 1677649420, + 'model': 'gpt-3.5-turbo', + 'usage': {'prompt_tokens': 56, 'completion_tokens': 31, 'total_tokens': 87}, + 'choices': [ + { + 'message': { + 'role': 'assistant', + 'content': 'The 2020 World Series was played in Arlington, Texas at the Globe Life Field, which was the new home stadium for the Texas Rangers.'}, + 'finish_reason': 'stop', + 'index': 0 + } + ] + } + """ + # Define the request headers (if needed) headers = { "Content-Type": "application/json",