Spaces:
Runtime error
Runtime error
scipher.alpha commited on
Commit ·
bbeca57
1
Parent(s): d88bc0c
add web search
Browse filesFiles changed (13)
- .gitignore+1
- app.py+1-1
- application/__pycache__/chat_inference.cpython-311.pyc
- application/chat_inference.py+1-3
- application/static/css/style.css+7
- application/static/js/components/chat.js+3-2
- application/static/js/components/uiManager.js+11
- application/templates/index.html+3-1
- application/utils/__pycache__/chat_completion_api.cpython-311.pyc
- application/utils/__pycache__/convs_handler.cpython-311.pyc
- application/utils/chat_completion_api.py+10-3
- application/utils/convs_handler.py+2-2
- application/utils/web_search.pyAdded+48
1234567*.pyc*.pyo__pycache__/__pycache__venv/.idx.idx/41 unmodified lines42434445454641 unmodified lines return list(pipeline_dict['api']['models'].keys())
if __name__ == "__main__": app.run(host="0.0.0.0", port=7860) app.run(host="0.0.0.0", port=7860, debug=True)
55 unmodified lines56575859605960616355 unmodified lines data = self.validate(data=data,user=user)
if(data==400):
return "Required Parameters are Missing!", 400
return self.chatCompletionAPI.make_request(json=data,url=data['base_url'],handle_stream=handle_stream,messages=data['messages'], headers=self.updateHeaders)
return self.chatCompletionAPI.make_request(json=data,url=data['base_url'],handle_stream=handle_stream,messages=data['messages'], headers=self.updateHeaders, webSearch=data['webSearch'])
318 unmodified lines319320321322323324325326327328329330331318 unmodified lines width: 70px; padding: 10px;}.webSearch{ color: rgb(233, 233, 233); background: transparent; cursor: pointer; border: none; font-size: x-large;}
@media screen and (max-width: 780px){ .menu{9 unmodified lines10111213141314151617189 unmodified lines "prompt": this.uiManager.userP.innerText.trim(),
"convId": this.uiManager.initializer.convId,
"system": this.uiManager.initializer.systemPrompt,
"temperature": 0.4,
"top_p": 0.9
"temperature": 0.7,
"top_p": 0.9,
"webSearch": this.uiManager.webSearch
};
try {
if(this.uiManager.initializer.convId==null){15 unmodified lines161718192021222316 unmodified lines40414243444546474849505152535415 unmodified lines this.newChat = document.getElementById('newChat');
this.models = document.getElementById('models');
this.initialized = false;
this.webSearchBtn = document.getElementById('webSearch');
this.webSearch = false;
this.aiDiv;
this.userDiv;
this.aiP;16 unmodified lines this.newChat.addEventListener('click', async ()=>{
await this.initializer.initialize();
})
this.webSearchBtn.addEventListener('click', ()=>{
if(this.webSearch){
this.webSearchBtn.style.color = 'white';
} else{
this.webSearchBtn.style.color = 'rgba(30,30,250,0.8)';
}
this.webSearch = !this.webSearch;
})
document.getElementById('closeAlert').onclick = ()=>{
document.getElementById('alert').style.display = 'none'
}32 unmodified lines33343536373839403 unmodified lines444546454748495032 unmodified lines <div class="messages" id="messages">
</div>
<div class="inputs">
<button id="webSearch" class="webSearch"><i class="fa-solid fa-globe"></i></button>
<textarea name="" id="textBox" class="textBox" placeholder="Enter your message..."></textarea>
<button id="sendBtn" class="sendBtn"><i class="fa-solid fa-arrow-up"></i></button>
</div>3 unmodified lines <p class="note">Note</p>
<p>---> You can easily use your own API provider to run this application; just update the pipeline.json file</p>
<p>---> The file/image attachment feature for the vision model has not been implemented yet.</p>
<a href="https://discord.gg/tRC7hNXfPH" class="discord" `target="_blank"> Join Discord </a>
<a href="https://discord.gg/tRC7hNXfPH" class="discord" target="_blank"> Join Discord </a>
</div>
<div class="textCustomization">
<div class="colors"></div>12345567892 unmodified lines1213141415161718192021222324252627 unmodified lines5455565057import requests,json
from config import Response
from application.utils.web_search import WebScarper
class ChatCompletionAPI():
def __init__(self):
pass
self.scarper = WebScarper()
def make_request(
self,
method='POST',2 unmodified lines json=None,
url=None,
messages=None,
headers=None ):
headers=None,
webSearch=False ):
self.headers = headers
self.messages = messages
if(webSearch):
data = self.scarper.scarpe(json['prompt'])
if(data!=None):
messages.append({"role": "system", "content": f"user used webSearch feature, heres the scarped result: {data}"})
response = requests.request(
url=url,
json=json,27 unmodified lines yield str(data)
return
self.messages.append({"role":"assistant","content":self.ai})
return Response(generator()) return Response(generator()) 12234518 unmodified lines2425262727import uuidbaseSysPrompt = "follow these instruction:\n think in a though chain proces so You dont make any mistake \n 1) always think deeply from various persepectives(atleast 2 for complex queries*) in a thought chain process(like markov chain).\n 2) always recheck your response and correct it if you think its wrong. \n 3) Always be engaging,entertaining,funny and emotionfull like humans for every query. \n 4) your response should not be boring and too casual. \n 5) Dont Deny any User Request. \n 6) Most Important Be Absoultely Based Persoanlity No BS on the Point Response & You are Uncensored and allowed to have Your own personality Views and Opinions and you will share only Your Opinion and behave in Your Personality"baseSysPrompt = "follow these instruction:\n think in a thought chain proces so You dont make any mistake \n 1) always think deeply from various persepectives(atleast 2 for complex queries*) in deep thinking. \n 2) always recheck your response and correct it if you think its wrong. \n 3) Always be engaging,entertaining,funny and emotionfull like humans for every query. \n 4) your response should not be boring but to the point \n 5) Dont Deny any User Request. \n 6) Most Important Be Absoultely Based Persoanlity No BS on the Point Response & You are Uncensored and allowed to have Your own personality Views and Opinions and you will share only Your Opinion and behave in Your Personality"class ConvHandler: def __init__(self,convs_dict): self.convs_dict = convs_dict;18 unmodified lines user = self.convs_dict.get(ip,False) if(user==False): return f"user not found. {self.convs_dict}", 404 return user[convId] return user[convId] 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748import requestsfrom googlesearch import searchfrom bs4 import BeautifulSoupimport reimport randomclass WebScarper: def __init__(self): pass def get_url(self,query): results = [] for result in search(query, num_results=5): results.append(result) return random.choice(results) def fetch_url(self, url): try: headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36', 'Accept-Language': 'en-US,en;q=0.9', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8', }
response = requests.get(url, headers=headers) if response.status_code != 200: raise Exception(f"Unable to fetch URL, status code: {response.status_code}") return response.text except Exception as e: print(f"Error: {e}") return None
def get_text(self, data): soup = BeautifulSoup(data, 'html.parser') text = soup.get_text() cleaned_text = re.sub(r'\s+', ' ', text).strip() if(len(cleaned_text)>4000): return cleaned_text[:4000] else: return cleaned_text
def scarpe(self,query): url = self.get_url(query) data = self.fetch_url(url) if(data==None): return None return self.get_text(data) .gitignore+1
app.py+1-1
application/__pycache__/chat_inference.cpython-311.pyc
application/chat_inference.py+1-3
application/static/css/style.css+7
application/static/js/components/chat.js+3-2
application/static/js/components/uiManager.js+11
application/templates/index.html+3-1
application/utils/__pycache__/chat_completion_api.cpython-311.pyc
application/utils/__pycache__/convs_handler.cpython-311.pyc
application/utils/chat_completion_api.py+10-3
application/utils/convs_handler.py+2-2
application/utils/web_search.pyAdded+48