-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add LLM Support #160
Add LLM Support #160
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe changes introduce a command-line interface (CLI) for querying a graph database focused on supply chain security artifacts. The new CLI, encapsulated in Changes
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (9)
cmd/server/server.go (2)
36-37
: Ensure consistent field naming in theoptions
structThe field
UseOpenAILLM
has inconsistent capitalization. For readability and to follow Go naming conventions, consider renaming it toUseOpenAiLLM
orUseOpenAILlm
.Apply this diff:
type options struct { // ... - UseOpenAILLM bool + UseOpenAiLLM bool VectorDBPath string }Don't forget to update all references to this field throughout the codebase.
60-61
: Align flag names with field names for clarityIn the
AddFlags
method, ensure that the flag names accurately reflect the field names. Since the field is namedUseOpenAiLLM
, consider renaming the flag to--use-openai-llm
for consistency.Apply this diff:
cmd.Flags().BoolVar(&o.UseOpenAILLM, "use-openai-llm", false, "Use OpenAI LLM for graph analysis")Adjust the variable name if you rename the field as suggested.
pkg/storages/sql.go (1)
282-309
: Optimize batch processing logic inSaveCaches
methodThe current implementation of batching in
SaveCaches
is functional but can be optimized for clarity and efficiency. Consider the following improvements:
- Use
min(i + batchSize, len(caches))
to calculate the end index without an explicitif
statement.- Preallocate the
kvCaches
slice withbatchSize
to improve memory allocation.Apply this diff:
const batchSize = 500 // Safe batch size considering SQLite's limits // Process caches in batches for i := 0; i < len(caches); i += batchSize { - end := i + batchSize - if end > len(caches) { - end = len(caches) - } + end := int(math.Min(float64(i+batchSize), float64(len(caches)))) batch := caches[i:end] kvCaches := make([]KVStore, 0, len(batch)) for _, cache := range batch { cacheKey := fmt.Sprintf("%s%d", CacheKeyPrefix, cache.ID) data, err := cache.MarshalJSON() if err != nil { return fmt.Errorf("failed to marshal cache: %w", err) } kvCaches = append(kvCaches, KVStore{ Key: cacheKey, Value: string(data), }) } if err := s.DB.Save(&kvCaches).Error; err != nil { return fmt.Errorf("failed to save caches batch: %w", err) } }cmd/llm/llm.go (4)
61-61
: Remove unused fieldsaveQuery
The field
saveQuery
is declared but not used anywhere in the code. To keep the codebase clean, consider removing it.Apply this diff:
type options struct { maxOutput int showInfo bool - saveQuery string addr string // ... }
🧰 Tools
🪛 golangci-lint (1.62.2)
61-61: field
saveQuery
is unused(unused)
82-84
: Handle missingOPENAI_API_KEY
environment variable gracefullyInstead of returning an error when the
OPENAI_API_KEY
is not set, consider providing a more user-friendly message or guidance on how to set it.Apply this diff:
if os.Getenv("OPENAI_API_KEY") == "" { - return fmt.Errorf("OPENAI_API_KEY environment variable is not set") + fmt.Println("Please set the OPENAI_API_KEY environment variable to use this feature.") + return nil }
139-143
: Trim and validate user input before processingAdd input validation to handle empty inputs or potential unintended commands.
Apply this diff:
input = strings.TrimSpace(input) + if input == "" { + fmt.Println("Input cannot be empty. Please enter a valid query.") + continue + } if strings.ToLower(input) == "exit" { fmt.Println("Ending chat session. Goodbye!") return nil }
278-285
: Refine assistant's feedback to the userThe assistant's feedback message could be more conversational and helpful by directly incorporating the query result without a repetitive prompt.
Apply this diff:
feedbackMsg := fmt.Sprintf("%s", queryResult) messages = append(messages, openai.ChatCompletionMessage{ Role: openai.ChatMessageRoleAssistant, Content: feedbackMsg, })cmd/root/root.go (1)
58-58
: Maintain alphabetical order of commands inrootCmd
For better readability and organization, consider adding the
llm
command in alphabetical order within the list of commands.Apply this diff:
rootCmd.AddCommand(cache.New()) + rootCmd.AddCommand(llm.New()) rootCmd.AddCommand(leaderboard.New()) rootCmd.AddCommand(query.New()) rootCmd.AddCommand(server.New())
go.mod (1)
52-54
: Group new dependencies with existing onesFor clarity, place the new direct dependencies (
chromem-go
andgo-openai
) within the existingrequire
block, keeping indirect dependencies separate.Apply this diff:
require ( // Existing dependencies... + github.com/philippgille/chromem-go v0.7.0 + github.com/sashabaranov/go-openai v1.36.0 ) require ( // Indirect dependencies... )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
go.sum
is excluded by!**/*.sum
📒 Files selected for processing (5)
cmd/llm/llm.go
(1 hunks)cmd/root/root.go
(2 hunks)cmd/server/server.go
(4 hunks)go.mod
(1 hunks)pkg/storages/sql.go
(1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
cmd/llm/llm.go
61-61: field saveQuery
is unused
(unused)
- Added an OpenAI llm to the CLI, that can run leaderboards, queries, and globsearchs all from user input, this is also a chat session, so the llm, can create queries based on the conversation - Batched SQLite so that it does not overflow on large amounts of data Signed-off-by: neilnaveen <[email protected]>
Signed-off-by: naveensrinivasan <[email protected]>
9d87ed8
to
c8f8522
Compare
Codecov ReportAttention: Patch coverage is
|
Summary by CodeRabbit
New Features
Bug Fixes
Chores