我应该怎么修改上面的代码
时间: 2024-02-06 13:10:28 浏览: 19
;
printf("Enter the index of the question to modify:\n");
scanf("%d", &index);
getchar(); // 吸收多余的换行符
if (index < 1 || index > numQuestions) {
printf("Invalid question index.\你可以将上面的代码改为以下形式:
```python
import openai
openai.api_key = "YOUR_API_KEYn");
return;
}
Question *q = &questions[index - 1];
printf("Enter the new question (or press"
def ask_question(question, model):
prompt = f"{model}: {question}\nAI:"
response = openai.Completion.create Enter to keep the old one):\n");
fgets(q->question, sizeof(q->question), stdin);
printf("Enter the new first(
engine=model,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature= choice (or press Enter to keep the old one):\n");
fgets(q->choices[0], sizeof(q->choices[0]), stdin0.7,
)
answer = response.choices[0].text.strip()
return answer
```
这样就可以调用);
printf("Enter the new second choice (or press Enter to keep the old one):\n");
fgets(q->choices[1], OpenAI 的 API 进行对话了。记得将 `YOUR_API_KEY` 替换成你自己的 API Key。另 sizeof(q->choices[1]), stdin);
printf("Enter the new third choice (or press Enter to keep the old one):\n");
外,由于 OpenAI 的 GPT-3 模型目前需要付费才能使用,所以你需要先注册 OpenAI 并购买相应的服务才能使用该代码。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)