main
HuangHai 4 months ago
parent 7703bbf66f
commit 0487bb1e82

@ -14,20 +14,19 @@ from alibabacloud_tea_openapi.models import Config
from fastapi import Query, Depends, HTTPException, status, Form, FastAPI
from fastapi.security import OAuth2PasswordBearer
from jose import JWTError, jwt
from openai import AsyncOpenAI
from passlib.context import CryptContext
from starlette.responses import StreamingResponse
from WxMini.Milvus.Config.MulvusConfig import *
from WxMini.Milvus.Utils.MilvusCollectionManager import MilvusCollectionManager
from WxMini.Milvus.Utils.MilvusConnectionPool import *
from WxMini.Milvus.X3_insert_data import person_id
from WxMini.Utils.EmbeddingUtil import text_to_embedding
from WxMini.Utils.ImageUtil import *
from WxMini.Utils.MySQLUtil import init_mysql_pool, get_chat_log_by_session, get_user_by_login_name, \
get_chat_logs_by_risk_flag, get_chat_logs_summary
from WxMini.Utils.MySQLUtil import update_risk, get_last_chat_log_id
from WxMini.Utils.OssUtil import upload_mp3_to_oss_from_memory, hmacsha256
from WxMini.Utils.TianQiUtil import get_weather
from WxMini.Utils.TtsUtil import TTS
# 配置日志
@ -293,6 +292,12 @@ async def reply(person_id: str = Form(...),
# 限制历史交互提示词长度
history_prompt = history_prompt[:3000]
# 拼接交互提示词
if '天气' in prompt or '降温' in prompt or '气温' in prompt or '下雨' in prompt or '下雪' in prompt or '' in prompt:
weather_info = await get_weather('长春')
history_prompt += f"天气信息: {weather_info}\n"
logger.info(f"历史交互提示词: {history_prompt}")
# 调用大模型,将历史交互作为提示词
@ -305,7 +310,7 @@ async def reply(person_id: str = Form(...),
"content": "你是一个和你聊天人的好朋友,疏导情绪,让他开心,亲切一些,不要使用哎呀这样的语气词。聊天的回复内容不要超过100字。"},
{"role": "user", "content": f"历史对话记录:{history_prompt},本次用户问题: {prompt}"}
],
max_tokens=3000
max_tokens=4000
),
timeout=60 # 设置超时时间为 60 秒
)
@ -597,9 +602,12 @@ async def generate_upload_params(current_user: dict = Depends(get_current_user))
@app.get("/aichat/recognize_content")
async def web_recognize_content(image_url: str, current_user: dict = Depends(get_current_user)):
logger.info(f"current_user:{current_user['login_name']}")
person_id = current_user['person_id']
async def web_recognize_content(image_url: str
#, current_user: dict = Depends(get_current_user)
):
#logger.info(f"current_user:{current_user['login_name']}")
#person_id = current_user['person_id']
person_id = "1"
try:
async def generate_stream():
# 假设 recognize_content 是一个异步生成器,逐条返回识别结果
@ -639,9 +647,12 @@ async def web_recognize_text(image_url: str, current_user: dict = Depends(get_cu
@app.get("/aichat/recognize_math")
async def web_recognize_math(image_url: str, current_user: dict = Depends(get_current_user)):
logger.info(f"current_user:{current_user['login_name']}")
person_id = current_user['person_id']
async def web_recognize_math(image_url: str
#, current_user: dict = Depends(get_current_user)
):
#logger.info(f"current_user:{current_user['login_name']}")
#person_id = current_user['person_id']
person_id="1"
try:
async def generate_stream():
# 假设 recognize_content 是一个异步生成器,逐条返回识别结果

@ -1,74 +1,8 @@
import requests
from bs4 import BeautifulSoup
def get_weather():
url = "https://www.weather.com.cn/textFC/db.shtml"
response = requests.get(url)
html_content = response.content
soup = BeautifulSoup(html_content, 'html.parser')
# 获取日期
day_tabs = soup.find('ul', class_='day_tabs')
days = [day.text.strip() for day in day_tabs.find_all('li')][:3] # 只取前三天
# 获取天气信息
weather_data = []
tables = soup.find_all('table', width="100%") # 找到所有天气表格
for table in tables:
rows = table.find_all('tr')
for row in rows:
cells = row.find_all('td')
if len(cells) >= 8: # 确保是天气数据行
city = cells[1].text.strip()
weather_info = {
'city': city,
'today': {
'day': {
'weather': cells[2].text.strip(),
'wind': cells[3].text.strip(),
'temp': cells[4].text.strip()
},
'night': {
'weather': cells[5].text.strip(),
'wind': cells[6].text.strip(),
'temp': cells[7].text.strip()
}
}
}
# 检查是否有明天和后天的数据
if len(cells) >= 15:
weather_info['tomorrow'] = {
'day': {
'weather': cells[9].text.strip(),
'wind': cells[10].text.strip(),
'temp': cells[11].text.strip()
},
'night': {
'weather': cells[12].text.strip(),
'wind': cells[13].text.strip(),
'temp': cells[14].text.strip()
}
}
if len(cells) >= 22:
weather_info['day_after_tomorrow'] = {
'day': {
'weather': cells[16].text.strip(),
'wind': cells[17].text.strip(),
'temp': cells[18].text.strip()
},
'night': {
'weather': cells[19].text.strip(),
'wind': cells[20].text.strip(),
'temp': cells[21].text.strip()
}
}
weather_data.append(weather_info)
return days, weather_data
from WxMini.Utils.TianQiUtil import *
if __name__ == "__main__":
days, weather_data = get_weather()
print(weather_data)
get_weather('长春')

@ -0,0 +1,57 @@
import requests
from bs4 import BeautifulSoup
async def get_weather(city_name):
url = "https://www.weather.com.cn/textFC/db.shtml"
response = requests.get(url)
html_content = response.content
soup = BeautifulSoup(html_content, 'html.parser')
# 获取日期
day_tabs = soup.find('ul', class_='day_tabs')
days = [day.text.strip() for day in day_tabs.find_all('li')]
# 获取天气信息
weather_data = []
tables = soup.find_all('table', width="100%") # 找到所有天气表格
day = 0
for table in tables:
rows = table.find_all('tr')[2:] # 跳过前两行表头
for row in rows:
cols = row.find_all('td')
if len(cols) >= 7: # 确保是数据行
city = cols[1].text.strip()
if city != city_name:
continue
day_weather = cols[2].text.strip()
day_wind = cols[3].text.strip()
day_temp = cols[4].text.strip()
night_weather = cols[5].text.strip()
night_wind = cols[6].text.strip()
night_temp = cols[7].text.strip()
d = days[day]
day = day + 1
weather_data.append({
'day': d,
'city': city,
'day_weather': day_weather,
'day_wind': day_wind,
'day_temp': day_temp,
'night_weather': night_weather,
'night_wind': night_wind,
'night_temp': night_temp
})
# 打印结果
for data in weather_data:
print(f"日期: {data['day']}")
print(f"城市: {data['city']}")
print(f"白天天气: {data['day_weather']}, 风向风力: {data['day_wind']}, 最高气温: {data['day_temp']}")
print(f"夜间天气: {data['night_weather']}, 风向风力: {data['night_wind']}, 最低气温: {data['night_temp']}")
print('-' * 40)
return weather_data
Loading…
Cancel
Save