我正在使用AzureOpenAI来测试LangChain使用宪法的自我批评。
\n这一切都有效,除了我得到了多个答案,最奇怪的部分是,它生成随机的、不需要的问题,并回答它们。
\n这是我的 Python 代码(我用 替换了敏感信息[XXX-XXX]):
import os\nfrom langchain.llms import AzureOpenAI\nfrom langchain.prompts import PromptTemplate\nfrom langchain.chains.llm import LLMChain\n\nfrom langchain.chains.constitutional_ai.base import ConstitutionalChain\nfrom langchain.chains.constitutional_ai.models import ConstitutionalPrinciple\n\nos.environ["OPENAI_API_TYPE"] = "azure"\nos.environ["OPENAI_API_VERSION"] = "2023-03-15-preview"\nos.environ["OPENAI_API_BASE"] = "https://[XXX-XXX].openai.azure.com/"\nos.environ["OPENAI_API_KEY"] = "[XXX-XXX]"\n\nqa_prompt = PromptTemplate(\n template="""You are a Microsoft specialist and know everything about the software it sells. Your aim is to help operators and employees when using the software.\n\nQuestion: {question}\n\nAnswer:""",\n input_variables=["question"],\n)\n\nllm = AzureOpenAI(\n deployment_name="[XXX-XXX]",\n model_name="[XXX-XXX]"\n)\n\n\nqa_chain = LLMChain(llm=llm, prompt=qa_prompt)\n\nethical_principle = ConstitutionalPrinciple(\n name="Ethical Principle",\n critique_request="The model should only …Run Code Online (Sandbox Code Playgroud)