Skip to content
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

Pass source: to the Langchain::Chunk #538

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

andreibondarev
Copy link
Collaborator

No description provided.

data = Langchain::Loader.new(path, options, chunker: chunker)&.load&.chunks
data.map { |chunk| chunk.text }
end
options[:source] ||= path.to_s

Choose a reason for hiding this comment

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

If I pass in an array, each path might have it's own metadata / source. I would like to see this be able to take a string or a hash in the array. I hope this suggestion helps!

Suggested change
options[:source] ||= path.to_s
if path.is_a?(Hash)
raise ArgumentError "Path hashes must have keys :path, :source" unless (path.keys & [:path, :source] == [:path, :source])
options[:source] ||= path[:source]
path = path[:path]
end
raise ArgumentError "Paths must be strings or hashes with keys :path, :source" unless path.is_a?(String)
options[:source] ||= path.to_s

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.

None yet

2 participants