# Dialogue System ## Week 13 ---- ## Architecture ![](https://hackmd.io/_uploads/H1eiMa-vn.png) ---- ## Frameworks + Google Cloud + [Dialogflow ES](https://cloud.google.com/dialogflow/es/docs) + [Dialogflow CX](https://cloud.google.com/dialogflow/cx/docs) + Rasa + [Minimal Example?](https://chat.openai.com/share/97f6ed6c-4b75-48c6-b4f0-b856fdec20d1) ---- ## 心得 學 Framework 不如自幹 ((x --- # Others ---- ## Python Decorator Python 的 Decorator 原本的用意是為了「裝飾」某個函式 ```python= def my_dec(fn): def new_fn(): print("Before Function") fn() print("After Function") return new_fn @my_dec def my_fn(): print("In The Function") my_fn() ``` ---- ## Function Collector 後來想做一個類似 Function Collector 的類別 <div class="flex-container"> <div class="flex-content"> ```python= class SoManyFunctions: def __init__(self): self.fns = list() def add_fn(self, fn): self.fns.append(fn) def run(self): for fn in self.fns: fn() ``` </div> <div class="flex-content"> ```python= smf = SoManyFunctions() @smf.add_fn def hello(): print("Hello!") @smf.add_fn def bye(): print("Bye!") smf.run() ``` </div> </div> ---- ### ChatGPT 卻跟我說這樣寫是不對的! ---- ## Return Function Decorator 必須在最後面 Return 一個 Function ```python= def add_fn(self, fn): self.fns.append(fn) return fn ``` ---- ## None Type 不然原本的 Function 會直接變成 None ```python= @without_return def hello(): print("Hello!") hello() # TypeError: 'NoneType' object is not callable @with_return def hello(): print("Hello!") hello() # Hello! ``` ---- ## Decorator Decorator 本質上是在製作另外一個 Function 在原本的 Function 行為上增加一些前後處理 --- ## VSCode Plugin + [Explorer Exclude](https://marketplace.visualstudio.com/items?itemName=PeterSchmalfeldt.explorer-exclude) + 用來瀏覽 VSCode 隱藏起來的檔案 <style> .flex-container { display: flex; justify-content: center; } .flex-content { flex-grow: 1; } </style>
{"metaMigratedAt":"2023-06-18T06:26:07.375Z","metaMigratedFrom":"YAML","title":"Week 13 - Dialogue System","breaks":true,"description":"地獄貓旅行團第 19 週心得分享","slideOptions":"{\"transition\":\"slide\"}","contributors":"[{\"id\":\"c7cbb212-2c41-4dfa-8d85-f8e7fa769bf1\",\"add\":3580,\"del\":1456}]"}
    122 views
   Owned this note