Not able to call the actions from colang file #247
-
Hi, I have a simple example of checking the rag custom action. I have added the config with instruction, sample, self check input. In rails.co I have added below code which very simple. and then in my app.py I have registered actions which i am using. It is very basic stuff, still the custom action is not getting called. I am not able to understand the problem, also the documentation is saying nothing more than what I have done.
@action()
async def retrieve(query: str) -> list:
print(">>> Retrieve Called...")
# create query embedding
vectorstore = FAISS.load_local("store", OpenAIEmbeddings())
res = vectorstore.as_retriever(
search_type="similarity",
search_kwargs={"k": 4, "include_metadata": True})
# get list of retrieved texts
contexts = [x['metadata']['chunk'] for x in res['matches']]
print(contexts)
return contexts
@action()
async def rag(query: str, contexts: list) -> str:
print(">>> RAG Called..")
# we'll add this so we can see when this is being used
context_str = "\n".join(contexts)
# place query and contexts into RAG prompt
prompt = f"""You are a helpful assistant, below is a query from a user and
some relevant contexts. Answer the question given the information in those
contexts. If you cannot find the answer to the question, say "I don't know".
History:
{st.session_state.messages[-5:]['content']}
Contexts:
{context_str}
Query: {query}
Answer: """
# generate answer
res = openai.Completion.create(
engine="gpt-3.5-turbo",
prompt=prompt,
temperature=0.5,
max_tokens=100
)
return res['choices'][0]['text']
# Register Nemo Guard rails
config = RailsConfig.from_path('./config')
# print("Config has registered...")
app = LLMRails(config,llm=get_llm(), verbose=True)
#register actions
app.register_action(action=retrieve, name="retrieve")
app.register_action(action=create_retrivalQa_chain, name="rag")
Could you guys provide the input on same |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Can you also add from nemoguardrails.logging.verbose import set_verbose
set_verbose(True) to your file and share the logs from a run that does not work. On a first glance, it should work. |
Beta Was this translation helpful? Give feedback.
Can you also add
to your file and share the logs from a run that does not work. On a first glance, it should work.