试用Google Colaboratory 执行python 试跑LangChain

LangChain访问地址:https://learn.activeloop.ai/courses/langchain

什么是 Colab?

借助 Colaboratory(简称 Colab),您可在浏览器中编写和执行 Python 代码,并且:

  • 无需任何配置
  • 免费使用 GPU
  • 轻松共享

无论您是一名学生数据科学家还是 AI 研究员,Colab 都能够帮助您更轻松地完成工作。

在Colab上如何安装模块?

# 例如安装openai
!pip install openai

注意,切记安装模块时,需要带上【!】.

【1】安装langchain

!pip install langchain

【2】安装openai

!pip install openai

环境准备好后,试跑程序:

from langchain.llms import OpenAI
API_KEY = "your Openai key"

# Before executing the following code, make sure to have
# your OpenAI key saved in the “OPENAI_API_KEY” environment variable.
llm = OpenAI(model="text-davinci-003", temperature=0.9,openai_api_key=API_KEY)

'''
export OPENAI_API_KEY="..."

'''

text = "Suggest a personalized workout routine for someone looking to improve cardiovascular endurance and prefers outdoor activities."
print(llm(text))

注意:

# Before executing the following code, make sure to have

# your OpenAI key saved in the “OPENAI_API_KEY” environment variable.

如果是使用了环境变量,export OPENAI_API_KEY="..."

则:

llm = OpenAI(model="text-davinci-003", temperature=0.9)

运行结果:



1. Swimming - Swimming is an excellent low-impact exercise that is perfect for improving cardiovascular endurance. It can be done outdoors at a local lake, pool, or beach.

2. Running - Running is a great way to improve cardiovascular endurance, and it can be done outdoors in a variety of terrain, ranging from asphalt to trails to beach sand.

3. Biking - Biking can be done indoors on a stationary bike, or it can be done outdoors for a change of scenery. It is a great way to improve cardiovascular endurance, while also exploring your local area.

4. Hiking - Hiking is a great low-impact way to improve cardiovascular endurance, while also taking in the beauty of nature. Hikes can be done on trails or up mountains, depending on the individual's preference.

5. Kayaking - Kayaking is a great way to improve cardiovascular endurance while exploring lakes or rivers. It is an excellent full-body workout and it can be done outdoors with the group or solo.

6. Rowing - Rowing is a great way to improve aerobic endurance and it is often done outdoors on a lake or ocean. Rowing is a great full-body workout and it can be

猜你喜欢

转载自blog.csdn.net/qq_23938507/article/details/131321806