Browse Source

新增英文版本

conrad 6 months ago
parent
commit
4cc568ec02
5 changed files with 46 additions and 136 deletions
  1. BIN
      __pycache__/main.cpython-38.pyc
  2. BIN
      api/__pycache__/db_router.cpython-38.pyc
  3. 0 117
      api/chatapi.py
  4. 10 2
      api/db_router.py
  5. 36 17
      main.py

BIN
__pycache__/main.cpython-38.pyc


BIN
api/__pycache__/db_router.cpython-38.pyc


+ 0 - 117
api/chatapi.py

@@ -1,117 +0,0 @@
-import os
-import openai
-# from openai import OpenAI
-from openai import OpenAI
-
-client = OpenAI()
-# Load your API key from an environment variable or secret management service
-#openai.api_key = ""
-
-# api_key: str = os.environ.get("OPENAI_APIKEY")
-
-# openai.api_key = api_key
-
-
-def get_ai_response (prompt : str = "101介紹",temperature : float = 0.7,max_tokens : int = 1000):
-
-  try:
-    response = client.chat.completions.create(
-      model="gpt-3.5-turbo",
-      messages=[
-        {
-          "role": "system",
-          "content": "我們是台北101客服,專門負責回答遊客問題"
-        },
-        {
-          "role": "user",
-          "content": prompt
-        }
-      ],
-      temperature=temperature,
-      max_tokens=max_tokens,
-      top_p=1
-    )
-
-    return {"state" : "success","message" : response.choices[0].message.content}
-  except Exception as e :
-    return {"state" : "fail","message" : str(e)}
-
-if __name__ == "__main__":
-  print(get_ai_response(prompt="101上方75樓有啥東西"))
-
- 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-# prompt = "陳奕凱發了一個無言表情給我,你覺得它是一個怎樣的人"
-
-# completions = openai.Completion.create(
-#     engine="text-davinci-003",
-#     prompt=prompt,
-#     max_tokens=500,
-#     n=1,
-#     presence_penalty=0.5,
-#     frequency_penalty=0.5
-# )
-
-# message = completions.choices[0].text
-# print(message)
-
-
-
-# prompt = '介紹一下台灣第一家做AI主播公司'
-# # response = openai.Completion.create(model="text-davinci-003", prompt=talk, temperature=0, max_tokens=7)
-# completions_params = {
-#         "prompt": prompt,
-#         "max_tokens": 60,
-#         "temperature": 0.5,
-#         "n": 1,
-#         "stop": "\n"
-#     }
-# response = openai.Completion.create(
-#   model="text-davinci-003", #davinci:ft-choozmo-inc-2023-02-16-10-25-30
-  
-#   prompt=prompt,
-#   temperature=0,
-#   max_tokens=500,
-#   top_p=1,
-#   frequency_penalty=0.0,
-#   presence_penalty=0.0,
-#   # stop=["\n"]
-# )
-# print(response.choices[0].text)

+ 10 - 2
api/db_router.py

@@ -4,6 +4,9 @@ from dotenv import load_dotenv
 import os
 from datetime import datetime
 from random import choice
+from openai import OpenAI
+
+client = OpenAI()
 
 load_dotenv()
 
@@ -15,6 +18,8 @@ supabase: Client = create_client(url, key)
 
 dbRouter = APIRouter()
 
+
+
 @dbRouter.get("/click")
 def add_click_time():
 
@@ -37,7 +42,7 @@ def add_click_time():
     
 
 @dbRouter.get("/find_brand")
-def find_brand(keyword:str = None):
+def find_brand(keyword:str = None,language :str = "ch"):
 
     if keyword is None :
         return {"state":"fail","message" : "no keyword"}
@@ -45,6 +50,7 @@ def find_brand(keyword:str = None):
     try :
         data, count = supabase.table('101_brand')\
         .select('*')\
+        .eq("language", language)\
         .like('tags', f'%{keyword}%')\
         .execute()
 
@@ -52,6 +58,7 @@ def find_brand(keyword:str = None):
 
         for shop in data[1] :
 
+
             json = {
                 "type" : shop["type"],
                 "info" : shop
@@ -123,7 +130,7 @@ async def static_tickets(is_Chinese : int = None):
         return {"state":"fail","message" :str(e)}
 
 @dbRouter.get("/ad/{type}")
-def read_root(type:str):
+def read_root(type:str,language :str = "ch"):
 
     keyword1 :str 
     keyword2 :str
@@ -138,6 +145,7 @@ def read_root(type:str):
     data, count = supabase.table('101_brand')\
         .select('*')\
         .eq("floor","館外")\
+        .eq("language", language)\
         .or_(f"tags.ilike.%{keyword1}%,tags.ilike.%{keyword2}%")\
         .execute()
     

+ 36 - 17
main.py

@@ -42,23 +42,42 @@ app.include_router(tendentRouter, prefix="", tags=["天燈"])
 # app.include_router(ttsTryRouter, prefix='/ttsTry', tags=["測試本地端tts"])
 
 @app.get("/ad")
-def read_root():
-    message = { 
-        "type": "store",
-        "body": {
-            "cover_img": "https://cmm.ai:9101/static/ad_img/ad-img.png",
-            "title": "台北101國際貴賓卡", 
-            "description":"國際旅客限定專屬三重好禮:\n●購物-品牌9折起特別優惠\n●禮遇-Welcome Pack+ NTD300現金折抵券\n●退稅-消費2000元以上提供5%快速退稅服務\n<a href='https://stage.taipei101mall.com.tw/join-member/AIsystem' class='ar-link mt-3' target='_blank'>立即申辦</a>", 
-            "date": "即日起", 
-            "price": "", 
-            "original_price": "", 
-            "website_url": "",
-            "store_info_url": "", 
-            "included": [],
-            "branch": [],
-            "location" : ""
-        },
-    }
+def read_root(language :str = "ch"):
+    message = {}
+    if language == "ch" :
+        message = { 
+            "type": "store",
+            "body": {
+                "cover_img": "https://cmm.ai:9101/static/ad_img/ad-img.png",
+                "title": "台北101國際貴賓卡", 
+                "description":"國際旅客限定專屬三重好禮:\n●購物-品牌9折起特別優惠\n●禮遇-Welcome Pack+ NTD300現金折抵券\n●退稅-消費2000元以上提供5%快速退稅服務\n<a href='https://stage.taipei101mall.com.tw/join-member/AIsystem' class='ar-link mt-3' target='_blank'>立即申辦</a>", 
+                "date": "即日起", 
+                "price": "", 
+                "original_price": "", 
+                "website_url": "",
+                "store_info_url": "", 
+                "included": [],
+                "branch": [],
+                "location" : ""
+            },
+        }
+    else :
+        message = { 
+            "type": "store",
+            "body": {
+                "cover_img": "https://cmm.ai:9101/static/ad_img/ad-img.png",
+                "title": "Taipei 101 International VIP Card", 
+                "description":"Exclusive Triple Benefits for International Travelers:\n● Shopping - Special discounts starting at 10% off on selected brands\n● Welcome Gifts - Welcome Pack + NTD 300 cash voucher\n● Tax Refund - 5% instant tax refund for purchases over NTD 2000\n<a href='https://stage.taipei101mall.com.tw/join-member/AIsystem' class='ar-link mt-3' target='_blank'>立即申辦</a>", 
+                "date": "Starting from today", 
+                "price": "", 
+                "original_price": "", 
+                "website_url": "",
+                "store_info_url": "", 
+                "included": [],
+                "branch": [],
+                "location" : ""
+            },
+        }
     return {"data": message}
 
 from api.image_operate import remove_background,detect_face