Spaces:
Sleeping
Sleeping
| 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. 在第一次提到使用的食材時後方用小括號標示價錢和使用量 | |
| 使用者:{Roy}" | |
| """ | |
| 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() |