solnone commited on
Commit
6438940
1 Parent(s): 2f0762a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -10
main.py CHANGED
@@ -106,12 +106,12 @@ from linebot.v3.insight import (
106
 
107
  import requests
108
 
109
- # HF_TOKEN = os.environ.get('HF_TOKEN')
110
- # headers = {"Authorization": f"Bearer {HF_TOKEN}"}
111
- # API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1"
112
- # def query(payload):
113
- # response = requests.post(API_URL, headers=headers, json=payload)
114
- # return response.json()
115
 
116
  app = Flask(__name__)
117
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -748,10 +748,10 @@ def handle_text_message(event):
748
  app.logger.info("Got x-line-request-id: " + e.headers['x-line-request-id'])
749
  app.logger.info("Got response with http body: " + str(ErrorResponse.from_json(e.body)))
750
  else:
751
- chat = get_chat(event.source.user_id)
752
- response = chat.send_message(text)
753
- # query({"inputs": input,"parameters":{"return_full_text":False,"max_length":1024}})
754
- html_msg = markdown.markdown(response.text)
755
  soup = BeautifulSoup(html_msg, 'html.parser')
756
  line_bot_api.reply_message(
757
  ReplyMessageRequest(
 
106
 
107
  import requests
108
 
109
+ HF_TOKEN = os.environ.get('HF_TOKEN')
110
+ headers = {"Authorization": f"Bearer {HF_TOKEN}"}
111
+ API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1"
112
+ def query(payload):
113
+ response = requests.post(API_URL, headers=headers, json=payload)
114
+ return response.json()
115
 
116
  app = Flask(__name__)
117
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
748
  app.logger.info("Got x-line-request-id: " + e.headers['x-line-request-id'])
749
  app.logger.info("Got response with http body: " + str(ErrorResponse.from_json(e.body)))
750
  else:
751
+ # chat = get_chat(event.source.user_id)
752
+ # response = chat.send_message(text).text
753
+ response = query({"inputs": input,"parameters":{"return_full_text":False,"max_length":1024}})
754
+ html_msg = markdown.markdown(response)
755
  soup = BeautifulSoup(html_msg, 'html.parser')
756
  line_bot_api.reply_message(
757
  ReplyMessageRequest(