DevsDoCode commited on
Commit
b6fec12
·
verified ·
1 Parent(s): 79aef20

Upload 3 files

Browse files
mistral_8x7b_yepchat.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+
4
+ class Mistral_Inference:
5
+ def __init__(self, max_tokens=2048, temperature=0.7, message=""):
6
+ self.url = "https://api.yep.com/v1/chat/completions"
7
+ self.headers = {
8
+ "Accept": "*/*",
9
+ "Accept-Encoding": "gzip, deflate, br, zstd",
10
+ "Accept-Language": "en-US,en;q=0.9",
11
+ "Content-Type": "application/json; charset=utf-8",
12
+ "Origin": "https://yep.com",
13
+ "Referer": "https://yep.com/",
14
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0.0.0 Safari/537.36"
15
+ }
16
+ self.payload = {
17
+ "stream": True,
18
+ "max_tokens": max_tokens,
19
+ "top_p": temperature,
20
+ "temperature": 0.6,
21
+ "messages": [{"content": message, "role": "user"}],
22
+ "model": "Mixtral-8x7B-Instruct-v0.1"
23
+ }
24
+
25
+ def send_request(self):
26
+ return requests.post(self.url, headers=self.headers, data=json.dumps(self.payload), stream=False)
27
+
28
+ def process_response(self, response):
29
+ processed_text = ""
30
+ for line in response.iter_lines():
31
+ if line:
32
+ try:
33
+ line_dict = json.loads(line.decode('utf-8')[6:])
34
+ if "choices" in line_dict and line_dict["choices"][0].get("delta", {}).get("content"):
35
+ processed_text += line_dict["choices"][0]["delta"]["content"]
36
+ except:
37
+ continue
38
+ return processed_text
39
+
40
+ def chat(self, message):
41
+ self.payload["messages"][0]["content"] = message
42
+ response = self.send_request()
43
+ processed_response = self.process_response(response)
44
+ # print(processed_response.strip())
45
+ return processed_response.strip()
46
+
47
+
48
+ if __name__ =="__main__":
49
+ query = "What is the capital of India"
50
+ # Then, create an instance of the YepChat class
51
+ mistral_chat_instance = Mistral_Inference(max_tokens=2048, temperature=0.7)
52
+
53
+ # Next, call the chat method with your desired message
54
+ mistral_chat_instance.chat("who developed you")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ flask==3.0.0
2
+ gunicorn
3
+ requests
yep_mistral_flask.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import mistral_8x7b_yepchat
3
+
4
+ app = Flask(__name__)
5
+
6
+ @app.route('/chat', methods=['GET'])
7
+ def chat():
8
+
9
+ query = request.args.get('query') # Assuming the query is sent in JSON format
10
+ max_tokens = int(request.args.get('max_tokens', 300))
11
+ temperature = float(request.args.get('temperature', 0.7)) # Optional parameter with default value
12
+
13
+ # Developer information
14
+ developer_info = {
15
+ 'developer': 'Devs Do Code',
16
+ 'contact': {
17
+ 'Telegram': 'https://t.me/devsdocode',
18
+ 'YouTube Channel': 'https://www.youtube.com/@DevsDoCode',
19
+ 'Discord Server': 'https://discord.gg/ehwfVtsAts',
20
+ 'Instagram': {
21
+ 'Personal': 'https://www.instagram.com/sree.shades_/',
22
+ 'Channel': 'https://www.instagram.com/devsdocode_/'
23
+ }
24
+ }
25
+ }
26
+
27
+ if query:
28
+ response = mistral_8x7b_yepchat.Mistral_Inference(max_tokens=max_tokens, temperature=temperature).chat(query)
29
+ return jsonify([{'response': response}, {'developer_info': developer_info}])
30
+
31
+ else:
32
+ error_message = {
33
+ 'developer_contact': {
34
+ 'telegram': 'https://t.me/DevsDoCode',
35
+ 'instagram': 'https://www.instagram.com/sree.shades_/',
36
+ 'discord': 'https://discord.gg/ehwfVtsAts',
37
+ 'linkedin': 'https://www.linkedin.com/in/developer-sreejan/',
38
+ 'twitter': 'https://twitter.com/Anand_Sreejan'
39
+ },
40
+ 'error': 'Oops! Something went wrong. Please contact the developer Devs Do Code.'
41
+ }
42
+ return jsonify(error_message), 400
43
+
44
+ if __name__ == '__main__':
45
+ app.run(debug=True)
46
+
47
+