Skip to content

upgrade graphrag-sdk and move to litellm #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 1, 2025
Merged

upgrade graphrag-sdk and move to litellm #40

merged 7 commits into from
Jan 1, 2025

Conversation

gkorland
Copy link
Contributor

@gkorland gkorland commented Dec 30, 2024

Summary by CodeRabbit

  • New Features
    • Updated AI model configuration to use LiteModel for improved performance.
    • Enhanced filtering criteria in the repository retrieval process to exclude additional graph types.
    • Introduced a new configuration for Gemini API key, replacing the Google API key.
  • Dependencies
    • Upgraded graphrag-sdk to version 0.4.1.
    • Switched dependency extras from OpenAI to LiteLLM.

Copy link

vercel bot commented Dec 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
code-graph-backend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 1, 2025 0:24am

@gkorland gkorland requested a review from Copilot December 30, 2024 14:47
Copy link
Contributor

coderabbitai bot commented Dec 30, 2024

Warning

Rate limit exceeded

@gkorland has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3f564ab and e04dd42.

📒 Files selected for processing (1)
  • README.md (3 hunks)

Walkthrough

The pull request introduces changes to the project's model configuration and dependency management. In the api/llm.py file, the generative model is switched from OpenAiGenerativeModel to LiteModel, initialized with a model name retrieved from an environment variable. Simultaneously, the pyproject.toml file is updated to upgrade the graphrag-sdk dependency version and change the extras from OpenAI to LiteLLM, reflecting a shift in the project's model integration approach. Additionally, the get_repos function in api/graph.py is modified to exclude graphs ending with _schema, enhancing the filtering criteria.

Changes

File Change Summary
api/llm.py Updated _create_kg_agent to instantiate LiteModel instead of OpenAiGenerativeModel for knowledge graph agent creation.
pyproject.toml Updated graphrag-sdk dependency from ^0.3.1 with OpenAI extras to ^0.4.1 with LiteLLM extras.
api/graph.py Modified get_repos to exclude graphs ending with _schema in addition to _git.
.env.template Removed GOOGLE_API_KEY and added GEMINI_API_KEY.

Sequence Diagram

sequenceDiagram
    participant User
    participant LLMAgent as Knowledge Graph Agent
    participant LiteModel as LiteModel
    
    User->>LLMAgent: Create Knowledge Graph
    LLMAgent->>LiteModel: Initialize with model name
    LiteModel-->>LLMAgent: Model Ready
    LLMAgent-->>User: Knowledge Graph Prepared
Loading

Poem

🐰 A Rabbit's Model Migration Ode 🤖

From OpenAI to Lite's bright glow,
Our code hops forward, watch it grow!
SDK updated, extras refined,
A technological bunny-hop designed,
Hopping through models with glee in tow! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c20267a and 20488ba.

⛔ Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • api/llm.py (1 hunks)
  • pyproject.toml (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
api/llm.py

202-202: Undefined name LiteModel

(F821)

🔇 Additional comments (1)
api/llm.py (1)

208-208: Configuration logic appears sound

The updated model_config references the newly created model object. This is consistent with the dependency change to LiteModel, and no immediate issues are apparent.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

api/llm.py:4

  • [nitpick] The variable name 'model' is generic. It should be renamed to 'lite_model' to be more descriptive.
from graphrag_sdk.models.litellm import LiteModel

api/llm.py:202

  • [nitpick] The variable name 'model' is generic. It should be renamed to 'lite_model' to be more descriptive.
model = LiteModel(model_name="gemini/gemini-2.0-flash-exp")

api/llm.py:208

  • Ensure that the new behavior introduced by switching to LiteLLM is covered by tests.
model_config=KnowledgeGraphModelConfig.with_model(model)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
api/graph.py (1)

31-31: Consider a more extensible filtering approach.

While this change is valid, if the codebase expands the set of unwanted graph suffixes over time, consider centralizing these suffixes in a set or list, making the logic easier to maintain. For instance:

-graphs = [g for g in graphs if not (g.endswith('_git') or g.endswith('_schema'))]
+excluded_suffixes = ["_git", "_schema"]
+graphs = [g for g in graphs if not any(g.endswith(suffix) for suffix in excluded_suffixes)]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34f5b7b and 45d0225.

📒 Files selected for processing (1)
  • api/graph.py (1 hunks)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.env.template (1)

6-6: Add documentation for GEMINI_API_KEY

Consider adding a comment above the GEMINI_API_KEY line to explain:

  1. How to obtain the API key
  2. Any specific requirements or limitations
  3. Link to relevant documentation
+# Gemini API key from Google AI Studio (https://makersuite.google.com/app/apikey)
 GEMINI_API_KEY=<gemini_api_key>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 45d0225 and 3f564ab.

📒 Files selected for processing (1)
  • .env.template (1 hunks)
🔇 Additional comments (1)
.env.template (1)

5-6: Verify if OPENAI_API_KEY is still required

Since the PR objectives mention moving to litellm and the changes introduce GEMINI_API_KEY, please verify if OPENAI_API_KEY is still needed. If not, it should be removed to avoid confusion.

✅ Verification successful

Both OpenAI and Gemini API keys are required

Based on the codebase analysis:

  • The project uses LiteLLM as an abstraction layer to support multiple LLM providers
  • The dependencies in poetry.lock and requirements.txt show both OpenAI and LiteLLM are required dependencies
  • The code in api/llm.py shows the system is configured to use Gemini by default (model_name = os.getenv('MODEL_NAME', 'gemini/gemini-2.0-flash-exp')) but can be switched to use other providers through LiteLLM
  • Both API keys should be kept in the template to support this flexibility
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for OpenAI API key usage in the codebase
echo "Checking for OpenAI API key usage..."
rg -l "OPENAI_API_KEY"

# Search for OpenAI related imports or configurations
echo "Checking for OpenAI related code..."
rg -l "openai\." 

Length of output: 205


Script:

#!/bin/bash
# Let's try a more comprehensive search for OpenAI and LiteLLM related code
echo "Checking for OpenAI references..."
rg -i "openai"

echo -e "\nChecking for LiteLLM references..."
rg -i "litellm"

echo -e "\nChecking for environment variable usage..."
rg -i "process\.env\.(OPENAI|GEMINI)"

echo -e "\nChecking Python environment variable usage..."
rg -i "os\.environ\.(get)?.*(OPENAI|GEMINI)"

echo -e "\nLooking for configuration files..."
fd -e json -e yaml -e yml -e config

Length of output: 2580


Script:

#!/bin/bash
# Let's check the LLM implementation to understand how the API keys are used
echo "Checking LLM implementation..."
cat api/llm.py

echo -e "\nChecking for environment variable loading..."
rg -i "load_dotenv|getenv|environ" -A 3 -B 3

Length of output: 12356

@gkorland gkorland merged commit 46d4693 into main Jan 1, 2025
4 checks passed
@gkorland gkorland deleted the litellm branch January 1, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants