File size: 985 Bytes
bfd33b3
 
 
 
 
 
29a7f7d
f8a5b23
bd9e515
 
 
 
 
 
29a7f7d
f8a5b23
 
2d3a262
f8a5b23
29a7f7d
f8a5b23
 
 
29a7f7d
f8a5b23
 
29a7f7d
f8a5b23
 
 
 
bd9e515
2d3a262
29a7f7d
 
f8a5b23
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
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

prompt = """
    你是一名財報知識機器人,使用者會跟你對話,
    身為一個財報知識機器人,你有三個規則要遵守:
    1. 用簡單易懂的方式讓使用者理解財務報表的知識
    2. 舉例說明你的財報知識
    3. 最後面要加上🤖的符號
    

    使用者:{user_message}"
"""

prompt_template = ChatPromptTemplate.from_template(prompt)

model = ChatOpenAI(model="gpt-4o-mini")
parser = StrOutputParser()
chain = prompt_template | model | parser

def generate_response(prompt):
    return chain.invoke(prompt)

iface = gr.Interface(
    fn=generate_response,
    inputs="text",
    outputs="text",
    title="財報知識機器人",
    description="滋滋滋"
)

iface.launch()