gushoubang 9 kuukautta sitten
vanhempi
commit
540d8fc96e
4 muutettua tiedostoa jossa 96 lisäystä ja 9 poistoa
  1. 32 0
      1.py
  2. 16 7
      app.py
  3. 46 0
      ceshi copy.py
  4. 2 2
      ceshi.py

+ 32 - 0
1.py

@@ -0,0 +1,32 @@
+from modelscope import AutoModelForCausalLM, AutoTokenizer
+device = "cuda" # the device to load the model onto
+ 
+model = AutoModelForCausalLM.from_pretrained(
+    "qwen/Qwen2-7B",
+    torch_dtype="auto",
+    device_map="auto"
+)
+tokenizer = AutoTokenizer.from_pretrained("qwen/Qwen2-7B")
+ 
+prompt = "Give me a short introduction to large language model."
+messages = [
+    {"role": "system", "content": "You are a helpful assistant."},
+    {"role": "user", "content": prompt}
+]
+text = tokenizer.apply_chat_template(
+    messages,
+    tokenize=False,
+    add_generation_prompt=True
+)
+model_inputs = tokenizer([text], return_tensors="pt").to(device)
+ 
+generated_ids = model.generate(
+    model_inputs.input_ids,
+    max_new_tokens=512
+)
+generated_ids = [
+    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
+]
+ 
+response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
+print(response)

+ 16 - 7
app.py

@@ -1,4 +1,5 @@
 from flask import Flask, render_template, request, jsonify
+from flask_cors import CORS
 import psycopg2
 from psycopg2.extras import DictCursor
 import logging
@@ -8,6 +9,7 @@ import datetime
 import uuid
 
 app = Flask(__name__)
+CORS(app)
 
 
 # 配置日志
@@ -53,7 +55,7 @@ def inputMsg():
 
     # 生成提示信息
     prompt = f"""请扮演文本提取工具,把这句话:"{msg}",基于以下因子选择、选址范围和用地类型提取其对应的相关数据,提取结果请严格将json格式字符串输出并保障寄送格式正确无误,
-    选址范围 = ['抱坡区','天涯区','崖州区','海棠区','吉阳区' ],
+    选址范围 = ['抱坡区','天涯区','崖州区','海棠区','吉阳区'],
     因子选择 = [
         "高程",
         "坡度",
@@ -96,7 +98,7 @@ def inputMsg():
     area是用地大小,单位统一转换为亩
     factors.type是因子选择
     其他公里、千米的单位转换为米
-    输出的json格式数据如下:
+    默认输出的json格式数据如下:
     {{
         "districtName": "抱坡区",
         "landType": "耕地",
@@ -112,11 +114,13 @@ def inputMsg():
             }},
             {{
                 "type": "永久基本农田",
-                "condition": "不相交"
+                "condition": "不相交",
+                "value": "0"
             }},
             {{
                 "type": "城镇开发边界内",
-                "condition": "包含"
+                "condition": "包含",
+                "value": "0"
             }},
             {{
                 "type": "医疗卫生设施",
@@ -130,7 +134,8 @@ def inputMsg():
 
     try:                                                                                                             
         res = ollama.generate(
-            model="qwen2:7b",
+            # model="qwen2:7b",
+            model="gemma2:27b",
             stream=False,
             prompt=prompt,
             options={"temperature": 0},
@@ -170,7 +175,7 @@ def jsonResToDict(json_res):
     formatted_time = now.strftime("%Y%m%d%H%M%S")
     res = {
         "xzmj": 1500,
-        "xmmc": "规划选址项目_"+formatted_time,
+        "xmmc": "聊天选址项目_"+formatted_time,
         "jsdw": "建设单位",
         "ydxz_bsm": landType,
         "ydmjbegin": json_res["area"]["min"],
@@ -231,7 +236,11 @@ def jsonResToDict(json_res):
         else:
             factorTemplate["conditionInfo"]=json.loads(factorTemplate["conditionInfo"])
             res["yxyz"].append(factorTemplate)
-    return res
+    resObj={}
+    resObj["data"]=res
+    resObj["code"]=200
+    resObj["type"]="selectLand"
+    return resObj
 
 # 获取因子信息
 

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 46 - 0
ceshi copy.py


+ 2 - 2
ceshi.py

@@ -82,12 +82,12 @@ factors.type是因子选择
 """
 try:
     res = ollama.generate(
-        model="qwen2:7b",
+        model="qwen2:72b",
         stream=False,
         prompt=prompt,
         options={"temperature": 0},
         format="json",
-        keep_alive=-1
+        keep_alive="1h"
     )
     print(res["response"])
 

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä