lanny xu commited on
Commit
c848868
·
1 Parent(s): 7c05a1b

delete urls

Browse files
Files changed (1) hide show
  1. KAGGLE_FIX_OLLAMA_CONNECTION.py +28 -3
KAGGLE_FIX_OLLAMA_CONNECTION.py CHANGED
@@ -106,6 +106,9 @@ def test_generation():
106
  print("🧪 测试文本生成")
107
  print("="*70)
108
 
 
 
 
109
  try:
110
  response = requests.post(
111
  'http://localhost:11434/api/generate',
@@ -114,7 +117,7 @@ def test_generation():
114
  "prompt": "Say 'Hello' in one word",
115
  "stream": False
116
  },
117
- timeout=30
118
  )
119
 
120
  if response.status_code == 200:
@@ -125,6 +128,10 @@ def test_generation():
125
  else:
126
  print(f" ❌ 生成失败: {response.status_code}")
127
  return False
 
 
 
 
128
  except Exception as e:
129
  print(f" ❌ 生成错误: {e}")
130
  return False
@@ -160,8 +167,9 @@ def main():
160
  print("="*70)
161
 
162
  if is_running:
163
- print("""
164
- ✅ Ollama 服务正常!现在可以运行 GraphRAG 了
 
165
 
166
  📝 在 Kaggle Notebook 中运行:
167
 
@@ -182,6 +190,23 @@ indexer = GraphRAGIndexer(
182
 
183
  graph = indexer.index_documents(doc_splits)
184
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  else:
186
  print("""
187
  ❌ Ollama 服务仍然异常
 
106
  print("🧪 测试文本生成")
107
  print("="*70)
108
 
109
+ print("\n ℹ️ 首次调用会加载模型到内存,需要 30-60 秒...")
110
+ print(" ⏳ 请耐心等待...\n")
111
+
112
  try:
113
  response = requests.post(
114
  'http://localhost:11434/api/generate',
 
117
  "prompt": "Say 'Hello' in one word",
118
  "stream": False
119
  },
120
+ timeout=120 # 增加到 120 秒,首次加载模型需要时间
121
  )
122
 
123
  if response.status_code == 200:
 
128
  else:
129
  print(f" ❌ 生成失败: {response.status_code}")
130
  return False
131
+ except requests.exceptions.Timeout:
132
+ print(f" ⚠️ 生成超时(但这可能是模型加载中)")
133
+ print(f" 💡 建议:再等待 30 秒后重试")
134
+ return False
135
  except Exception as e:
136
  print(f" ❌ 生成错误: {e}")
137
  return False
 
167
  print("="*70)
168
 
169
  if is_running:
170
+ if test_generation():
171
+ print("""
172
+ ✅ Ollama 服务完全就绪!现在可以运行 GraphRAG 了
173
 
174
  📝 在 Kaggle Notebook 中运行:
175
 
 
190
 
191
  graph = indexer.index_documents(doc_splits)
192
  """)
193
+ else:
194
+ print("""
195
+ ⚠️ Ollama 服务运行中,但模型可能还在加载
196
+
197
+ 💡 解决方案:
198
+
199
+ 1. 等待 30-60 秒让模型完全加载
200
+ 2. 再次运行此脚本验证
201
+ 3. 或者直接运行一次简单测试:
202
+ !curl http://localhost:11434/api/generate -d '{
203
+ "model": "mistral",
204
+ "prompt": "Hello",
205
+ "stream": false
206
+ }'
207
+
208
+ 4. 如果上述测试成功,就可以运行 GraphRAG 了
209
+ """)
210
  else:
211
  print("""
212
  ❌ Ollama 服务仍然异常