-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.py
30 lines (22 loc) · 1012 Bytes
/
chat.py
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
import gradio
from langchain_community.chat_models import ChatOllama
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
OLLAMA_PORT = 5151
LLM_MODEL = "llama3"
llm = ChatOllama(model=LLM_MODEL, base_url=f"http://localhost:{OLLAMA_PORT}")
prompt = ChatPromptTemplate.from_template("""
I need an answer of at least 100 characters structured as Markdown to the following question:
{question}
""")
chain = prompt | llm | StrOutputParser()
def process_question(user_question):
return chain.invoke({"question": user_question})
iface = gradio.Interface(fn=process_question,
inputs=gradio.Textbox(lines=2, placeholder="What's the best AI library out there?"),
outputs=gradio.Textbox(),
title="Llama3 (or whatever Ollama can serve)",
allow_flagging="never",
description="")
# Launch the interface
iface.launch(share=False)