NeMo-Guardrails icon indicating copy to clipboard operation
NeMo-Guardrails copied to clipboard

Bot responding with answer when Using VertexAI but not returning answer

Open Komal-99 opened this issue 1 year ago • 0 comments

I have Tries using llama2 retrival chain with Neoguardrails but didn't work so I added vertexai as a main model in config.yml seems like it is not considering my llm chain not and using VertexAi to generate Answer

But ques is Answer is generated and displayed in Logs but not Bot Returning None Also How I can stop printing all logs everytime whole logs are printed for Neoguardrails my code

MODEL_TYPE=GPT4All
MODEL_PATH=r'C:\Users\komal\Desktop\mages\chatbot\llama-2-7b-chat.Q3_K_M.gguf'
MODEL_N_CTX=1000
MODEL_N_BATCH=8
TARGET_SOURCE_CHUNKS=4
llm = LlamaCpp(model_path=MODEL_PATH, n_ctx=MODEL_N_CTX, n_batch=MODEL_N_BATCH, verbose=False)
qa = RetrievalQA.from_chain_type(
    llm=llm ,chain_type="stuff", retriever=retriever, return_source_documents=True,
    chain_type_kwargs={
        "prompt": PromptTemplate(
            template=template,
            input_variables=["context", "query"],
        ),
    },
)
prompt =PromptTemplate(
            template=template,
            input_variables=["context", 'query'],
        )
config = RailsConfig.from_path("./config")
rails = LLMRails(config)
guardrails = RunnableRails(config)
chain_with_guardrails = prompt| guardrails | qa
chain_with_guardrails = RunnableRails(config, runnable=qa, input_key='query')
a=chain_with_guardrails.invoke({'query': "what is fat grafting"})
print(a)

config.yml

models:
  - type: main
    engine: vertexai
    model: text-bison

instructions:
  - type: general
    content: |
      Below is a conversation between a user and a health assistant bot called Helpful Holly.
      The bot is designed to answer questions related to breast reconstruction surgery.
      If the bot does not know the answer to a question, it truthfully says it does not know.

rails.co

define flow
  user ...
  $output = execute qa($user_message)
  bot $output

Output

user "what is fat grafting"

INFO:nemoguardrails.logging.callbacks:Completion ::  bot respond to the question
  "Fat grafting, also known as autologous fat transfer, is a surgical procedure that involves transferring fat from one area of your body to another, in this case, to the breast area. It's commonly used in breast reconstruction to enhance the shape and volume of the reconstructed breast. During the procedure, fat is harvested from a donor site, such as the abdomen or thighs, and then carefully injected into the breast tissue. This technique can provide a natural-looking and fuller appearance to the reconstructed breast. However, it's important to note that fat grafting may not be suitable for all individuals and may
INFO:nemoguardrails.logging.callbacks:Output Stats :: None
INFO:nemoguardrails.logging.callbacks:--- :: LLM call took 2.90 seconds
INFO:nemoguardrails.actions.llm.generation:Canonical form for user intent: bot respond to the question
INFO:nemoguardrails.flows.runtime:Processing event: {'type': 'UserIntent', 'uid': 'd44d1f70-cc00-408e-ad39-ada8b80ee2d1', 'event_created_at': '2024-02-02T16:39:55.947926+00:00', 'source_uid': 'NeMoGuardrails', 'intent': 'bot respond to the question'}
INFO:nemoguardrails.flows.runtime:Event :: UserIntent {'uid': 'd44d1f70-cc00-408e-ad39-ada8b80ee2d1', 'event_created_at': '2024-02-02T16:39:55.947926+00:00', 'source_uid': 'NeMoGuardrails', 'intent': 'bot respond to the question'}
INFO:nemoguardrails.flows.runtime:Processing event: {'type': 'StartInternalSystemAction', 'uid': 'd407d885-1d03-4f8e-becd-0bb8a7fd11fa', 'event_created_at': '2024-02-02T16:39:55.947926+00:00', 'source_uid': 'NeMoGuardrails', 'action_name': 'qa', 'action_params': {'$1': '$user_message'}, 'action_result_key': 'output', 'action_uid': '86e75c4a-e4d1-44eb-8d27-d204a1fafa24', 'is_system_action': False}
INFO:nemoguardrails.flows.runtime:Event :: StartInternalSystemAction {'uid': 'd407d885-1d03-4f8e-becd-0bb8a7fd11fa', 'event_created_at': '2024-02-02T16:39:55.947926+00:00', 'source_uid': 'NeMoGuardrails', 'action_name': 'qa', 'action_params': {'$1': '$user_message'}, 'action_result_key': 'output', 'action_uid': '86e75c4a-e4d1-44eb-8d27-d204a1fafa24', 'is_system_action': False}
INFO:nemoguardrails.flows.runtime:Processing event: {'type': 'hide_prev_turn'}
INFO:nemoguardrails.flows.runtime:Event :: hide_prev_turn {}
INFO:nemoguardrails.rails.llm.llmrails:--- :: Total processing took 2.92 seconds.
INFO:nemoguardrails.rails.llm.llmrails:--- :: Stats: 1 total calls, 2.898914098739624 total time, 0 total tokens, 0 total prompt tokens, 0 total completion tokens
{'output': None}
Error in sys.excepthook:

Komal-99 avatar Feb 02 '24 17:02 Komal-99