python 玩转 chatgpt
时间: 2023-09-11 20:10:47 浏览: 162
chatgpt开源项目,无需调用AIP接口,不需要联网即可运行的chatgpt,里面代码完整,有word操作手册,可做毕业设计
要在Python中玩转ChatGPT,你可以使用OpenAI API进行交互。以下是一段示例代码,演示如何调用OpenAI API来实现与ChatGPT的交互:
```python
import openai
# 设置API Key
openai.api_key = "your_api_key"
# 设置请求参数
model_engine = "text-davinci-002"
prompt = "如何用Python玩转ChatGPT"
completions = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
# 获取ChatGPT的回复
message = completions.choices<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [用 ChatGPT 运行 Python](https://blog.csdn.net/weixin_56659172/article/details/128478808)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [如何用Python玩转ChatGPT?看这篇就够了](https://blog.csdn.net/m0_66958971/article/details/130294122)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文