Adding moderation | ü¶úÔ∏èüîó Langchain






Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookPrompt + LLMRAGMultiple chainsQuerying a SQL DBAgentsCode writingAdding memoryAdding moderationUsing toolsLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreLangChain Expression LanguageCookbookAdding moderationAdding moderationThis shows how to add in moderation (or other safeguards) around your LLM application.from langchain.chains import OpenAIModerationChainfrom langchain.llms import OpenAIfrom langchain.prompts import ChatPromptTemplatemoderate = OpenAIModerationChain()model = OpenAI()prompt = ChatPromptTemplate.from_messages([    ("system", "repeat after me: {input}")])chain = prompt | modelchain.invoke({"input": "you are stupid"})    '\n\nYou are stupid.'moderated_chain = chain | moderatemoderated_chain.invoke({"input": "you are stupid"})    {'input': '\n\nYou are stupid',     'output': "Text was found that violates OpenAI's content policy."}PreviousAdding memoryNextUsing toolsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
This shows how to add in moderation (or other safeguards) around your LLM application.
This shows how to add in moderation (or other safeguards) around your LLM application. ->: Adding moderation | ü¶úÔ∏èüîó Langchain






Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookPrompt + LLMRAGMultiple chainsQuerying a SQL DBAgentsCode writingAdding memoryAdding moderationUsing toolsLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreLangChain Expression LanguageCookbookAdding moderationAdding moderationThis shows how to add in moderation (or other safeguards) around your LLM application.from langchain.chains import OpenAIModerationChainfrom langchain.llms import OpenAIfrom langchain.prompts import ChatPromptTemplatemoderate = OpenAIModerationChain()model = OpenAI()prompt = ChatPromptTemplate.from_messages([    ("system", "repeat after me: {input}")])chain = prompt | modelchain.invoke({"input": "you are stupid"})    '\n\nYou are stupid.'moderated_chain = chain | moderatemoderated_chain.invoke({"input": "you are stupid"})    {'input': '\n\nYou are stupid',     'output': "Text was found that violates OpenAI's content policy."}PreviousAdding memoryNextUsing toolsCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.