kenken999 commited on
Commit
5a16c22
1 Parent(s): a74f794
babyagi/classesa/diamond.py CHANGED
@@ -80,6 +80,59 @@ class ProductDatabase:
80
  results = cursor.fetchall()
81
  return results
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  def main():
84
  # データベース接続情報
85
  DATABASE_URL = "postgresql://miyataken999:[email protected]/neondb?sslmode=require"
 
80
  results = cursor.fetchall()
81
  return results
82
 
83
+ def calculate(x,y,z,c):
84
+ # データベース接続情報
85
+ DATABASE_URL = "postgresql://miyataken999:[email protected]/neondb?sslmode=require"
86
+
87
+ # ProductDatabaseクラスのインスタンスを作成
88
+ db = ProductDatabase(DATABASE_URL)
89
+
90
+ # データベースに接続
91
+ db.connect()
92
+
93
+ try:
94
+ # pgvector拡張機能のインストールとカラムの追加
95
+ db.setup_vector_extension_and_column()
96
+ print("Vector extension installed and column added successfully.")
97
+ query_text="1"
98
+ results = db.search_similar_all(query_text)
99
+ print("Search results:")
100
+ DEBUG=0
101
+ if DEBUG==1:
102
+ for result in results:
103
+ print(result)
104
+ id = result[0]
105
+ sample_text = str(result[1])+str(result[2])+str(result[3])+str(result[4])+str(result[5])+str(result[6])+str(result[7])+str(result[8])+str(result[9])
106
+ print(sample_text)
107
+ db.insert_vector(id, sample_text)
108
+ #return
109
+ # サンプルデータの挿入
110
+ #sample_text = """"""
111
+ #sample_product_id = 1 # 実際の製品IDを使用
112
+ #db.insert_vector(sample_product_id, sample_text)
113
+ #db.insert_vector(2, sample_text)
114
+
115
+ #print(f"Vector inserted for product ID {sample_product_id}.")
116
+
117
+
118
+ # ベクトル検索
119
+ query_text = "2.03Very GoodJSI262.058.08.068.125.05"
120
+
121
+ query_text = "2.03Very GoodJSI2"
122
+
123
+ #query_text = "2.03-Very Good-J-SI2-62.2-58.0-7.27-7.33-4.55"
124
+ results = db.search_similar_vectors(query_text)
125
+ res_all = ""
126
+ print("Search results:")
127
+ for result in results:
128
+ print(result)
129
+ res_all += result+""
130
+
131
+ finally:
132
+ # 接続を閉じる
133
+ db.close()
134
+
135
+
136
  def main():
137
  # データベース接続情報
138
  DATABASE_URL = "postgresql://miyataken999:[email protected]/neondb?sslmode=require"
chat_history.db CHANGED
Binary files a/chat_history.db and b/chat_history.db differ
 
controllers/gpt_enginner20240623055745 ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit 35fa17068f94587089db2c188dfebe760e97c074
controllers/gpt_enginner20240623060021 ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit 33283e43c1fb61111147c97ecf3587ade44b4c4e
controllers/gpt_enginner20240623060323 ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit e48e80a8f35468c3d3965d84ddc03745878db6f3
controllers/gpt_enginner20240623062247 ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit b14eca59be89da0baf0648650a8a86c6e155572a
controllers/gra_02_openInterpreter/OpenInterpreter.py CHANGED
@@ -3,7 +3,7 @@ from mysite.libs.utilities import chat_with_interpreter, completion, process_fil
3
  from interpreter import interpreter
4
  import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます
5
  import duckdb
6
- from logger import logger
7
 
8
  def format_response(chunk, full_response):
9
  # Message
 
3
  from interpreter import interpreter
4
  import mysite.interpreter.interpreter_config # インポートするだけで設定が適用されます
5
  import duckdb
6
+ #from logger import logger
7
 
8
  def format_response(chunk, full_response):
9
  # Message
mysite/routers/diamond.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # prompt: fastapi route 処理作成 引数は calat wehth state x
2
+
3
+ from fastapi import APIRouter, HTTPException
4
+ from babyagi.classesa import da
5
+
6
+ import psycopg2
7
+ from sentence_transformers import SentenceTransformer
8
+ from fastapi import APIRouter, HTTPException
9
+
10
+ router = APIRouter(prefix="/leaning", tags=["leaning"])
11
+ @router.get("/route/{calat}/{wehth}/{state}/{x}")
12
+ async def route(calat: float, wehth: float, state: str, x: int):
13
+ # Validate input parameters
14
+ if not (0.0 <= calat <= 90.0):
15
+ raise HTTPException(status_code=400, detail="Invalid calat value.")
16
+ if not (0.0 <= wehth <= 180.0):
17
+ raise HTTPException(status_code=400, detail="Invalid wehth value.")
18
+ if state not in ["AC", "AL", "AP", ..., "TO"]:
19
+ raise HTTPException(status_code=400, detail="Invalid state value.")
20
+ if not (0 <= x <= 100):
21
+ raise HTTPException(status_code=400, detail="Invalid x value.")
22
+
23
+ # Process the request and return a response
24
+ # ...
25
+
26
+ return {"result": "OK"}
27
+
28
+ class ProductDatabase:
29
+ def __init__(self, database_url):
30
+ self.database_url = database_url
31
+ self.conn = None
32
+ self.model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
33
+
34
+ def connect(self):
35
+ self.conn = psycopg2.connect(self.database_url)
36
+
37
+ def close(self):
38
+ if self.conn:
39
+ self.conn.close()
40
+
41
+ def setup_vector_extension_and_column(self):
42
+ with self.conn.cursor() as cursor:
43
+ # pgvector拡張機能のインストール
44
+ cursor.execute("CREATE EXTENSION IF NOT EXISTS vector;")
45
+
46
+ # ベクトルカラムの追加
47
+ cursor.execute("ALTER TABLE products ADD COLUMN IF NOT EXISTS vector_col vector(384);")
48
+
49
+ self.conn.commit()
50
+
51
+ def get_embedding(self, text):
52
+ embedding = self.model.encode(text)
53
+ return embedding
54
+
55
+ def insert_vector(self, product_id, text):
56
+ vector = self.get_embedding(text).tolist() # ndarray をリストに変換
57
+ with self.conn.cursor() as cursor:
58
+ cursor.execute("UPDATE diamondprice SET vector_col = %s WHERE id = %s", (vector, product_id))
59
+ self.conn.commit()
60
+
61
+ def search_similar_vectors(self, query_text, top_k=50):
62
+ query_vector = self.get_embedding(query_text).tolist() # ndarray をリストに変換
63
+ with self.conn.cursor() as cursor:
64
+ cursor.execute("""
65
+ SELECT id,price,carat, cut, color, clarity, depth, diamondprice.table, x, y, z, vector_col <=> %s::vector AS distance
66
+ FROM diamondprice
67
+ WHERE vector_col IS NOT NULL
68
+ ORDER BY distance asc
69
+ LIMIT %s;
70
+ """, (query_vector, top_k))
71
+ results = cursor.fetchall()
72
+ return results
73
+
74
+ def search_similar_all(self, query_text, top_k=5):
75
+ query_vector = self.get_embedding(query_text).tolist() # ndarray をリストに変換
76
+ with self.conn.cursor() as cursor:
77
+ cursor.execute("""
78
+ SELECT id,carat, cut, color, clarity, depth, diamondprice.table, x, y, z
79
+ FROM diamondprice
80
+ order by id asc
81
+ limit 10000000
82
+ """, (query_vector, top_k))
83
+ results = cursor.fetchall()
84
+ return results
85
+
86
+ def calculate(x,y,z,c):
87
+ # データベース接続情報
88
+ DATABASE_URL = "postgresql://miyataken999:[email protected]/neondb?sslmode=require"
89
+
90
+ # ProductDatabaseクラスのインスタンスを作成
91
+ db = ProductDatabase(DATABASE_URL)
92
+
93
+ # データベースに接続
94
+ db.connect()
95
+
96
+ try:
97
+ # pgvector拡張機能のインストールとカラムの追加
98
+ db.setup_vector_extension_and_column()
99
+ print("Vector extension installed and column added successfully.")
100
+ query_text="1"
101
+ results = db.search_similar_all(query_text)
102
+ print("Search results:")
103
+ DEBUG=0
104
+ if DEBUG==1:
105
+ for result in results:
106
+ print(result)
107
+ id = result[0]
108
+ sample_text = str(result[1])+str(result[2])+str(result[3])+str(result[4])+str(result[5])+str(result[6])+str(result[7])+str(result[8])+str(result[9])
109
+ print(sample_text)
110
+ db.insert_vector(id, sample_text)
111
+ #return
112
+ # サンプルデータの挿入
113
+ #sample_text = """"""
114
+ #sample_product_id = 1 # 実際の製品IDを使用
115
+ #db.insert_vector(sample_product_id, sample_text)
116
+ #db.insert_vector(2, sample_text)
117
+
118
+ #print(f"Vector inserted for product ID {sample_product_id}.")
119
+
120
+
121
+ # ベクトル検索
122
+ query_text = "2.03Very GoodJSI262.058.08.068.125.05"
123
+
124
+ query_text = "2.03Very GoodJSI2"
125
+
126
+ #query_text = "2.03-Very Good-J-SI2-62.2-58.0-7.27-7.33-4.55"
127
+ results = db.search_similar_vectors(query_text)
128
+ res_all = ""
129
+ print("Search results:")
130
+ for result in results:
131
+ print(result)
132
+ res_all += result+""
133
+
134
+ finally:
135
+ # 接続を閉じる
136
+ db.close()
137
+ #router = APIRouter()
138
+
workspace/product_info.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "ブランド名": "",
3
+ "モデル名": "",
4
+ "型番や品番": "",
5
+ "購入店": "",
6
+ "購入時期": "",
7
+ "購入金額": "",
8
+ "付属品": "",
9
+ "コンディション": "",
10
+ "貴金属品位": "",
11
+ "貴金属重量": ""
12
+ }