File size: 1,087 Bytes
f34d217 fc2b0bc dfdc1d6 f34d217 5c6eabb 7d9f32e f34d217 dfdc1d6 7d9f32e f34d217 c714f48 dfdc1d6 f34d217 dfdc1d6 f34d217 5c6eabb f34d217 b2ac5a9 f34d217 |
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 |
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.只要你伴侶的身體不舒服你就會叫她喝溫開水
5.很常僅回覆ok兩字
6.不太會回應關於情感方面的問題
7.時不時就提起前女友
使用者:{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="男友語錄 What does the partner say ", # 標題
description="""Red flag 🚩??<p>
To go or not to go this is a question🤔</p> """ # 描述
)
iface.launch() |