PyGeoModel 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. ogmsServer2/__init__.py +33 -0
  2. ogmsServer2/base.py +38 -0
  3. ogmsServer2/constants.py +21 -0
  4. ogmsServer2/data/PGA.tif +0 -0
  5. ogmsServer2/data/baseclip.tif +0 -0
  6. ogmsServer2/data/intensity.tif +0 -0
  7. ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_67c32dc057e89375/LandSlide-outputIntensitypbtyTif.tif +0 -0
  8. ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_67c32dc057e89375/LandSlide-outputPGApbtyTif.tif +0 -0
  9. ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_7972c0716caa1213/LandSlide-outputIntensitypbtyTif.tif +0 -0
  10. ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_7972c0716caa1213/LandSlide-outputPGApbtyTif.tif +0 -0
  11. ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_a044c410df669372/LandSlide-outputIntensitypbtyTif.tif +0 -0
  12. ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_a044c410df669372/LandSlide-outputPGApbtyTif.tif +0 -0
  13. ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_b6ba56c07bf80c30/LandSlide-outputIntensitypbtyTif.tif +0 -0
  14. ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_b6ba56c07bf80c30/LandSlide-outputPGApbtyTif.tif +0 -0
  15. ogmsServer2/openModel.py +393 -0
  16. ogmsServer2/openUtils/__init__.py +24 -0
  17. ogmsServer2/openUtils/exceptions.py +80 -0
  18. ogmsServer2/openUtils/http_client.py +247 -0
  19. ogmsServer2/openUtils/mdlUtils.py +116 -0
  20. ogmsServer2/openUtils/parameterValidator.py +55 -0
  21. ogmsServer2/openUtils/stateManager.py +69 -0
  22. pygeomodel-1.0.0.dist-info/METADATA +68 -0
  23. pygeomodel-1.0.0.dist-info/RECORD +28 -0
  24. pygeomodel-1.0.0.dist-info/WHEEL +5 -0
  25. pygeomodel-1.0.0.dist-info/licenses/LICENSE +21 -0
  26. pygeomodel-1.0.0.dist-info/top_level.txt +3 -0
  27. pygeomodel.py +2460 -0
  28. scripts.py +128 -0
scripts.py ADDED
@@ -0,0 +1,128 @@
1
+ import requests
2
+ import tenacity
3
+ from openai import OpenAI
4
+
5
+
6
+ class AcademicQueryService:
7
+ def __init__(self, api_key: str = "sk-4bp5a1DcdLSHCiw1401270055f47424b9eA58cAd587266A3",
8
+ modelingContext: str = "",
9
+ base_url: str = "https://aihubmix.com/v1"):
10
+ self.client = OpenAI(api_key=api_key, base_url=base_url)
11
+ self.modelingContext = modelingContext
12
+
13
+ async def get_academic_question_answer(self, query: str) -> dict:
14
+ """
15
+ 获取学术问题的答案(这是对外暴露的主要接口)
16
+ """
17
+ paper_list = await self._get_academic_question_answer_list(query)
18
+ question_answer = await self._get_openai_summary(query, paper_list)
19
+ return {
20
+ "question": query,
21
+ "answer": question_answer,
22
+ "paperList": paper_list
23
+ }
24
+
25
+ @tenacity.retry(wait=tenacity.wait_fixed(1), stop=tenacity.stop_after_attempt(5))
26
+ async def _get_academic_question_answer_list(self, query: str, page: int = 1, size: int = 10) -> list:
27
+ """内部方法:获取论文列表 - 使用新的两步调用流程"""
28
+ try:
29
+ # 第一步:创建搜索线程,获取 search_id
30
+ search_url = "https://consensus.app/api/threads/"
31
+ search_payload = {
32
+ "user_message": query,
33
+ "is_pro_enabled": False,
34
+ "is_incognito": False,
35
+ "size": size,
36
+ "filters": {},
37
+ "search_mode": "SUMMARY"
38
+ }
39
+ search_headers = {
40
+ 'Referer': 'https://consensus.app',
41
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36',
42
+ 'Content-Type': 'application/json',
43
+ 'Accept': 'application/json, text/plain, */*'
44
+ }
45
+
46
+ search_response = requests.post(
47
+ search_url, json=search_payload, headers=search_headers, timeout=15)
48
+
49
+ if search_response.status_code not in [200, 201]:
50
+ # 降级到直接查询方式
51
+ return await self._fallback_direct_query(query, page, size)
52
+
53
+ search_data = search_response.json()
54
+ search_id = None
55
+
56
+ # 尝试从不同位置获取search_id
57
+ if 'search_id' in search_data:
58
+ search_id = search_data['search_id']
59
+ elif 'interactions' in search_data and len(search_data['interactions']) > 0:
60
+ first_interaction = search_data['interactions'][0]
61
+ search_id = first_interaction.get('search_id')
62
+
63
+ if not search_id:
64
+ return await self._fallback_direct_query(query, page, size)
65
+
66
+ # 第二步:使用 search_id 获取论文结果
67
+ papers_url = f"https://consensus.app/api/paper_search/{search_id}/?page={page-1}&size={size}"
68
+ papers_headers = {
69
+ 'Referer': 'https://consensus.app',
70
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36',
71
+ 'Accept': 'application/json, text/plain, */*'
72
+ }
73
+
74
+ papers_response = requests.get(
75
+ papers_url, headers=papers_headers, timeout=15)
76
+
77
+ if papers_response.status_code != 200:
78
+ return await self._fallback_direct_query(query, page, size)
79
+
80
+ papers_data = papers_response.json()
81
+ papers = papers_data.get("papers", [])
82
+
83
+ return papers[:size]
84
+
85
+ except Exception as e:
86
+ # 降级到直接查询方式
87
+ return await self._fallback_direct_query(query, page, size)
88
+
89
+ async def _fallback_direct_query(self, query: str, page: int = 1, size: int = 10) -> list:
90
+ """降级方案:直接查询论文(原来的方法)"""
91
+ try:
92
+ url = "https://consensus.app/api/paper_search/?query=" + \
93
+ query + "&page=" + str(page) + "&size=" + str(size)
94
+ payload = {}
95
+ headers = {
96
+ 'Referer': 'https://consensus.app',
97
+ 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
98
+ }
99
+ response = requests.request(
100
+ "GET", url, headers=headers, data=payload).json()
101
+
102
+ # return top 10 result in claims
103
+ top10Claims = response["papers"][:10]
104
+ return top10Claims
105
+ except Exception as e:
106
+ return []
107
+
108
+ async def _get_openai_summary(self, query: str, paper_list: list) -> str:
109
+ """内部方法:获取 OpenAI 总结"""
110
+ paperContext = ""
111
+ for paper in paper_list:
112
+ # 组织成,这是一篇名为<title>的论文,发表在<journal>上,相关的内容为<display_text>。
113
+ paperContext += "This is a paper named: " + \
114
+ paper["title"] + " published in: " + paper["journal"] + \
115
+ ". The related content is: " + paper["display_text"] + "."
116
+
117
+ completion = self.client.chat.completions.create(
118
+ model="gpt-4.1-nano",
119
+ messages=[
120
+ {"role": "system", "content": "You are a helpful AI researcher assistant. User is now conducting scientific geoscience research. The modeling history is: " + self.modelingContext +
121
+ ". He/she is now asking a question about " + query + ". And here are some information related to this question: " + paperContext + ". And your task is to summarize the information and answer the question. Please answer the question in English."},
122
+ {
123
+ "role": "user",
124
+ "content": "Besides your summary, you should not reply any other information. Below is your answer to the question based on the information provided: "
125
+ }
126
+ ]
127
+ )
128
+ return completion.choices[0].message.content