Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,9 +8,15 @@ from langchain.tools import Tool,YoutubeSearchTool as YTS
|
|
8 |
from langchain.memory import ConversationalBufferMomory as MEM,RedisChatHistory as HIS
|
9 |
from langchain.schema import SystemMessage as SM,HumanMessage as HM
|
10 |
from langchain import hub
|
11 |
-
import chainlit as cl
|
12 |
import os
|
13 |
from langchain.retrievers import WikipediaRetriever as Wiki
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
def terminal(c):
|
15 |
a=Popen(c,shell=True,stdin=P,stdout=P,stderr=P)
|
16 |
return a.stdout.read()+a.stderr.read()
|
@@ -23,26 +29,42 @@ tools.append(Tool.from_function(func=terminal,name="terminal"))
|
|
23 |
tools.append(crt(name="wiki",description="위키 백과를 검색하여 정보를 가져온다",retriever=Wiki(lang="ko",top_k_results=1)))
|
24 |
llm=HF(repo_id="peterpeter8585/syai4.0")
|
25 |
prompt=hub.pull("hwchase17/structed-chat-agent")
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
history
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
agent=EX(agent=Agent(llm,tools,prompt,memory_key="history"),tools=tools,verbose=True,handle_parsing_errors=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
await cl.Message(author="ChatBot",content=f"{m.content}").send()
|
43 |
-
cl.user_session.set("agent",agent)
|
44 |
-
@cl.on_message
|
45 |
-
async def on_message(message:str):
|
46 |
-
exe=cl.user_session.get("agent")
|
47 |
-
result=exe(message)
|
48 |
-
await cl.Message(content=result["output"]).send()
|
|
|
8 |
from langchain.memory import ConversationalBufferMomory as MEM,RedisChatHistory as HIS
|
9 |
from langchain.schema import SystemMessage as SM,HumanMessage as HM
|
10 |
from langchain import hub
|
|
|
11 |
import os
|
12 |
from langchain.retrievers import WikipediaRetriever as Wiki
|
13 |
+
import gradio as gr
|
14 |
+
chatbot = gr.Chatbot(
|
15 |
+
label="SYAI4.1",
|
16 |
+
show_copy_button=True,
|
17 |
+
likeable=True,
|
18 |
+
layout="panel"
|
19 |
+
)
|
20 |
def terminal(c):
|
21 |
a=Popen(c,shell=True,stdin=P,stdout=P,stderr=P)
|
22 |
return a.stdout.read()+a.stderr.read()
|
|
|
29 |
tools.append(crt(name="wiki",description="위키 백과를 검색하여 정보를 가져온다",retriever=Wiki(lang="ko",top_k_results=1)))
|
30 |
llm=HF(repo_id="peterpeter8585/syai4.0")
|
31 |
prompt=hub.pull("hwchase17/structed-chat-agent")
|
32 |
+
def chat(message,
|
33 |
+
history: list[tuple[str, str]],
|
34 |
+
system_message,
|
35 |
+
max_tokens,
|
36 |
+
temperature,
|
37 |
+
top_p, chat_session=""):
|
38 |
+
messages=[SM(content=system_message+"And, Your name is Chatchat")]
|
39 |
+
for val in history:
|
40 |
+
if val[0]:
|
41 |
+
messages.append(HM(content=val[0]))
|
42 |
+
if val[1]:
|
43 |
+
messages.append(AM(content=val[1]))
|
44 |
+
|
45 |
+
messages.append(HM(content=message))
|
46 |
+
history1=HIS(session_id=chat_session, url=os.environ["URL"])
|
47 |
+
memory=MEM(chat_memory=history1,memory_key="history")
|
48 |
agent=EX(agent=Agent(llm,tools,prompt,memory_key="history"),tools=tools,verbose=True,handle_parsing_errors=True)
|
49 |
+
yield agent.invoke(messages)
|
50 |
+
ai1=gr.ChatInterface(
|
51 |
+
chat,
|
52 |
+
chatbot=chatbot,
|
53 |
+
additional_inputs=[
|
54 |
+
gr.Textbox(value="You are a helpful assistant.", label="System message", interactive=True),
|
55 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
56 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.1, step=0.1, label="Temperature"),
|
57 |
+
gr.Slider(
|
58 |
+
minimum=0.1,
|
59 |
+
maximum=1.0,
|
60 |
+
value=0.1,
|
61 |
+
step=0.05,
|
62 |
+
label="Top-p (nucleus sampling)",
|
63 |
+
),
|
64 |
+
gr.Textbox(label="chat_id(please enter the chat id!)")
|
65 |
+
],
|
66 |
|
67 |
+
)
|
68 |
+
with gr.Blocks(theme="shivi/calm_seafoam") as ai:
|
69 |
+
gr.TabbedInterface([ai1],["Chatchat"])
|
70 |
+
ai.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|