< >
Home » ollama大模型框架入门教程 » ollama大模型框架入门教程-Python访问API接口

ollama大模型框架入门教程-Python访问API接口

说明

  • 我们利用pytho访问ollama的api接口

python的API接口

pip3 install ollama 
  • 测试代码
import ollama
response = ollama.chat(model='llama3', messages=[
  {
    'role': 'user',
    'content': 'Why is the sky blue?',
  },
])
print(response['message']['content'])
  • 保持代码到一个文件ollama-api.py
  • 执行代码
python3 ollama-api.py
  • 效果
$ python3 ollama-api.py 
The short answer: The sky appears blue because of a phenomenon called scattering, where shorter (blue) wavelengths of light are scattered more than longer (red) wavelengths by tiny molecules of gases in the Earth's atmosphere.

Here's a more detailed explanation:

1. **Sunlight**: When sunlight enters the Earth's atmosphere, it contains all the colors of the visible spectrum (red, orange, yellow, green, blue, indigo, and violet).
2. **Scattering**: As this light travels through the atmosphere, it encounters tiny molecules of gases like nitrogen (N2) and oxygen (O2). These molecules are much smaller than the wavelength of light, so they scatter the shorter wavelengths more efficiently.
3. **Blue dominance**: The blue wavelengths (~450-495 nanometers) are scattered in all directions by these gas molecules, while the longer wavelengths (like red and orange) continue to travel in a more direct path to our eyes.
4. **Atmospheric absorption**: As light travels through the atmosphere, it also encounters tiny particles like water vapor, aerosols, and pollutants. These particles absorb certain wavelengths of light, which can affect the apparent color of the sky.
5. **Angle of the sun**: The angle at which the sun's rays hit the Earth's surface also plays a role in the blue color we see. When the sun is overhead (at its highest point), the light has to travel through more of the atmosphere, which scatters the shorter wavelengths even more. This makes the sky appear bluer.
6. **Atmospheric conditions**: The color of the sky can be influenced by various atmospheric conditions, such as:
    * Dust and pollutants in the air, which can scatter light in different ways and change its apparent color.
    * Water vapor, which can absorb or reflect certain wavelengths of light.
    * Clouds and fog, which can add their own scattering effects to the sky's color.

So, to summarize: The blue color of the sky is primarily due to the scattering of shorter (blue) wavelengths by tiny molecules in the atmosphere. This phenomenon is influenced by various atmospheric conditions, but it's the main reason why the sky often appears blue during daytime hours.

演示视频

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: ollama大模型框架入门教程