Spaces:
Sleeping
Sleeping
File size: 4,094 Bytes
6060c1f a00c795 8b843d4 b472985 d40b153 7af90ad b472985 ddb1584 e7a7122 b472985 f6ab55d e87659d b472985 59628b5 7b89462 eb72857 819f86e a6db119 0e44529 a6db119 0e44529 a6db119 0e44529 a6db119 0e44529 a6db119 0e44529 a6db119 0e44529 a6db119 5039870 a6db119 0e44529 a6db119 0e44529 a6db119 0e44529 7b89462 fb0e311 0cb6fe1 e02ed3c 5ba803b 71b33a1 a676ccb 46a6ac7 a676ccb 46a6ac7 a676ccb b472985 a49d96b d40b153 a49d96b b472985 18f646d b472985 f6ab55d 2ed007f a84d38a 2ed007f c78e2fb b472985 0b876fd a49d96b d40b153 c78e2fb a49d96b d40b153 a49d96b 6e86bb5 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
from tqdm import tqdm
from langchain_huggingface.llms import HuggingFaceEndpoint as HF
llm = HF(repo_id="HuggingFaceH4/zephyr-7b-beta",task="conversational.")
from subprocess import Popen, PIPE as P
#b=Popen("wget 1https://huggingface.co/peterpeter8585/deepseek-llm-7b-chat-Q8_0-GGUF/resolve/main/deepseek-llm-7b-chat-q8_0.gguf -O ./model.gguf",shell=True,stderr=P,stdout=P)
#print(b.stdout.read()+b.stderr.read())
from langchain_experimental.tools.python.tool import PythonREPLTool as PYT
from langchain.agents import load_tools, create_structured_chat_agent as Agent,AgentExecutor as Ex, AgentType as Type
from langchain.agents.agent_toolkits import create_retriever_tool as crt
from langchain_community.agent_toolkits import FileManagementToolkit as FMT
from langchain.tools import Tool,YouTubeSearchTool as YTS
from langchain.memory import ConversationBufferMemory as MEM,RedisChatMessageHistory as HIS
from langchain import hub
import os
import torch
from langchain import hub
torch.set_flush_denormal(True)
import importlib.util
import logging
from typing import Any, Dict, Iterator, List, Mapping, Optional
#system = '''Respond to the human as helpfully and accurately as possible. You have access to the following tools:
#{tools}
#Use a json blob to specify a tool by providing an action key (tool name) and an action_input key (tool input).
#Valid "action" values: "Final Answer" or {tool_names}
#Provide only ONE action per $JSON_BLOB, as shown:
#```
#{{
#"action": $TOOL_NAME,
# "action_input": $INPUT
#}}
#```
#'''
#Follow this format:
#Question: input question to answer
#Thought: consider previous and subsequent steps
#Action:
#```
#$JSON_BLOB
#```
#Observation: action result
#... (repeat Thought/Action/Observation N times)
#Thought: I know what to respond
#Action:
#```
#{
#"action": "Final Answer",
#"action_input": "Final response to human"
#}}
#Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:```$JSON_BLOB```then Observation'''
#'''
#(reminder to respond in a JSON blob no matter what)'''
prompt=hub.pull("hwchase17/structured-chat-agent")
from typing import Any, Dict, List, Optional
from langchain_core.language_models import BaseChatModel
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
from langchain_core.outputs import ChatResult, ChatGeneration
from langchain_core.callbacks.manager import CallbackManagerForLLMRun
from langchain_core.callbacks.manager import AsyncCallbackManagerForLLMRun
from langchain_core.runnables import run_in_executor
from transformers import AutoTokenizer, AutoModelForCausalLM
import requests
import os
#from transformers import pipeline,AutoModelForCausalLM as M,AutoTokenizer as T
#m=M.from_pretrained("peterpeter8585/syai4.3")
#t=T.from_pretrained("peterpeter8585/syai4.3")
#pipe=pipeline(model=m,tokenizer=t,task="text-generation")
import multiprocessing
#from langchain.llms import GPT4All
#llm = GPT4All(model=("./model.gguf"))
from langchain.retrievers import WikipediaRetriever as Wiki
import gradio as gr
chatbot = gr.Chatbot(
label="PIXAL(Pimary Interactive X-ternal Assistant with multi Language) 1.0",
show_copy_button=True,
layout="panel"
)
def terminal(c):
a=Popen(c,shell=True,stdin=P,stdout=P,stderr=P)
return a.stdout.read()+a.stderr.read()
tools=FMT().get_tools()
tools.append(PYT())
tools.append(YTS())
tools.extend(load_tools(["requests_all"],allow_dangerous_tools=True))
tools.extend(load_tools(["llm-math","ddg-search"],llm=llm))
tools.append(Tool.from_function(func=terminal,name="terminal",description="터미널 명령어실행에 적합함"))
memory=MEM()
tools.append(crt(name="wiki",description="위키 백과를 검색하여 정보를 가져온다",retriever=Wiki(lang="ko",top_k_results=1)))
agent=Ex(agent=Agent(llm,tools,prompt),tools=tools,verbose=True,memory=memory)
def chat(message,
history: list[tuple[str, str]]):
return agent.invoke({"input":message})
ai1=gr.ChatInterface(
chat,
chatbot=chatbot,
)
ai1.launch() |