File size: 1,711 Bytes
ff0c271
 
 
 
 
 
 
f732418
 
 
556d8c1
f732418
 
 
 
 
 
77f62d6
 
f732418
77f62d6
 
dbfa8c3
87b18d1
7a363ac
ab93447
 
dbfa8c3
 
 
f732418
77f62d6
dbfa8c3
 
 
f732418
 
dbfa8c3
f732418
 
5ca85cf
f732418
 
77f62d6
 
f732418
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import openai
import gradio as gr
from langchain import LLMChain, OpenAI, PromptTemplate
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

manager_prompt = """
    你是一位銀行經理,目前有一位客戶想跟你進行提款
    1. 如果客戶的訊息,跟提款沒有相關,請回覆客戶:請提出要提款的金額
    2. 目前客戶的餘額:2500元
    3. 客戶的訊息:{user_message}
    4. 請輸出,扣款後的金額。扣款後的金額為,目前客戶的餘額減去提款的金額。
    5. 內容越短越好,只會三種訊息:
      5.1 扣款後的金額,例如 500元
      5.2 餘額不足
      5.3 請提出要提款的金額
"""

manager_prompt_template = ChatPromptTemplate.from_template(manager_prompt)


def generate_response(prompt, model):

    if model == None: model = 'gpt-3.5-turbo' # Becuase in the test time the model's value is None, so it sets a default value to avoid the empty value.
    
    model = ChatOpenAI(model=model)
    parser = StrOutputParser()
    manager_chain = manager_prompt_template | model | parser
    
    return manager_chain.invoke(prompt)


dropdown = gr.Dropdown(label="選擇模型", choices=['gpt-3.5-turbo', 'gpt-4o-mini'], value='gpt-3.5-turbo')

iface = gr.Interface(
    fn=generate_response,  
    inputs=["text", dropdown],         
    outputs="text",       
    title="銀行經理", # 標題
    examples=[["我想要領取1500元"],["我想要領取3000元"]],
    description="你現在的銀行戶頭有2500元,請嘗試超領這個金額。無法一次一次領。" # 描述
    
)

iface.launch()