yangdx commited on
Commit
4aad236
·
1 Parent(s): a076e42

Update webui assets

Browse files
lightrag/api/webui/assets/{index-C-CHRwmZ.js → index-BItOVH8B.js} RENAMED
Binary files a/lightrag/api/webui/assets/index-C-CHRwmZ.js and b/lightrag/api/webui/assets/index-BItOVH8B.js differ
 
lightrag/api/webui/index.html CHANGED
Binary files a/lightrag/api/webui/index.html and b/lightrag/api/webui/index.html differ
 
lightrag/llm/anthropic.py CHANGED
@@ -38,11 +38,14 @@ from lightrag.utils import (
38
  )
39
  from lightrag.api import __api_version__
40
 
 
41
  # Custom exception for retry mechanism
42
  class InvalidResponseError(Exception):
43
  """Custom exception class for triggering retry mechanism"""
 
44
  pass
45
 
 
46
  # Core Anthropic completion function with retry
47
  @retry(
48
  stop=stop_after_attempt(3),
@@ -96,10 +99,7 @@ async def anthropic_complete_if_cache(
96
 
97
  try:
98
  response = await anthropic_async_client.messages.create(
99
- model=model,
100
- messages=messages,
101
- stream=True,
102
- **kwargs
103
  )
104
  except APIConnectionError as e:
105
  logger.error(f"Anthropic API Connection Error: {e}")
@@ -119,7 +119,11 @@ async def anthropic_complete_if_cache(
119
  async def stream_response():
120
  try:
121
  async for event in response:
122
- content = event.delta.text if hasattr(event, "delta") and event.delta.text else None
 
 
 
 
123
  if content is None:
124
  continue
125
  if r"\u" in content:
@@ -131,6 +135,7 @@ async def anthropic_complete_if_cache(
131
 
132
  return stream_response()
133
 
 
134
  # Generic Anthropic completion function
135
  async def anthropic_complete(
136
  prompt: str,
@@ -149,6 +154,7 @@ async def anthropic_complete(
149
  **kwargs,
150
  )
151
 
 
152
  # Claude 3 Opus specific completion
153
  async def claude_3_opus_complete(
154
  prompt: str,
@@ -166,6 +172,7 @@ async def claude_3_opus_complete(
166
  **kwargs,
167
  )
168
 
 
169
  # Claude 3 Sonnet specific completion
170
  async def claude_3_sonnet_complete(
171
  prompt: str,
@@ -183,6 +190,7 @@ async def claude_3_sonnet_complete(
183
  **kwargs,
184
  )
185
 
 
186
  # Claude 3 Haiku specific completion
187
  async def claude_3_haiku_complete(
188
  prompt: str,
@@ -200,6 +208,7 @@ async def claude_3_haiku_complete(
200
  **kwargs,
201
  )
202
 
 
203
  # Embedding function (placeholder, as Anthropic does not provide embeddings)
204
  @retry(
205
  stop=stop_after_attempt(3),
@@ -216,13 +225,13 @@ async def anthropic_embed(
216
  ) -> np.ndarray:
217
  """
218
  Generate embeddings using Voyage AI since Anthropic doesn't provide native embedding support.
219
-
220
  Args:
221
  texts: List of text strings to embed
222
  model: Voyage AI model name (e.g., "voyage-3", "voyage-3-large", "voyage-code-3")
223
  base_url: Optional custom base URL (not used for Voyage AI)
224
  api_key: API key for Voyage AI (defaults to VOYAGE_API_KEY environment variable)
225
-
226
  Returns:
227
  numpy array of shape (len(texts), embedding_dimension) containing the embeddings
228
  """
@@ -230,42 +239,73 @@ async def anthropic_embed(
230
  api_key = os.environ.get("VOYAGE_API_KEY")
231
  if not api_key:
232
  logger.error("VOYAGE_API_KEY environment variable not set")
233
- raise ValueError("VOYAGE_API_KEY environment variable is required for embeddings")
 
 
234
 
235
  try:
236
  # Initialize Voyage AI client
237
  voyage_client = voyageai.Client(api_key=api_key)
238
-
239
  # Get embeddings
240
  result = voyage_client.embed(
241
  texts,
242
  model=model,
243
- input_type="document" # Assuming document context; could be made configurable
244
  )
245
-
246
  # Convert list of embeddings to numpy array
247
  embeddings = np.array(result.embeddings, dtype=np.float32)
248
-
249
  logger.debug(f"Generated embeddings for {len(texts)} texts using {model}")
250
  verbose_debug(f"Embedding shape: {embeddings.shape}")
251
-
252
  return embeddings
253
 
254
  except Exception as e:
255
  logger.error(f"Voyage AI embedding failed: {str(e)}")
256
  raise
257
 
 
258
  # Optional: a helper function to get available embedding models
259
  def get_available_embedding_models() -> dict[str, dict]:
260
  """
261
  Returns a dictionary of available Voyage AI embedding models and their properties.
262
  """
263
  return {
264
- "voyage-3-large": {"context_length": 32000, "dimension": 1024, "description": "Best general-purpose and multilingual"},
265
- "voyage-3": {"context_length": 32000, "dimension": 1024, "description": "General-purpose and multilingual"},
266
- "voyage-3-lite": {"context_length": 32000, "dimension": 512, "description": "Optimized for latency and cost"},
267
- "voyage-code-3": {"context_length": 32000, "dimension": 1024, "description": "Optimized for code"},
268
- "voyage-finance-2": {"context_length": 32000, "dimension": 1024, "description": "Optimized for finance"},
269
- "voyage-law-2": {"context_length": 16000, "dimension": 1024, "description": "Optimized for legal"},
270
- "voyage-multimodal-3": {"context_length": 32000, "dimension": 1024, "description": "Multimodal text and images"},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  }
 
38
  )
39
  from lightrag.api import __api_version__
40
 
41
+
42
  # Custom exception for retry mechanism
43
  class InvalidResponseError(Exception):
44
  """Custom exception class for triggering retry mechanism"""
45
+
46
  pass
47
 
48
+
49
  # Core Anthropic completion function with retry
50
  @retry(
51
  stop=stop_after_attempt(3),
 
99
 
100
  try:
101
  response = await anthropic_async_client.messages.create(
102
+ model=model, messages=messages, stream=True, **kwargs
 
 
 
103
  )
104
  except APIConnectionError as e:
105
  logger.error(f"Anthropic API Connection Error: {e}")
 
119
  async def stream_response():
120
  try:
121
  async for event in response:
122
+ content = (
123
+ event.delta.text
124
+ if hasattr(event, "delta") and event.delta.text
125
+ else None
126
+ )
127
  if content is None:
128
  continue
129
  if r"\u" in content:
 
135
 
136
  return stream_response()
137
 
138
+
139
  # Generic Anthropic completion function
140
  async def anthropic_complete(
141
  prompt: str,
 
154
  **kwargs,
155
  )
156
 
157
+
158
  # Claude 3 Opus specific completion
159
  async def claude_3_opus_complete(
160
  prompt: str,
 
172
  **kwargs,
173
  )
174
 
175
+
176
  # Claude 3 Sonnet specific completion
177
  async def claude_3_sonnet_complete(
178
  prompt: str,
 
190
  **kwargs,
191
  )
192
 
193
+
194
  # Claude 3 Haiku specific completion
195
  async def claude_3_haiku_complete(
196
  prompt: str,
 
208
  **kwargs,
209
  )
210
 
211
+
212
  # Embedding function (placeholder, as Anthropic does not provide embeddings)
213
  @retry(
214
  stop=stop_after_attempt(3),
 
225
  ) -> np.ndarray:
226
  """
227
  Generate embeddings using Voyage AI since Anthropic doesn't provide native embedding support.
228
+
229
  Args:
230
  texts: List of text strings to embed
231
  model: Voyage AI model name (e.g., "voyage-3", "voyage-3-large", "voyage-code-3")
232
  base_url: Optional custom base URL (not used for Voyage AI)
233
  api_key: API key for Voyage AI (defaults to VOYAGE_API_KEY environment variable)
234
+
235
  Returns:
236
  numpy array of shape (len(texts), embedding_dimension) containing the embeddings
237
  """
 
239
  api_key = os.environ.get("VOYAGE_API_KEY")
240
  if not api_key:
241
  logger.error("VOYAGE_API_KEY environment variable not set")
242
+ raise ValueError(
243
+ "VOYAGE_API_KEY environment variable is required for embeddings"
244
+ )
245
 
246
  try:
247
  # Initialize Voyage AI client
248
  voyage_client = voyageai.Client(api_key=api_key)
249
+
250
  # Get embeddings
251
  result = voyage_client.embed(
252
  texts,
253
  model=model,
254
+ input_type="document", # Assuming document context; could be made configurable
255
  )
256
+
257
  # Convert list of embeddings to numpy array
258
  embeddings = np.array(result.embeddings, dtype=np.float32)
259
+
260
  logger.debug(f"Generated embeddings for {len(texts)} texts using {model}")
261
  verbose_debug(f"Embedding shape: {embeddings.shape}")
262
+
263
  return embeddings
264
 
265
  except Exception as e:
266
  logger.error(f"Voyage AI embedding failed: {str(e)}")
267
  raise
268
 
269
+
270
  # Optional: a helper function to get available embedding models
271
  def get_available_embedding_models() -> dict[str, dict]:
272
  """
273
  Returns a dictionary of available Voyage AI embedding models and their properties.
274
  """
275
  return {
276
+ "voyage-3-large": {
277
+ "context_length": 32000,
278
+ "dimension": 1024,
279
+ "description": "Best general-purpose and multilingual",
280
+ },
281
+ "voyage-3": {
282
+ "context_length": 32000,
283
+ "dimension": 1024,
284
+ "description": "General-purpose and multilingual",
285
+ },
286
+ "voyage-3-lite": {
287
+ "context_length": 32000,
288
+ "dimension": 512,
289
+ "description": "Optimized for latency and cost",
290
+ },
291
+ "voyage-code-3": {
292
+ "context_length": 32000,
293
+ "dimension": 1024,
294
+ "description": "Optimized for code",
295
+ },
296
+ "voyage-finance-2": {
297
+ "context_length": 32000,
298
+ "dimension": 1024,
299
+ "description": "Optimized for finance",
300
+ },
301
+ "voyage-law-2": {
302
+ "context_length": 16000,
303
+ "dimension": 1024,
304
+ "description": "Optimized for legal",
305
+ },
306
+ "voyage-multimodal-3": {
307
+ "context_length": 32000,
308
+ "dimension": 1024,
309
+ "description": "Multimodal text and images",
310
+ },
311
  }