w831152001 commited on
Commit
8c77142
·
1 Parent(s): bb4b5bd

change to google gemini

Browse files
Files changed (2) hide show
  1. main.py +13 -5
  2. requirements.txt +2 -1
main.py CHANGED
@@ -25,11 +25,19 @@ import os
25
  import requests
26
  import logging
27
 
28
- HF_TOKEN = os.environ.get('HF_TOKEN')
29
- headers = {"Authorization": f"Bearer {HF_TOKEN}"}
30
- API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1"
 
 
 
 
 
 
 
31
  def query(payload):
32
- response = requests.post(API_URL, headers=headers, json=payload)
 
33
  return response.text
34
 
35
  app = Flask(__name__)
@@ -69,7 +77,7 @@ def callback():
69
  def handle_message(event):
70
  with ApiClient(configuration) as api_client:
71
  line_bot_api = MessagingApi(api_client)
72
- response = query({"inputs": event.message.text})
73
  html_msg = markdown.markdown(response)
74
  soup = BeautifulSoup(html_msg, 'html.parser')
75
  line_bot_api.reply_message_with_http_info(
 
25
  import requests
26
  import logging
27
 
28
+ import google.generativeai as genai
29
+
30
+ # HF_TOKEN = os.environ.get('HF_TOKEN')
31
+ # headers = {"Authorization": f"Bearer {HF_TOKEN}"}
32
+
33
+ GOOGLE_API_KEY = os.environ.get('GOOGLE_API_KEY')
34
+ genai.configure(api_key=GOOGLE_API_KEY)
35
+ model = genai.GenerativeModel('gemini-1.5-flash')
36
+
37
+ # API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1"
38
  def query(payload):
39
+ # response = requests.post(API_URL, headers=headers, json=payload)
40
+ response = model.generate_content(payload)
41
  return response.text
42
 
43
  app = Flask(__name__)
 
77
  def handle_message(event):
78
  with ApiClient(configuration) as api_client:
79
  line_bot_api = MessagingApi(api_client)
80
+ response = query(event.message.text)
81
  html_msg = markdown.markdown(response)
82
  soup = BeautifulSoup(html_msg, 'html.parser')
83
  line_bot_api.reply_message_with_http_info(
requirements.txt CHANGED
@@ -2,4 +2,5 @@ Flask
2
  gunicorn
3
  line-bot-sdk
4
  markdown
5
- beautifulsoup4
 
 
2
  gunicorn
3
  line-bot-sdk
4
  markdown
5
+ beautifulsoup4
6
+ google-generativeai