37创客科创中心

 找回密码
 立即注册
查看: 1020|回复: 4

AI课程250119

  [复制链接]

194

主题

324

帖子

2399

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2399
发表于 2025-1-19 10:31:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x

app_deepseek.py
  1. # 安装库文件: `pip3 install openai`  
  2. from openai import OpenAI
  3. dapi_key = "sk-520a3aea160a4370b022144722d54724"
  4. dapi_url = "https://api.deepseek.com"
  5. def OASK(ask="你是谁?"):      
  6.     client = OpenAI(api_key=dapi_key, base_url=dapi_url)
  7.     response = client.chat.completions.create(
  8.         model="deepseek-chat",
  9.         messages=[            
  10.             {"role": "system", "content": ask},
  11.         ],
  12.         max_tokens=1024,
  13.         temperature=0.7,
  14.         stream=False,
  15.     )
  16.     res = response.choices[0].message.content
  17.     print(res)
  18.     return res
  19. OASK()
复制代码


  1. dapi_key = "sk-520a3aea160a4370b022144722d54724"
  2. dapi_url = "https://api.deepseek.com"
复制代码
  1. def wxai():
  2.     signature = request.args.get("signature")
  3.     timestamp = request.args.get("timestamp")
  4.     nonce = request.args.get("nonce")
  5.     # echostr = request.args.get("echostr")
  6.     if not all([signature, timestamp, nonce]):
  7.         abort(400)
  8.     li = [WECHAT_TOKEN, timestamp, nonce]
  9.     li.sort()
  10.     t_str = ''.join(li)
  11.     sign = hashlib.sha1(t_str.encode('utf-8')).hexdigest()
  12.     if signature != sign:
  13.         abort(403)
  14.     else:
  15.         if request.method == 'GET':#GET获取数据和验证
  16.             echostr = request.args.get('echostr')
  17.             if not echostr:
  18.                 abort(400)
  19.             siotpub1('Get 接收:' +echostr)
  20.             return echostr
  21.         elif request.method == 'POST':#数据提交交互部分,人机应答入口
  22.             xml_s = request.data
  23.             if not xml_s:
  24.                 abort(400)
  25.             # 获取微信公众平台信息
  26.             # siotpub1('接收:' + str(xml_s))#调试使用
  27.             xml_dict = xmltodict.parse(xml_s)
  28.             xml_dict = xml_dict.get('xml')
  29.             msg_type = xml_dict.get('MsgType')
  30.             Content = xml_dict.get('Content')
  31.             # 各个成员功能入口
  32.             if msg_type == 'text':
  33.                 # Content = '\n'+wxai(Content,'\n')+'\n********37梦想********'
  34.                 Content = ''+OASK(Content,'\n')#+'**37创客 安全锋速(接送)**'
  35.             elif msg_type =='image':
  36.                 mediaId = xml_dict.get('MediaId')
  37.                 PicUrl = xml_dict.get('PicUrl')
  38.                 Content = "图片信息" + mediaId +'\n'+ PicUrl
  39.                 res_dict = makeimg(xml_dict, mediaId)
  40.                 siotpub1('发送:'+Content)#str(res_dict))
  41.                 res_xml_str = xmltodict.unparse(res_dict)
  42.                 return res_xml_str
  43.             elif msg_type =='voice':
  44.                 Content = "语音信息"
  45.             elif msg_type == 'video':
  46.                 Content = "视频信息"
  47.             elif msg_type == 'music':
  48.                 Content = "音乐信息"
  49.             elif msg_type == 'news':
  50.                 Content = "图文信息"
  51.             elif msg_type == 'location':
  52.                 Content = "位置信息"
  53.             elif msg_type == 'link':
  54.                 Content = "网址链接信息"
  55.             elif msg_type == 'shortvideo':
  56.                 Content = "短视频信息"
  57.             elif msg_type == 'event':
  58.                 event = xml_dict.get('Event')
  59.                 if event == 'subscribe':
  60.                     Content = WEL #config配置文件中设置关注欢迎词
  61.                 elif event == 'subscribe':
  62.                      Content = '取消订阅我们'
  63.             else:
  64.                 Content = '其他奥利给混进来了,大家开启防御系统!'
  65.             res_dict = make(xml_dict, Content)
  66.             siotpub1(''+Content)#str(res_dict))
  67.             res_xml_str = xmltodict.unparse(res_dict)
  68.             return res_xml_str
复制代码


app_deepseek.py
  1. #文件名字:app_deepseek.py
  2. import requests
  3. import json
  4. from typing import Dict, Any

  5. class DeepSeekClient:
  6.     def __init__(self, api_key: str):
  7.         self.api_key = api_key
  8.         self.base_url = "https://api.deepseek.com/v1"
  9.         self.headers = {
  10.             "Authorization": f"Bearer {self.api_key}",
  11.             "Content-Type": "application/json"
  12.         }
  13.     def chat_completion(self, messages: list, model: str = "deepseek-chat", temperature: float = 0.7) -> Dict[str, Any]:
  14.         """与DeepSeek AI进行对话"""
  15.         endpoint = f"{self.base_url}/chat/completions"
  16.         payload = {
  17.             "model": model,
  18.             "messages": messages,
  19.             "temperature": temperature
  20.         }
  21.         try:
  22.             response = requests.post(endpoint, headers=self.headers, json=payload)
  23.             response.raise_for_status()
  24.             return response.json()
  25.         except requests.exceptions.RequestException as e:
  26.             print(f"API请求失败: {e}")
  27.             return {}

  28. def main():
  29.     # 从配置文件读取API密钥
  30.     with open("config.json") as f:
  31.         config = json.load(f)
  32.     client = DeepSeekClient(config["deepseek_api_key"])
  33.     # 示例对话
  34.     messages = [
  35.         {"role": "user", "content": "马德堡半球实验关系到的知识点有哪些?"}#你好,请介绍一下你自己
  36.     ]
  37.     response = client.chat_completion(messages)
  38.     if response:
  39.         print("AI回复:", response["choices"][0]["message"]["content"])

  40. if __name__ == "__main__":
  41.     main()
复制代码




api key
sk-cb441140e1a44a4a86a725260f81be8d

config.json
  1. {
  2.     "deepseek_api_key": "you api key",
  3.     "tables": {
  4.         "example_table": {
  5.             "display_name": "示例表",
  6.             "fields": [
  7.                 {
  8.                     "name": "id",
  9.                     "type": "integer",
  10.                     "widget": "Label",
  11.                     "readonly": true
  12.                 },
  13.                 {
  14.                     "name": "name",
  15.                     "type": "text",
  16.                     "widget": "Entry",
  17.                     "required": true,
  18.                     "max_length": 50
  19.                 },
  20.                 {
  21.                     "name": "created_at",
  22.                     "type": "datetime",
  23.                     "widget": "DateEntry",
  24.                     "required": true
  25.                 }
  26.             ],
  27.             "actions": ["create", "read", "update", "delete"]
  28.         }
  29.     },
  30.     "ui_settings": {
  31.         "theme": "cosmo",
  32.         "window_size": "800x600",
  33.         "background_image": "background.jpg"
  34.     }
  35. }
复制代码


回复

使用道具 举报

194

主题

324

帖子

2399

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2399
 楼主| 发表于 2025-1-20 17:17:57 | 显示全部楼层
sk-0e05766085044d99a603a6e55ef7c5d7
回复

使用道具 举报

194

主题

324

帖子

2399

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2399
 楼主| 发表于 2025-1-23 09:24:15 | 显示全部楼层
ChatCompletion(id='01a3ee25-fac4-4767-9e6a-55f8fce69e6d', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='猪的死亡原因可能有很多种,以下是一些常见的原因:\n\n1. **疾病**:猪可能因为感染病毒、细菌或寄生虫而 生病,如猪瘟、猪流感、猪链球菌感染等,严重时可能导致死亡。\n\n2. **营养不良**:如果猪的饲料中缺乏必要的营养成分,或者饲料质量差, 可能导致猪营养不良,进而影响健康甚至死亡。\n\n3. **环境因素**:恶劣的饲养环境,如过度拥挤、通风不良、温度过高或过低、湿度过大等, 都可能导致猪生病或死亡。\n\n4. **中毒**:猪可能因为误食有毒物质,如农药、重金属、霉菌毒素等而中毒死亡。\n\n5. **意外伤害**:猪可  能因为打架、跌倒、被其他动物攻击等意外伤害而死亡。\n\n6. **遗传因素**:某些遗传性疾病可能导致猪在出生后不久死亡。\n\n7. **管理不  当**:饲养管理不当,如疫苗接种不及时、疾病防控措施不到位等,也可能导致猪死亡。\n\n8. **老龄化**:猪的自然寿命有限,老年猪可能因为 器官功能衰竭而死亡。\n\n在养猪业中,为了减少猪的死亡率,通常会采取一系列措施,如定期接种疫苗、提供均衡的饲料、保持良好的饲养环境  、及时治疗疾病等。', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=None))], created=1737595400, model='deepseek-chat', object='chat.completion', service_tier=None, system_fingerprint='fp_3a5770e1b4', usage=CompletionUsage(completion_tokens=265, prompt_tokens=5, total_tokens=270, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetails(audio_tokens=None, cached_tokens=0), prompt_cache_hit_tokens=0, prompt_cache_miss_tokens=5))
回复

使用道具 举报

194

主题

324

帖子

2399

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2399
 楼主| 发表于 2025-1-23 09:24:36 | 显示全部楼层
猪的死亡原因可能有很多种,以下是一些常见的原因:

1. **疾病**:猪可能因为感染病毒、细菌或寄生虫而死亡。例如,猪瘟、猪流感、猪蓝耳病等都是常见的猪病。  

2. **营养不良**:如果猪的饮食不均衡或缺乏必要的营养,可能会导致健康问题,最终死亡。

3. **环境因素**:极端的气候条件,如过热或过冷,都可能对猪的健康造成严重影响,甚至导致死亡。

4. **管理不当**:不适当的饲养管理,如过度拥挤、卫生条件差、缺乏适当的医疗照顾等,都可能导致猪的死亡。
4. **管理不当**:不适当的饲养管理,如过度拥挤、卫生条件差、缺乏适当的医疗照顾等,都可能导致猪的死亡。

5. **意外伤害**:猪可能因为意外事故,如被其他动物攻击、跌落、被重物压伤等而死亡。

6. **遗传问题**:某些遗传性疾病或缺陷可能导致猪的死亡。

7. **中毒**:猪可能因为误食有毒物质,如农药、有毒植物等而中毒死亡。

8. **屠宰**:在养殖业中,猪通常会被屠宰以供人类食用。

了解猪的死亡原因对于养殖户来说非常重要,因为这有助于他们采取预防措施,减少猪的死亡率,提高养殖效率。如果猪群中出现异常死亡情况,
应及时请兽医进行检查和诊断。
回复

使用道具 举报

45

主题

84

帖子

905

积分

版主

Rank: 7Rank: 7Rank: 7

积分
905
发表于 2025-1-23 11:23:03 | 显示全部楼层
  1. from flask import Flask, request, abort
  2. import hashlib
  3. import xmltodict
  4. from app_deepseek import *
  5. import time
  6. WECHAT_TOKEN = '37ck20200808'
  7. WEL='欢迎关注37创客!'
  8. app = Flask(__name__)
  9. def make(xmldict, t_text):
  10.     res_dict = {
  11.         'xml': {
  12.             'ToUserName': xmldict.get('FromUserName'),
  13.             'FromUserName': xmldict.get('ToUserName'),
  14.             'CreateTime': int(time.time()),
  15.             'MsgType': 'text',
  16.             'Content': t_text
  17.         }
  18.     }
  19.     return res_dict
  20. @app.route('/37mx', methods=['GET', 'POST'])
  21. def wxai():
  22.     signature = request.args.get("signature")
  23.     timestamp = request.args.get("timestamp")
  24.     nonce = request.args.get("nonce")
  25.     # echostr = request.args.get("echostr")
  26.     if not all([signature, timestamp, nonce]):
  27.         abort(400)
  28.     li = [WECHAT_TOKEN, timestamp, nonce]
  29.     li.sort()
  30.     t_str = ''.join(li)
  31.     sign = hashlib.sha1(t_str.encode('utf-8')).hexdigest()
  32.     if signature != sign:
  33.         abort(403)
  34.     else:
  35.         if request.method == 'GET':#GET获取数据和验证
  36.             echostr = request.args.get('echostr')
  37.             if not echostr:
  38.                 abort(400)
  39.             # siotpub1('Get 接收:' +echostr)
  40.             return echostr
  41.         elif request.method == 'POST':#数据提交交互部分,人机应答入口
  42.             xml_s = request.data
  43.             if not xml_s:
  44.                 abort(400)
  45.             # 获取微信公众平台信息
  46.             # siotpub1('接收:' + str(xml_s))#调试使用
  47.             xml_dict = xmltodict.parse(xml_s)
  48.             xml_dict = xml_dict.get('xml')
  49.             msg_type = xml_dict.get('MsgType')
  50.             Content = xml_dict.get('Content')
  51.             # 各个成员功能入口
  52.             if msg_type == 'text':
  53.                 # Content = '\n'+wxai(Content,'\n')+'\n********37梦想********'
  54.                 Content = ''+OASK(Content,'\n')   #接入deepseek         
  55.             elif msg_type == 'event':
  56.                 event = xml_dict.get('Event')
  57.                 if event == 'subscribe':
  58.                     Content = WEL #config配置文件中设置关注欢迎词
  59.                 elif event == 'subscribe':
  60.                      Content = '取消订阅我们'
  61.             else:
  62.                 Content = '其他奥利给混进来了,大家开启防御系统!'
  63.             res_dict = make(xml_dict, Content)
  64.             res_xml_str = xmltodict.unparse(res_dict)
  65.             return res_xml_str
  66. if __name__ == '__main__':
  67.     app.run(host='0.0.0.0', port=86, debug=True)



  68.    
  69. @app.route('/', methods=['GET', 'POST'])
  70. def index():
  71.     return "欢迎访问37创客API!flaskwx"
  72.    
  73. @app.route('/mx', methods=['GET', 'POST'])
  74. def mx():
  75.     return "欢迎访问37创客API 37梦想"
  76.    
  77. @app.route('/ck', methods=['GET', 'POST'])
  78. def ck():
  79.     return "欢迎访问37创客API 37创客 ck"


复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|37创客科创中心

GMT+8, 2025-12-10 05:13 , Processed in 0.194731 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表