This commit is contained in:
parent
b18ddc8f5a
commit
f2d5882573
@ -15,4 +15,9 @@ LOG_LEVEL=debug # 控制日志级别: debug, info, warning, error, critical
|
||||
|
||||
# 其他高级选项
|
||||
# SSL_CERT_PATH=/path/to/cert.pem
|
||||
# SSL_KEY_PATH=/path/to/key.pem
|
||||
# SSL_KEY_PATH=/path/to/key.pem
|
||||
|
||||
# OpenAI相关配置
|
||||
AI_BASE_URL=https://api.deepseek.com/v1
|
||||
AI_KEY=sk-xxxx
|
||||
AI_MODEL=depseek-chat
|
53
.gitea/workflows/build-image.yaml
Normal file
53
.gitea/workflows/build-image.yaml
Normal file
@ -0,0 +1,53 @@
|
||||
name: BuildImage
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build-image:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
# 使用这个镜像,不然Docker无法打包镜像
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Gen Tags
|
||||
id: gen_tags
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: gitee.ltd/lxh/sms-server
|
||||
flavor: |
|
||||
latest=true
|
||||
tags: |
|
||||
type=raw,value={{date 'YYYYMMDD' tz='Asia/Shanghai'}}
|
||||
|
||||
- name: Print Tags
|
||||
run: |
|
||||
echo "${{ steps.gen_tags.outputs.tags }}"
|
||||
echo "----------------- labels -----------------"
|
||||
echo "${{ steps.meta.outputs.labels }}"
|
||||
|
||||
- name: Login to Repository
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: gitee.ltd
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
|
||||
- name: Build image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
push: true
|
||||
no-cache: true
|
||||
tags: ${{ steps.gen_tags.outputs.tags }}
|
||||
labels: ${{ steps.gen_tags.outputs.labels }}
|
||||
|
||||
- name: Clear images
|
||||
run: |
|
||||
docker images | grep "gitee.ltd/lxh/sms-server"
|
||||
docker rmi -f $(docker images | grep "gitee.ltd/lxh/sms-server" | awk '{print $3}')
|
@ -2,11 +2,8 @@ FROM python:3.9-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 安装 git 用于拉取最新代码
|
||||
RUN apt-get update && apt-get install -y git && apt-get clean
|
||||
|
||||
# 拉取最新代码(请确保仓库为public,否则需要处理身份验证)
|
||||
RUN git clone https://github.com/nmhjklnm/sms_server.git .
|
||||
# 复制代码
|
||||
COPY . .
|
||||
|
||||
# 安装依赖
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
@ -9,6 +9,9 @@ class Settings(BaseSettings):
|
||||
host: str = os.getenv("HOST", "0.0.0.0")
|
||||
port: int = int(os.getenv("PORT", "8322"))
|
||||
log_level: str = os.getenv("LOG_LEVEL", "info").lower()
|
||||
ai_base_url: str = os.getenv("AI_BASE_URL", "")
|
||||
ai_api_key: str = os.getenv("AI_KEY", "")
|
||||
ai_model: str = os.getenv("AI_MODEL", "")
|
||||
|
||||
# 数据库配置
|
||||
db_connect_args: Dict[str, Any] = {"check_same_thread": False}
|
||||
|
@ -1,7 +1,21 @@
|
||||
from typing import Optional
|
||||
import re
|
||||
|
||||
from openai import OpenAI
|
||||
|
||||
from backend.config.settings import settings
|
||||
|
||||
|
||||
def extract_code_with_context(sms_content: str) -> Optional[str]:
|
||||
# 判断AI相关的三个环境变量是否都有值
|
||||
# 如果有值,调用AI接口
|
||||
# 如果没有值,调用正则表达式
|
||||
if settings.ai_base_url != "" and settings.ai_api_key != "" and settings.ai_model != "":
|
||||
return _extract_code_with_ai(sms_content)
|
||||
else:
|
||||
return _extract_code_with_reg(sms_content)
|
||||
|
||||
def _extract_code_with_reg(sms_content: str) -> Optional[str]:
|
||||
pattern = r'(?:验证码|auth|code)[^0-9]{0,20}(\d{4,8})'
|
||||
match = re.search(pattern, sms_content, re.IGNORECASE)
|
||||
if match:
|
||||
@ -9,6 +23,24 @@ def extract_code_with_context(sms_content: str) -> Optional[str]:
|
||||
fallback = re.findall(r'(\d{4,8})', sms_content)
|
||||
return fallback[0] if fallback else None
|
||||
|
||||
def _extract_code_with_ai(sms_content: str) -> Optional[str]:
|
||||
client = OpenAI(api_key=settings.api_key, base_url=settings.ai_base_url)
|
||||
response = client.chat.completions.create(
|
||||
messages=[
|
||||
{
|
||||
"role": "system",
|
||||
"content": "你是一个验证码提取助手,我会告诉你短信内容,请将其中的验证码提取给我,只需要返回验证码即可,如果没有验证码,请返回null,不需要返回任何其他无关的内容。",
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": sms_content,
|
||||
}
|
||||
],
|
||||
model=settings.ai_model,
|
||||
)
|
||||
code = response.choices[0].message.content
|
||||
return code if code != "null" else None
|
||||
|
||||
def extract_phone_from_sim_slot(sim_slot: Optional[str]) -> Optional[str]:
|
||||
if not sim_slot:
|
||||
return None
|
||||
|
@ -7,3 +7,4 @@ python-multipart>=0.0.5
|
||||
aiosqlite>=0.17.0
|
||||
jinja2>=3.1.6
|
||||
python-dotenv>=0.19.0
|
||||
openai>=1.68.2
|
Loading…
x
Reference in New Issue
Block a user