Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
orthagonal committed Apr 30, 2023
1 parent c90b59f commit 581c032
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
63 changes: 55 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
# Langchainex
# LangchainEx

**TODO: Add description**
- [LangchainEx](#langchainex)
- [Overview](#overview)
- [Installation](#installation)
- [GenServers](#genservers)
- [Scraper](#scraper)

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `langchainex` to your list of dependencies in `mix.exs`:
### Overview

Loosely inspired by [LangChainJs](https://github.com/hwchase17/langchainjs)
This library seeks to enable core LangChain functionality but using
Elixir and OTP idioms. It provides low-level structures
you can use to build your own language chain applications
as well as high-level GenServers for accomplishing common
natural-language processing tasks very quickly.

## Installation

```elixir
def deps do
Expand All @@ -15,7 +26,43 @@ def deps do
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/langchainex>.
Be sure to set your OPENAI_API_KEY and OPENAI_ORGANIZATION_KEY in your environment variables before using.


## GenServers

### Scraper

Scraper holds language chains that extract structured data
from natural language text. It has a handy "default_scraper" that
can be used out of the box.


In your Application tree:
```elixir
{LangChain.Scraper, name: :scraper},
```

In your code:
```elixir
description = "Hi I'm Nermal an 11th-level magic user with 30 hit points, I have a wand of healing and a cloak of protection in my inventory."

character_schema = "{
name: String,
class: String,
hitPoints: Int,
inventory: [String]
}"

{:ok, result } = LangChain.Scraper.scrape(:scraper, description, "default_scraper", %{ outputFormat: "YAML", inputSchema: character_schema })

IO.puts result.text
" name: Nermal
class: magic user
hitPoints: 30
inventory:
- wand of healing
- cloak of protection
"
end
```
2 changes: 2 additions & 0 deletions lib/langchain/chat.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule LangChain.Chat do
@derive Jason.Encoder
defstruct [template: "", inputVariables: [], partialVariables: %{}, promptMessages: [], llm: %LangChain.LLM{
provider: :openai,
temperature: 0.1,
maxTokens: 200,
modelName: "gpt-3.5-turbo", # model must support chat dialogue history
}]

Expand Down
1 change: 1 addition & 0 deletions lib/langchain/llm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ defmodule LangChain.LLM do
end
end

# call is a single chat msg
def call(model, prompt) do
case model.provider do
:openai -> LangChain.Providers.OpenAI.call(model, prompt)
Expand Down

0 comments on commit 581c032

Please sign in to comment.