67 Commits

Author SHA1 Message Date
yangdx
2a0cff3ed6 Fix linting 2025-07-08 18:17:21 +08:00
Molion Surya
8cbba6e9db Fix #1746: [openai.py logic for streaming complete] 2025-07-08 13:25:52 +08:00
Daniel.y
c740401b7f
Merge pull request #1654 from a-bruhn/azure-env-vars
Clean up azure env vars
2025-06-26 19:11:20 +08:00
zrguo
96b9bd8cc5 fix lint 2025-06-19 14:16:24 +08:00
Alexander Bruhn
5e3970e18b
Resolve confusion between azure embedding and completion environment variables 2025-06-04 14:45:11 +02:00
eddiemaru-101
77399e051f Fix: Increase Ollama timeout values to prevent ReadTimeout errors 2025-05-30 22:43:52 +09:00
yangdx
3b9c28fae9 Fix linting 2025-05-22 10:46:03 +08:00
Martin Perez-Guevara
3d418d95c5 feat: Integrate Opik for Enhanced Observability in LlamaIndex LLM Interactions
This pull request demonstrates how to create a new Opik project when using LiteLLM for LlamaIndex-based LLM calls. The primary goal is to enable detailed tracing, monitoring, and logging of LLM interactions in a new Opik project_name, particularly when using LiteLLM as an API proxy. This enhancement allows for better debugging, performance analysis, observability when using LightRAG with LiteLLM and Opik.

**Motivation:**

As our application's reliance on Large Language Models (LLMs) grows, robust observability becomes crucial for maintaining system health, optimizing performance, and understanding usage patterns. Integrating Opik provides the following key benefits:

1.  **Improved Debugging:** Enables end-to-end tracing of requests through the LlamaIndex and LiteLLM layers, making it easier to identify and resolve issues or performance bottlenecks.
2.  **Comprehensive Performance Monitoring:** Allows for the collection of vital metrics such as LLM call latency, token usage, and error rates. This data can be filtered and analyzed within Opik using project names and tags.
3.  **Effective Cost Management:** Facilitates tracking of token consumption associated with specific requests or projects, leading to better cost control and optimization.
4.  **Deeper Usage Insights:** Provides a clearer understanding of how different components of the application or various projects are utilizing LLM capabilities.

These changes empower developers to seamlessly add observability to their LlamaIndex-based LLM workflows, especially when leveraging LiteLLM, by passing necessary Opik metadata.

**Changes Made:**

1.  **`lightrag/llm/llama_index_impl.py`:**
    *   Modified the `llama_index_complete_if_cache` function:
        *   The `**kwargs` parameter, which previously handled additional arguments, has been refined. A dedicated `chat_kwargs={}` parameter is now used to pass keyword arguments directly to the `model.achat()` method. This change ensures that vendor-specific parameters, such as LiteLLM's `litellm_params` for Opik metadata, are correctly propagated.
        *   The logic for retrieving `llm_instance` from `kwargs` was removed as `model` is now a direct parameter, simplifying the function.
    *   Updated the `llama_index_complete` function:
        *   Ensured that `**kwargs` (which may include `chat_kwargs` or other parameters intended for `llama_index_complete_if_cache`) are correctly passed down.

2.  **`examples/unofficial-sample/lightrag_llamaindex_litellm_demo.py`:**
    *   This existing demo file was updated to align with the changes in `llama_index_impl.py`.
    *   The `llm_model_func` now passes an empty `chat_kwargs={}` by default to `llama_index_complete_if_cache` if no specific chat arguments are needed, maintaining compatibility with the updated function signature. This file serves as a baseline example without Opik integration.

3.  **`examples/unofficial-sample/lightrag_llamaindex_litellm_opik_demo.py` (New File):**
    *   A new example script has been added to specifically demonstrate the integration of LightRAG with LlamaIndex, LiteLLM, and Opik for observability.
    *   The `llm_model_func` in this demo showcases how to construct the `chat_kwargs` dictionary.
    *   It includes `litellm_params` with a `metadata` field for Opik, containing `project_name` and `tags`. This provides a clear example of how to send observability data to Opik.
    *   The call to `llama_index_complete_if_cache` within `llm_model_func` passes these `chat_kwargs`, ensuring Opik metadata is included in the LiteLLM request.

These modifications provide a more robust and extensible way to pass parameters to the underlying LLM calls, specifically enabling the integration of observability tools like Opik.

Co-authored-by: Martin Perez-Guevara <8766915+MartinPerez@users.noreply.github.com>
Co-authored-by: Young Jin Kim <157011356+jidodata-ykim@users.noreply.github.com>
2025-05-20 17:47:05 +02:00
yangdx
29be2aac71 Remove tenacity from dynamic import 2025-05-14 11:30:48 +08:00
yangdx
ac2b6af97e Eliminate tenacity from dynamic import 2025-05-14 10:57:05 +08:00
yangdx
0e26cbebd0 Fix linting 2025-05-14 01:14:45 +08:00
yangdx
b836d02cac Optimize Ollama LLM driver 2025-05-14 01:13:03 +08:00
yangdx
56f82bdcd5 Ensure OpenAI connection is closed after streaming response finished 2025-05-12 17:37:28 +08:00
yangdx
c2938a71a4 Fix streaming problem for OpenAI 2025-05-09 15:54:54 +08:00
Daniel.y
3597239768
Merge pull request #1548 from maharjun/use_openai_context_manager
Use Openai Client Context Manager
2025-05-09 14:33:48 +08:00
Arjun Rao
b7eae4d7c0 Use the context manager for the openai client
This avoids issues of resource cleanup (too many open files) when dealing with massively parallel calls to the openai API since RAII in python is highly unreliable in such contexts.
2025-05-08 11:42:53 +10:00
Balaji Munusamy
c3bc0eb53b made bedrock complete generic 2025-05-02 18:25:48 +02:00
yangdx
34cc8b6a51 Fix linting 2025-04-29 17:52:07 +08:00
yangdx
f58c8276bc fix: correct retry_if_exception_type usage and improve async iterator resource management
- Corrects the syntax of retry_if_exception_type decorators to ensure proper exception handling and retry behavior
- Implements proper resource cleanup for async iterators to prevent memory leaks and potential SIGSEGV errors
2025-04-29 17:43:27 +08:00
yangdx
99522a088d Fix ollama embedding func ruturn data type bugs 2025-04-21 00:01:25 +08:00
yangdx
39540f3f8b Fix linting 2025-04-20 14:33:33 +08:00
yangdx
5f2cd871a8 Update sample code and README 2025-04-20 14:33:16 +08:00
yangdx
a418b18ed1 Fix linting 2025-04-20 11:17:51 +08:00
Enoughappens
704ef16ce3
fix streaming "list index out of range" 2025-04-19 12:57:08 +08:00
yangdx
14b4bc96ce Fix OPENAI_API_BASE not working in .env 2025-04-17 05:20:22 +08:00
Qodi
8f3068f1c0
Update openai.py
增加环境变量,支持OPENAI_API_BASE 支持中转站
2025-04-10 12:10:35 +08:00
zrguo
e17e61f58e fix lint 2025-04-03 14:44:56 +08:00
zrguo
9648300b18
Merge pull request #1208 from shane-lil/openai-client-config
feat(openai): add client configuration support to OpenAI integration
2025-04-03 17:43:57 +11:00
yangdx
80335d57a5 Fix linting 2025-03-28 21:43:47 +08:00
yangdx
491c78dac1 Improve OpenAI LLM logging with more detailed debug information 2025-03-28 21:33:59 +08:00
Shane Walker
d45dc14069
feat(openai): add client configuration support to OpenAI integration
Add support for custom client configurations in the OpenAI integration,
allowing for more flexible configuration of the AsyncOpenAI client.
This includes:

- Create a reusable helper function `create_openai_async_client`
- Add proper documentation for client configuration options
- Ensure consistent parameter precedence across the codebase
- Update the embedding function to support client configurations
- Add example script demonstrating custom client configuration usage

The changes maintain backward compatibility while providing a cleaner
and more maintainable approach to configuring OpenAI clients.
2025-03-27 15:39:39 -07:00
choizhang
8488229a29 feat: Add TokenTracker to track token usage for LLM calls 2025-03-28 01:25:15 +08:00
yangdx
dc99b714ba Update webui assets 2025-03-22 00:36:38 +08:00
Saifeddine ALOUI
3f8043ba43
Merge branch 'HKUDS:main' into main 2025-03-21 14:20:51 +01:00
Mario Vignieri
f33bcbb32c fix hf_embed torch device use MPS or CPU when CUDA is not available -macos users 2025-03-20 09:40:56 +01:00
Saifeddine ALOUI
c7d76b4cee
Create anthropic.py 2025-03-17 10:21:01 +01:00
zrguo
adba09f6c2 fix stream 2025-03-17 11:41:55 +08:00
zrguo
f5ab76dc4c fix linting 2025-03-14 14:10:59 +08:00
lvyb
87474f7b2c fix stream 2025-03-12 16:57:51 +08:00
Zhichun Wu
d77401961d
Resolve the issue with making API calls to Azure OpenAI service 2025-03-11 11:57:41 +08:00
Konrad Wojciechowski
4f76b1c23e fix AttributeError: 'NoneType' object has no attribute 'dim' 2025-02-24 10:28:15 +01:00
Pankaj Kaushal
6f09bfc970 Update LlamaIndex README: improve documentation and example paths
- Updated file paths for LlamaIndex examples
- Simplified README structure
- Corrected import statements to reflect new directory layout
- Removed outdated wrapper directory references
2025-02-20 10:33:15 +01:00
Pankaj Kaushal
173a806b9a Moved back to llm dir as per
https://github.com/HKUDS/LightRAG/pull/864#issuecomment-2669705946

- Created two new example scripts demonstrating LightRAG integration with LlamaIndex:
  - `lightrag_llamaindex_direct_demo.py`: Direct OpenAI integration
  - `lightrag_llamaindex_litellm_demo.py`: LiteLLM proxy integration
- Both examples showcase different search modes (naive, local, global, hybrid)
- Includes configuration for working directory, models, and API settings
- Demonstrates text insertion and querying using LightRAG with LlamaIndex
- removed wrapper directory and references to it
2025-02-20 10:23:01 +01:00
Pankaj Kaushal
203fdf2565 Remove LlamaIndex implementation from llm directory as per @MdNazishArmanShorthillsAI
- Deleted `lightrag/llm/llama_index_impl.py`
- Reorganization of the LlamaIndex wrapper location
2025-02-20 10:23:01 +01:00
Pankaj Kaushal
3b25e32e8d Removed verbose module-level documentation 2025-02-20 10:23:01 +01:00
Pankaj Kaushal
0b94117848 Add LlamaIndex LLM implementation module
- Implemented LlamaIndex interface for language model interactions
- Added async chat completion support
- Included embedding generation functionality
- Implemented retry mechanisms for API calls
- Added configuration and message formatting utilities
- Supports OpenAI-style message handling and external settings
2025-02-20 10:23:01 +01:00
Yannick Stephan
55cd900e8e clean comments and unused libs 2025-02-18 21:12:06 +01:00
Yannick Stephan
ea41d08b9f removed torch from requirement lightrag server 2025-02-18 20:05:51 +01:00
Yannick Stephan
2524e02428 remove tqdm and cleaned readme and ollama 2025-02-18 19:58:03 +01:00
Yannick Stephan
24ae083284 removed never used method 2025-02-18 19:38:04 +01:00