大网站都开放自己的cms系统,东莞市智通人才市场最新招聘信息,如何做单位网站,昆明网站这里写目录标题 问题记录1、库的版本问题 实例记录1、公司名生成2 提示模板的使用3LLM Chain 参考资料 问题记录
1、库的版本问题
openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(hostapi.openai.com, port443): Max retries excee… 这里写目录标题 问题记录1、库的版本问题 实例记录1、公司名生成2 提示模板的使用3LLM Chain 参考资料 问题记录
1、库的版本问题
openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(hostapi.openai.com, port443): Max retries exceeded with url: /v1/completions (Caused by SSLError(SSLEOFError(8, EOF occurred in violation of protocol (_ssl.c:1129))))解决办法
降低urllib3的版本 1.25.11pip install urllib31.25.11实例记录
1、公司名生成
# 来源于LangChain中文网
#-*- coding:utf-8 -*-
# 实例1构建一个基于公司产品生成公司名称的服务
import os
os.environ[OPENAI_API_KEY] ……
from langchain.llms import OpenAIllm OpenAI(temperature0.9)
text What would be a good company name for a company that makes colorful socks?
print(llm(text))# 输出Rainbow Rascals Socks.
我的第一个调用实例感觉还是很神奇的 “temperature” OpenAI的API有效载荷中temperature选项是一个控制语言模型输出的随机性或创造性的参数。当使用语言模型生成文本时它通常会输出根据输入和先前训练数据确定为最可能的单词或词序列。然而增加输出的随机性可以帮助模型创建更具创意和有趣的输出。temperature选项实际上控制着随机性的程度。将温度设置为较低的值将导致输出更可预测和重复而较高的温度会导致更多种类和不可预测的输出。例如将温度设置为0.5将导致较保守的输出而温度为1将创建更富创意和自发的输出。需要注意的是理想的温度值将取决于具体的任务和上下文因此可能需要一些实验来找到适合您需要的正确值。 2 提示模板的使用
# 实例2提示模板的使用
prompt PromptTemplate(input_variables[product],templateWhat is a good name for a company that makes {product}?,
)
print(prompt.format(productcolorful socks))# 输出What is a good name for a company that makes colorful socks?3LLM Chain
# 实例3在多步骤的工作流中组合 LLM 和提示
import os
os.environ[OPENAI_API_KEY] ……
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChainllm OpenAI(temperature0.9)prompt PromptTemplate(input_variables[product],templateWhat is a good name for a company that makes {product}?,
)chain LLMChain(llmllm, promptprompt)print(chain.run(colorful socks))# 输出Sock Pop!参考资料
1、LangChain中文网 2、python 关于Caused by SSLError(SSLEOFError(8, ‘EOF occurred in violation of protocol (_ssl.c:1131)‘)