Update webui assets

This commit is contained in:
yangdx
2025-03-22 00:36:38 +08:00
parent b21c32645d
commit dc99b714ba
3 changed files with 176 additions and 98 deletions

File diff suppressed because one or more lines are too long

View File

@@ -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>

View File

@@ -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),
@@ -230,7 +239,9 @@ 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
@@ -240,7 +251,7 @@ async def anthropic_embed(
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
@@ -255,17 +266,46 @@ async def anthropic_embed(
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",
},
} }