Comments (11)
Hey, I found a workaround for this. It can be solved using LangChain in the Python API. You can define your LLM in LangChain using the Azure Chat OpenAI object and pass that as an argument to the LLMRails class.
For example,
from langchain.chat_models import AzureChatOpenAI
llm = AzureChatOpenAI(<your-parameters-here>)
from nemoguardrails import LLMRails, RailsConfig
config = RailsConfig.from_path("path/to/config")
app = LLMRails(config, llm=llm)
new_message = app.generate(messages=[{
"role": "user",
"content": "Hello! What can you do for me?"
}])
An additional error I was noticing here is that app.generate kept telling me that I can't run synchronous calls inside async code, not really sure why. I got it running by replacing app.generate with app.generate_async but that's probably not the best way to solve this problem.
from nemo-guardrails.
Ok, I think I'm starting to understand the issue. Can't test, so bear with me. Can you try adding the following:
app = LLMRails(config=config, llm=chat_model)
app.runtime.register_action_param("llm", chat_model)
from nemo-guardrails.
@tanujjain @chilicrabcakes facing a similar issue while trying to work with guardrails .
Parameter temperature does not exist for NoneType
Error 'NoneType' object has no attribute 'agenerate_prompt' while execution check_jailbreak
Traceback (most recent call last):
File "C:\Python311\Lib\site-packages\nemoguardrails\actions\action_dispatcher.py", line 125, in execute_action
result = await fn(**params)
^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\nemoguardrails\actions\jailbreak_check.py", line 50, in check_jailbreak
check = await llm_call(llm, prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\nemoguardrails\actions\llm\utils.py", line 31, in llm_call
result = await llm.agenerate_prompt(
Any suggestions ,have you faced this issue
from nemo-guardrails.
Hi @drazvan i am try in to use the following config to connect to azure open ai-
chat_model = AzureChatOpenAI(
openai_api_type="azure",
openai_api_version="2023-03-15-preview",
openai_api_key=azure_openai_key,
deployment_name=azure_openai_model,
openai_api_base=azure_openai_endpoint
)
app = LLMRails(config=config, llm=chat_model)
new_message = app.generate(messages=[{
"role": "user",
"content": "What's the latest fashion trend?"
}])
i hope currently guradrails supports azure open ai ,pls let me know
from nemo-guardrails.
@ansumanparija007 : looks like llm
is set to None
in your case. Can you provide more details on the config?
from nemo-guardrails.
any luck with this @drazvan ?
from nemo-guardrails.
I can't test this directly as I don't have an Azure Key. Can you confirm the chat_model
instance works correctly? i.e. completion = chat_model("some text")
. And if it does, can you share the complete error stack trace? Thanks.
from nemo-guardrails.
Yeah chat_model works fine .but while working with guardrails following error is thrown -
Parameter temperature does not exist for NoneType
Error 'NoneType' object has no attribute 'agenerate_prompt' while execution check_jailbreak
Traceback (most recent call last):
File "C:\Users\testcopilot2\guardrails\chatbot-guardrails\env\Lib\site-packages\nemoguardrails\actions\action_dispatcher.py", line 125, in execute_action
result = await fn(**params)
^^^^^^^^^^^^^^^^^^
File "C:\Users\testcopilot2\guardrails\chatbot-guardrails\env\Lib\site-packages\nemoguardrails\actions\jailbreak_check.py", line 50, in check_jailbreak
check = await llm_call(llm, prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\testcopilot2\guardrails\chatbot-guardrails\env\Lib\site-packages\nemoguardrails\actions\llm\utils.py", line 31, in llm_call
result = await llm.agenerate_prompt(
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'agenerate_prompt'
new_message: {'role': 'assistant', 'content': "I'm sorry, an internal error has occurred."}
from nemo-guardrails.
thanks @drazvan this error is gone.ll try to play with it and let you know ..
from nemo-guardrails.
Hi @drazvan while running hallucination cheack it says Hallucination rail can only be used with OpenAI LLM engines.Current LLM engine is AzureChatOpenAI. Any ETA when it will be supported for other LLM models?
from nemo-guardrails.
Hi @drazvan @ansumanparija007 @tanujjain I believe we can help with this issue. Iβm the maintainer of LiteLLM https://github.com/BerriAI/litellm
TLDR:
We allow you to use any LLM as a drop in replacement for gpt-3.5-turbo
.
If you don't have access to the LLM you can use the LiteLLM proxy to make requests to the LLM
You can use LiteLLM in the following ways:
With your own API KEY:
This calls the provider API directly
from litellm import completion
import os
## set ENV variables
os.environ["OPENAI_API_KEY"] = "your-key" #
os.environ["COHERE_API_KEY"] = "your-key" #
messages = [{ "content": "Hello, how are you?","role": "user"}]
# openai call
response = completion(model="gpt-3.5-turbo", messages=messages)
# cohere call
response = completion(model="command-nightly", messages=messages)
Using the LiteLLM Proxy with a LiteLLM Key
this is great if you donβt have access to claude but want to use the open source LiteLLM proxy to access claude
from litellm import completion
import os
## set ENV variables
os.environ["OPENAI_API_KEY"] = "sk-litellm-5b46387675a944d2" # [OPTIONAL] replace with your openai key
os.environ["COHERE_API_KEY"] = "sk-litellm-5b46387675a944d2" # [OPTIONAL] replace with your cohere key
messages = [{ "content": "Hello, how are you?","role": "user"}]
# openai call
response = completion(model="gpt-3.5-turbo", messages=messages)
# cohere call
response = completion(model="command-nightly", messages=messages)
from nemo-guardrails.
Related Issues (20)
- Issue while trying to use HOT 1
- [BUG] colang content causing streaming issues HOT 5
- [BUG] LLMGenerationActions.generate_value() fails if the value is not a number HOT 4
- The message "yes" is blocked by the input rail. HOT 2
- Installation issue on mac m1 HOT 4
- Support for KB/Retrieval rails without dialog rails
- [DEP_ISSUE] issue with sentence-transformers, huggingface_hub => fastembed HOT 2
- RAG Example doesn't work with guardrails, not using the knowledge base. HOT 4
- Error : Organization has been restricted HOT 1
- ValueError: Invalid embedding engine: SentenceTransformer HOT 7
- Off topic rail accuracy improvement HOT 1
- Error while execution generate_user_intent: 'NoneType' object has no attribute 'agenerate_prompt'
- What are the options to use NeMo Guardrails with Agents until Agent support is added?
- Error in `VerboseHandler` when `::` present in log messages but not ` :: `. HOT 1
- Unable to install any version > 0.7.0 of nemoguardrails using pipenv install nemoguardrails HOT 1
- Error when using Flask, Gemini models(gemini-1.5-pro-001), and NemoGuardRails integrated with each other. HOT 4
- Error evaluating '$generation_options.rails.input': Attribute 'rails' does not exist in expression 'var_generation_options.rails.input' HOT 1
- passing in relevant_chunks as a message's context HOT 1
- Compatibility with LangChain's invoke() HOT 2
- Issue with streaming with Ollama HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nemo-guardrails.