Packages
langchain
0.8.2
0.9.2
0.9.1
0.9.0
0.8.14
0.8.13
0.8.12
0.8.11
0.8.10
0.8.9
0.8.8
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.4.0-rc.3
0.4.0-rc.2
0.4.0-rc.1
0.4.0-rc.0
0.3.3
0.3.2
0.3.1
0.3.0
0.3.0-rc.2
0.3.0-rc.1
0.3.0-rc.0
0.2.0
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Elixir implementation of a LangChain style framework that lets Elixir projects integrate with and leverage LLMs.
Current section
Files
Jump to
Current section
Files
lib/message/citation_source.ex
defmodule LangChain.Message.CitationSource do
@moduledoc """
Represents the source of a citation - where the cited information came from.
## Source Types
- `:web` - A URL-based web source (search results, web pages)
- `:document` - A document provided in the request (Anthropic documents,
OpenAI files)
- `:place` - A geographic location (Google Maps)
"""
use Ecto.Schema
import Ecto.Changeset
alias LangChain.LangChainError
alias __MODULE__
@primary_key false
embedded_schema do
field :type, Ecto.Enum, values: [:web, :document, :place]
field :title, :string
field :url, :string
field :document_id, :string
# Provider-specific data. String keys for JSON serialization.
field :metadata, :map, default: %{}
end
@type t :: %CitationSource{}
@create_fields [:type, :title, :url, :document_id, :metadata]
@doc false
def changeset(source, attrs) do
source
|> cast(attrs, @create_fields)
|> validate_required([:type])
end
@spec new(map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
def new(attrs \\ %{}) do
%CitationSource{}
|> changeset(attrs)
|> apply_action(:insert)
end
@spec new!(map()) :: t() | no_return()
def new!(attrs \\ %{}) do
case new(attrs) do
{:ok, struct} -> struct
{:error, changeset} -> raise LangChainError, changeset
end
end
end