Environnement : macos/thonny
Мой код:
Код: Выделить всё
import pandas as pd
# Configure OpenAI API key
from openai import OpenAI
client = OpenAI()
openai.api_key = 'my secret key openai'
# Prompt user for 2 questions
questions = []
for i in range(2):
question = input("Posez une question: ")
questions.append(question)
# Use OpenAI to answer questions
answers = []
for question in questions:
response = client.Completions.create(
engine="gpt-3.5-turbo-instruct",
prompt=f"Question: {question}\nRéponse:",
max_tokens=1024,
n=1,
stop=None,
temperature=0.7,
)
answer = response.choices[0].text.strip()
answers.append(answer)
# Create a pandas dataframe with questions and answers
df = pd.DataFrame({"Question": questions, "Réponse": answers})
# Export dataframe to CSV file
df.to_csv("questions_reponses.csv", index=False)
print("Le fichier CSV a été créé avec succès.")`
замечание в ответе < /h4>
Я обращаюсь к ответчику здесь. Что касается правил обмена стека, я должен сделать это в вопросе. = "Lang-Py PrettyPrint-Override">
Код: Выделить всё
import pandas as pd
# Configure OpenAI API key
import os
from openai import OpenAI
client = OpenAI()
OpenAI.api_key = os.getenv('OPENAI_API_KEY')
# Prompt user for 5 questions
questions = []
for i in range(1):
question = input("Posez une question: ")
questions.append(question)
# Use OpenAI to answer questions
answers = []
for question in questions:
response = client.Completions.create(
engine="gpt-3.5-turbo-instruct",
prompt=f"Question: {question}\nRéponse:",
max_tokens=1024,
n=1,
stop=None,
temperature=0.7,
)
answer = response.choices[0].text.strip()
answers.append(answer)
# Create a pandas dataframe with questions and answers
df = pd.DataFrame({"Question": questions, "Réponse": answers})
# Export dataframe to CSV file
df.to_csv("questions_reponses.csv", index=False)
print("Le fichier CSV a été créé avec succès.")
< /code>
Я только что попробовал опцию 2, то же сообщение об ошибке: < /p>
import pandas as pd
# Configure OpenAI API key
from openai import OpenAI
client = OpenAI()
OpenAI.api_key = "sk-xxxxxxxxxxxxxx"
# Prompt user for 5 questions
questions = []
for i in range(1):
question = input("Posez une question: ")
questions.append(question)
# Use OpenAI to answer questions
answers = []
for question in questions:
response = client.Completions.create(
engine="gpt-3.5-turbo-instruct",
prompt=f"Question: {question}\nRéponse:",
max_tokens=1024,
n=1,
stop=None,
temperature=0.7,
)
answer = response.choices[0].text.strip()
answers.append(answer)
# Create a pandas dataframe with questions and answers
df = pd.DataFrame({"Question": questions, "Réponse": answers})
# Export dataframe to CSV file
df.to_csv("questions_reponses.csv", index=False)
print("Le fichier CSV a été créé avec succès.")
Подробнее здесь: https://stackoverflow.com/questions/778 ... sing-api-k