Update webui assets
This commit is contained in:
File diff suppressed because one or more lines are too long
2
lightrag/api/webui/index.html
generated
2
lightrag/api/webui/index.html
generated
@@ -8,7 +8,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="logo.png" />
|
<link rel="icon" type="image/svg+xml" href="logo.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Lightrag</title>
|
<title>Lightrag</title>
|
||||||
<script type="module" crossorigin src="/webui/assets/index-C-CHRwmZ.js"></script>
|
<script type="module" crossorigin src="/webui/assets/index-BItOVH8B.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/webui/assets/index-BViPRMGA.css">
|
<link rel="stylesheet" crossorigin href="/webui/assets/index-BViPRMGA.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@@ -38,11 +38,14 @@ from lightrag.utils import (
|
|||||||
)
|
)
|
||||||
from lightrag.api import __api_version__
|
from lightrag.api import __api_version__
|
||||||
|
|
||||||
|
|
||||||
# Custom exception for retry mechanism
|
# Custom exception for retry mechanism
|
||||||
class InvalidResponseError(Exception):
|
class InvalidResponseError(Exception):
|
||||||
"""Custom exception class for triggering retry mechanism"""
|
"""Custom exception class for triggering retry mechanism"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Core Anthropic completion function with retry
|
# Core Anthropic completion function with retry
|
||||||
@retry(
|
@retry(
|
||||||
stop=stop_after_attempt(3),
|
stop=stop_after_attempt(3),
|
||||||
@@ -96,10 +99,7 @@ async def anthropic_complete_if_cache(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
response = await anthropic_async_client.messages.create(
|
response = await anthropic_async_client.messages.create(
|
||||||
model=model,
|
model=model, messages=messages, stream=True, **kwargs
|
||||||
messages=messages,
|
|
||||||
stream=True,
|
|
||||||
**kwargs
|
|
||||||
)
|
)
|
||||||
except APIConnectionError as e:
|
except APIConnectionError as e:
|
||||||
logger.error(f"Anthropic API Connection Error: {e}")
|
logger.error(f"Anthropic API Connection Error: {e}")
|
||||||
@@ -119,7 +119,11 @@ async def anthropic_complete_if_cache(
|
|||||||
async def stream_response():
|
async def stream_response():
|
||||||
try:
|
try:
|
||||||
async for event in response:
|
async for event in response:
|
||||||
content = event.delta.text if hasattr(event, "delta") and event.delta.text else None
|
content = (
|
||||||
|
event.delta.text
|
||||||
|
if hasattr(event, "delta") and event.delta.text
|
||||||
|
else None
|
||||||
|
)
|
||||||
if content is None:
|
if content is None:
|
||||||
continue
|
continue
|
||||||
if r"\u" in content:
|
if r"\u" in content:
|
||||||
@@ -131,6 +135,7 @@ async def anthropic_complete_if_cache(
|
|||||||
|
|
||||||
return stream_response()
|
return stream_response()
|
||||||
|
|
||||||
|
|
||||||
# Generic Anthropic completion function
|
# Generic Anthropic completion function
|
||||||
async def anthropic_complete(
|
async def anthropic_complete(
|
||||||
prompt: str,
|
prompt: str,
|
||||||
@@ -149,6 +154,7 @@ async def anthropic_complete(
|
|||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Claude 3 Opus specific completion
|
# Claude 3 Opus specific completion
|
||||||
async def claude_3_opus_complete(
|
async def claude_3_opus_complete(
|
||||||
prompt: str,
|
prompt: str,
|
||||||
@@ -166,6 +172,7 @@ async def claude_3_opus_complete(
|
|||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Claude 3 Sonnet specific completion
|
# Claude 3 Sonnet specific completion
|
||||||
async def claude_3_sonnet_complete(
|
async def claude_3_sonnet_complete(
|
||||||
prompt: str,
|
prompt: str,
|
||||||
@@ -183,6 +190,7 @@ async def claude_3_sonnet_complete(
|
|||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Claude 3 Haiku specific completion
|
# Claude 3 Haiku specific completion
|
||||||
async def claude_3_haiku_complete(
|
async def claude_3_haiku_complete(
|
||||||
prompt: str,
|
prompt: str,
|
||||||
@@ -200,6 +208,7 @@ async def claude_3_haiku_complete(
|
|||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Embedding function (placeholder, as Anthropic does not provide embeddings)
|
# Embedding function (placeholder, as Anthropic does not provide embeddings)
|
||||||
@retry(
|
@retry(
|
||||||
stop=stop_after_attempt(3),
|
stop=stop_after_attempt(3),
|
||||||
@@ -216,13 +225,13 @@ async def anthropic_embed(
|
|||||||
) -> np.ndarray:
|
) -> np.ndarray:
|
||||||
"""
|
"""
|
||||||
Generate embeddings using Voyage AI since Anthropic doesn't provide native embedding support.
|
Generate embeddings using Voyage AI since Anthropic doesn't provide native embedding support.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
texts: List of text strings to embed
|
texts: List of text strings to embed
|
||||||
model: Voyage AI model name (e.g., "voyage-3", "voyage-3-large", "voyage-code-3")
|
model: Voyage AI model name (e.g., "voyage-3", "voyage-3-large", "voyage-code-3")
|
||||||
base_url: Optional custom base URL (not used for Voyage AI)
|
base_url: Optional custom base URL (not used for Voyage AI)
|
||||||
api_key: API key for Voyage AI (defaults to VOYAGE_API_KEY environment variable)
|
api_key: API key for Voyage AI (defaults to VOYAGE_API_KEY environment variable)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
numpy array of shape (len(texts), embedding_dimension) containing the embeddings
|
numpy array of shape (len(texts), embedding_dimension) containing the embeddings
|
||||||
"""
|
"""
|
||||||
@@ -230,42 +239,73 @@ async def anthropic_embed(
|
|||||||
api_key = os.environ.get("VOYAGE_API_KEY")
|
api_key = os.environ.get("VOYAGE_API_KEY")
|
||||||
if not api_key:
|
if not api_key:
|
||||||
logger.error("VOYAGE_API_KEY environment variable not set")
|
logger.error("VOYAGE_API_KEY environment variable not set")
|
||||||
raise ValueError("VOYAGE_API_KEY environment variable is required for embeddings")
|
raise ValueError(
|
||||||
|
"VOYAGE_API_KEY environment variable is required for embeddings"
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Initialize Voyage AI client
|
# Initialize Voyage AI client
|
||||||
voyage_client = voyageai.Client(api_key=api_key)
|
voyage_client = voyageai.Client(api_key=api_key)
|
||||||
|
|
||||||
# Get embeddings
|
# Get embeddings
|
||||||
result = voyage_client.embed(
|
result = voyage_client.embed(
|
||||||
texts,
|
texts,
|
||||||
model=model,
|
model=model,
|
||||||
input_type="document" # Assuming document context; could be made configurable
|
input_type="document", # Assuming document context; could be made configurable
|
||||||
)
|
)
|
||||||
|
|
||||||
# Convert list of embeddings to numpy array
|
# Convert list of embeddings to numpy array
|
||||||
embeddings = np.array(result.embeddings, dtype=np.float32)
|
embeddings = np.array(result.embeddings, dtype=np.float32)
|
||||||
|
|
||||||
logger.debug(f"Generated embeddings for {len(texts)} texts using {model}")
|
logger.debug(f"Generated embeddings for {len(texts)} texts using {model}")
|
||||||
verbose_debug(f"Embedding shape: {embeddings.shape}")
|
verbose_debug(f"Embedding shape: {embeddings.shape}")
|
||||||
|
|
||||||
return embeddings
|
return embeddings
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Voyage AI embedding failed: {str(e)}")
|
logger.error(f"Voyage AI embedding failed: {str(e)}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
# Optional: a helper function to get available embedding models
|
# Optional: a helper function to get available embedding models
|
||||||
def get_available_embedding_models() -> dict[str, dict]:
|
def get_available_embedding_models() -> dict[str, dict]:
|
||||||
"""
|
"""
|
||||||
Returns a dictionary of available Voyage AI embedding models and their properties.
|
Returns a dictionary of available Voyage AI embedding models and their properties.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
"voyage-3-large": {"context_length": 32000, "dimension": 1024, "description": "Best general-purpose and multilingual"},
|
"voyage-3-large": {
|
||||||
"voyage-3": {"context_length": 32000, "dimension": 1024, "description": "General-purpose and multilingual"},
|
"context_length": 32000,
|
||||||
"voyage-3-lite": {"context_length": 32000, "dimension": 512, "description": "Optimized for latency and cost"},
|
"dimension": 1024,
|
||||||
"voyage-code-3": {"context_length": 32000, "dimension": 1024, "description": "Optimized for code"},
|
"description": "Best general-purpose and multilingual",
|
||||||
"voyage-finance-2": {"context_length": 32000, "dimension": 1024, "description": "Optimized for finance"},
|
},
|
||||||
"voyage-law-2": {"context_length": 16000, "dimension": 1024, "description": "Optimized for legal"},
|
"voyage-3": {
|
||||||
"voyage-multimodal-3": {"context_length": 32000, "dimension": 1024, "description": "Multimodal text and images"},
|
"context_length": 32000,
|
||||||
|
"dimension": 1024,
|
||||||
|
"description": "General-purpose and multilingual",
|
||||||
|
},
|
||||||
|
"voyage-3-lite": {
|
||||||
|
"context_length": 32000,
|
||||||
|
"dimension": 512,
|
||||||
|
"description": "Optimized for latency and cost",
|
||||||
|
},
|
||||||
|
"voyage-code-3": {
|
||||||
|
"context_length": 32000,
|
||||||
|
"dimension": 1024,
|
||||||
|
"description": "Optimized for code",
|
||||||
|
},
|
||||||
|
"voyage-finance-2": {
|
||||||
|
"context_length": 32000,
|
||||||
|
"dimension": 1024,
|
||||||
|
"description": "Optimized for finance",
|
||||||
|
},
|
||||||
|
"voyage-law-2": {
|
||||||
|
"context_length": 16000,
|
||||||
|
"dimension": 1024,
|
||||||
|
"description": "Optimized for legal",
|
||||||
|
},
|
||||||
|
"voyage-multimodal-3": {
|
||||||
|
"context_length": 32000,
|
||||||
|
"dimension": 1024,
|
||||||
|
"description": "Multimodal text and images",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user