NVIDIA-NeMo / NVIDIA-NeMo/Guardrails

global variable to update user informations for extraction task

Open
#424 6 comments 0 reactions 1 assignee View on GitHub

@drazvan is already working on this.

Since Apr 15, 2024.

bug
Dominant language
Python
Stars
7.2k
Forks
842
Avg merge
3d 1h
Merged PRs (30d)
25

Description

Hi, thank for great framework

I want to use 1 variable user_info to init and update user information.
My script like this

user_info = {}
USER_INFO_KEYS = ["user_name", "ship_address", "phone_number"]

def init_user_info():
    for info_key in USER_INFO_KEYS:
        user_info[info_key] = "unknown"
init_user_info()

async def update_user_info_details(user_info_details="unknown", key="info"):
    user_info[key] = user_info_details
    return user_info

async def get_user_info_details():
    return user_info


COLANG_CONFIG = """
define user give personal info
  "mình tên Hà, địa chỉ của mình là quận Thủ đức"
  "42 đường Ngô Quyền là địa chỉ, mình tên Sang, sđt 01823737738"
  "Ship về địa chỉ Biên Hòa cho tôi, số điện thoại 096594019"

define bot confirm personal info
  "Thông tin của bạn đã được tiếp nhận: - Tên người mua hàng: $user_name - Địa chỉ: $ship_address - Số điện thoại: $phone_number"

define flow process personal info
  user give personal info

  $user_info = execute get_user_info_details()

  if $user_info.user_name == "unknown"
    ## Extract the name of the Vietnamese user. If not specified, say "unknown"
    $user_name = ...
    if $user_name != "unknown"
      $user_info = execute update_user_info_details(user_info_details=$user_name, key="user_name")

  if $user_info.ship_address == "unknown"
    ## Extract the ship address from the Vietnamese user's query. If not specified, say "unknown"
    $ship_address = ...
    if $ship_address != "unknown"
      $user_info = execute update_user_info_details(user_info_details=$ship_address, key="ship_address")

  if $user_info.phone_number == "unknown"
    ## Extract the phone number from the Vietnamese user's query. If not specified, say "unknown"
    $phone_number = ...
    if $phone_number != "unknown"
      $user_info = execute update_user_info_details(user_info_details=$phone_number, key="phone_number")

  bot confirm personal info
"""

config = RailsConfig.from_content(COLANG_CONFIG)
app = LLMRails(config, llm=llm, verbose=True)
app.runtime.register_action_param("llm", llm)
app.register_action(update_user_info_details, "update_user_info_details")
app.register_action(get_user_info_details, "get_user_info_details")

when user give their info:

messages= [{
    "role": "user",
    "content": "Mình là Ngọc, địa chỉ giao hàng là 42 đường số 3, số điện thoại là 0965326589"
}]
new_message = await app.generate_async(messages=messages)

i got output when print new_message :
{'user_name': 'Ngọc', 'ship_address': 'unknown', 'phone_number': 'unknown'}
but my expected output is:
{'user_name': 'Ngọc', 'ship_address': '42 đường số 3', 'phone_number': '0965326589'}

Can you take a look my problem and shown the misstake in my flow. Thank you so much !!!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.