-
Notifications
You must be signed in to change notification settings - Fork 0
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
Introduce Narrative Field System with LLM interfaces and CI setup #11
Conversation
… the logging mechanism
Fixes #4
Refactor LanguageModel
4 refactor languagemodel 1
Simplifies EmbeddingCache after I got carried away 😁
…ge-model-and-caching-classes 9-tests-needed-for-language-model-and-caching-classes
Reviewer's Guide by SourceryThis PR introduces a new Narrative Field System (NFS) framework for analyzing and tracking narrative dynamics in social systems. The implementation includes core system components, language model interfaces, and testing infrastructure. The system uses async/await patterns for efficient processing and includes comprehensive logging and performance monitoring. Class diagram for Narrative Field SystemclassDiagram
class VectorStore {
<<abstract>>
+store(story: Story, embedding: List[float])
+find_similar(embedding: List[float], threshold: float, limit: int) List[Dict]
}
class Story {
+content: str
+context: str
+id: StoryID
+timestamp: datetime
+metadata: Optional[Dict[str, Any]]
+resonances: List[str]
+field_effects: List[Dict]
}
class FieldState {
+description: str
+patterns: List[Dict[str, Any]]
+active_resonances: List[Dict[str, Any]]
+emergence_points: List[Dict[str, Any]]
+timestamp: datetime
}
class FieldAnalysisPrompts {
+get_impact_analysis_prompt(story: Story, current_state: FieldState) str
+get_pattern_detection_prompt(stories: List[Story], current_state: FieldState) str
+get_resonance_analysis_prompt(story1: Story, story2: Story) str
}
class PerformanceMetrics {
+metrics: Dict[str, Dict[str, Any]]
+start_timer(operation: str)
+stop_timer(operation: str) float
+get_average_duration(operation: str) float
+print_summary()
+log_system_resources()
}
class PerformanceMonitor {
+metrics: List[Dict[str, float]]
+monitor_generation(llm: LanguageModel, prompt: str) Tuple[str, Dict[str, float]]
+get_performance_report() Dict[str, float]
}
class BatchProcessor {
+llm: LanguageModel
+optimal_batch_size: int
+process_batch(prompts: List[str]) List[str]
}
class ChromaStore {
+collection: Any
+store(story: Story, embedding: List[float])
+find_similar(embedding: List[float], threshold: float, limit: int) List[Dict]
}
class FieldAnalyzer {
+llm: LanguageModel
+analyze_impact(story: Story, current_state: FieldState) Dict[str, Any]
+detect_patterns(stories: List[Story], current_state: FieldState) str
}
class ResonanceDetector {
+vector_store: VectorStore
+llm: LanguageModel
+find_resonances(story: Story, threshold: float, limit: int) List[Dict[str, Any]]
+determine_resonance_type(story1: Story, story2: Story) Dict[str, Any]
}
class NarrativeField {
+_analyzer: FieldAnalyzer
+_resonance_detector: ResonanceDetector
+_vector_store: VectorStore
+_state: FieldState
+_stories: Dict[StoryID, Story]
+add_story(content: str, context: str) Story
}
VectorStore <|-- ChromaStore
NarrativeField --> FieldAnalyzer
NarrativeField --> ResonanceDetector
NarrativeField --> VectorStore
FieldAnalyzer --> LanguageModel
ResonanceDetector --> LanguageModel
ResonanceDetector --> VectorStore
BatchProcessor --> LanguageModel
PerformanceMonitor --> LanguageModel
Story --> FieldState
FieldAnalysisPrompts --> Story
FieldAnalysisPrompts --> FieldState
PerformanceMetrics --> Story
PerformanceMetrics --> FieldState
Class diagram for Language ModelsclassDiagram
class LanguageModel {
<<abstract>>
+generate(prompt: str) str
+_generate_embedding(text: str) List[float]
+generate_embedding(text: str) List[float]
+cleanup()
}
class OllamaInterface {
+generate(prompt: str) str
+_generate_embedding(text: str) List[float]
}
class LlamaInterface {
+generate(prompt: str) str
+_generate_embedding(text: str) List[float]
+cleanup()
}
LanguageModel <|-- OllamaInterface
LanguageModel <|-- LlamaInterface
OllamaInterface --> EmbeddingCache
LlamaInterface --> EmbeddingCache
LanguageModel --> EmbeddingCache
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @leonvanbokhorst - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding more test coverage, particularly for the NarrativeField and VectorStore components which currently lack tests.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟡 Testing: 2 issues found
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@sourcery-ai merge PR |
Summary by Sourcery
Introduce a framework for narrative analysis and tracking using language models, with performance monitoring and logging. Implement interfaces for Ollama and Llama models, and add a caching mechanism for embeddings. Set up CI workflow and logging configuration, and add unit tests for new components.
New Features:
Enhancements:
Build:
CI:
Tests: