Releases: yohasebe/ruby-spacy
Releases · yohasebe/ruby-spacy
v0.4.0
What's New
Block-based OpenAI API
Language#with_openai: A new block-based API for OpenAI integration. Yields anOpenAIHelperinstance that is configured once and reused for all calls within the block, making it efficient for batch processing withpipe.Doc#linguistic_summary: Generates a JSON summary of spaCy's linguistic analysis (tokens, entities, noun chunks, sentences) that can be passed directly to LLMs as context. Sections and token attributes are fully customizable.OpenAIHelper#chat: Convenientsystem:/user:shortcuts for building messages, withraw:option for full API response access.OpenAIHelper#embeddings: Standalone embeddings method that accepts text directly.
Quality Improvements
- Bug fix:
Doc#entsnow returns properSpanobjects instead of raw Python objects - Security: Model name validation in
Language#initializeto prevent injection - OpenAI: Temperature handling for o-series models, 429 retry with exponential backoff, client reuse,
dimensions/response_formatparameters, tool call depth limit - Code quality: Unified
mapusage across 17 methods, improvedrespond_to_missing?withpy_hasattr?, optimizedDoc#initializeretry loop
New Features
Token#idxfor character offset accessSpan#to_sfor string representationLanguage#memory_zonefor spaCy 3.8+ memory managementPhraseMatchersupport viaLanguage#phrase_matcherinstance_variables_to_inspectfor Ruby 4.0+ compatibility
Dependencies
- Added
base64gem (Ruby 3.4+) - Added
fiddlegem (Ruby 4.0+)
Tests
- 24 new tests added (81 total)
- All passing on Ruby 3.4.6 and Ruby 4.0.1
Example
nlp = Spacy::Language.new("en_core_web_sm")
texts = ["The bank approved the loan.", "I sat on the river bank."]
nlp.with_openai(model: "gpt-5-mini") do |ai|
nlp.pipe(texts).each do |doc|
result = ai.chat(
system: "Analyze using the linguistic data.",
user: doc.linguistic_summary
)
puts result
end
end