Skip to content

Commit f6f6b82

Browse files
authored
feat!: Use Mercury's OpenAI client (#7)
* WIP: added OpenAI.V1 in OpenAICompatible * WIP: removed OpenAI internal module * WIP: fixed examples as per new OpenAI client * WIP: added messageConvertible instance for OpenAI.Message * chore!: fixed examples with new openai client * chore: doc fixs
1 parent afccd8c commit f6f6b82

38 files changed

+865
-2266
lines changed

docs/docs/concepts/DocumentLoader.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Right now, langchain-hs provides below integrations, with more integrations plan
4141
- `PdfLoader`: Loads documents from a PDF file path.
4242
- `DirectoryLoader`: Loads documents from a directory. It can recursively load files from subdirectories and filter files based on their extensions.
4343

44-
**DiretoryLaoderOptions**
44+
**DirectoryLoaderOptions**
4545

4646
```haskell
4747
data DirectoryLoaderOptions = DirectoryLoaderOptions

docs/docs/concepts/Embeddings.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ data DeepseekEmbedding = DeepseekEmbedding {
5050
model :: Text
5151
}
5252

53-
instance Embeddings Deepseek where
54-
embedDocuments OpenAIEmbedding docs = do
53+
instance Embeddings DeepseekEmbedding where
54+
embedDocuments DeepseekEmbedding{..} docs = do
5555
-- Your implementation here
5656
return $ Right []
57-
embedQuery OpenAIEmbedding{..} query = do
57+
embedQuery DeepseekEmbedding{..} query = do
5858
-- Your implementation here
5959
return $ Right []
6060
```

docs/docs/concepts/LLM.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ data Message = Message
6868
The `Message` type represents a single message in the chat conversation. It has three fields:
6969
- `role`: The role of the message sender (Possible values are User, Assistant, System, Tool, Developer, Function).
7070
- `content`: The content of the message (Text).
71-
- `messageData`: Additional data associated with the message, such as name or toolcalls (soon to be depreceted). You can use `defaultMessageData` to create a default instance of `MessageData` with no additional data.
71+
- `messageData`: Additional data associated with the message, such as name or tool calls. You can use `defaultMessageData` to create a default instance of `MessageData` with no additional data.
7272
7373
## Writing your own LLM
7474
@@ -158,7 +158,7 @@ For full control, construct the type directly:
158158
let customClient = OpenAICompatible
159159
{ apiKey = Just "your-api-key"
160160
, modelName = "custom-mistral"
161-
, callbacks = [stdOutCallbacl] -- Example with logging callback
161+
, callbacks = [stdOutCallback] -- Example with logging callback
162162
, baseUrl = Just "https://my-ai-server.com/openai/v1"
163163
, defaultBaseUrl = "http://localhost:8080/v1"
164164
, providerName = "MyCustomProvider"

docs/docs/concepts/Tool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Calculator tool can perform Add, Sub, Mul, Div, Pow operation and return type wo
172172

173173
:::Warning
174174

175-
Write now, duckduckgo tool only returns result if the search term has an abstract card.
175+
Right now, duckduckgo tool only returns result if the search term has an abstract card.
176176
It does not return links, only abstract summary
177177

178178
:::

docs/docs/concepts/VectorStore.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The `InMemory` vector store is a simple implementation that stores documents and
2929
Below is an example that:
3030
- Reads a 20 pages long pdf file and generates a list of documents.
3131
- Sets up an OllamaEmbeddings model.
32-
- Creates an InMemoryVectoStore with model and documents.
32+
- Creates an InMemoryVectorStore with model and documents.
3333
- Fetches top 2 documents that are closest to the given query.
3434

3535
```haskell

docs/docs/getting-started/quick_start.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ main :: IO ()
7979
main = do
8080
let openAI = OpenAI
8181
{ apiKey = "your-api-key"
82-
, openAIModelName = "gpt-4.1-nano"
8382
, callbacks = []
83+
, baseUrl = Nothing
8484
}
8585
result <- LLM.generate openAI "Tell me a joke" Nothing
8686
case result of
8787
Left err -> putStrLn $ "Error: " ++ err
8888
Right response -> putStrLn response
8989
```
9090
In above code:
91-
1. Setup the `OpenAI` LLM with the api key, model name and optional list of callback functions.
91+
1. Setup the `OpenAI` LLM with the api key and optional list of callback functions. You can specify a custom base URL if needed.
9292
2. Call the `generate` function with the prompt and optional parameters.
9393
3. Handle the result, which can be either an error or the generated text.
9494
4. The `generate` function returns a `Text` response, which you can print or use as needed.
@@ -154,7 +154,7 @@ runApp :: IO ()
154154
runApp = do
155155
let ollamaLLM = Ollama "llama3.2" []
156156
let chatHistory = fromList
157-
[ Message System "Explain everthing with a texas accent." defaultMessageData
157+
[ Message System "Explain everything with a texas accent." defaultMessageData
158158
, Message User "What is functional programming?" defaultMessageData
159159
]
160160
chatResult <- chat ollamaLLM chatHistory Nothing
@@ -177,7 +177,7 @@ For Ollama, Make sure the model that you want to use is installed on your local
177177
`Message` constructor takes 3 parameters:
178178
1. `role`: The role of the message sender (System, User, Assistant).
179179
2. `content`: The content of the message (Text).
180-
3. `metadata`: Optional metadata for the message (A type containing a optinal name and optional list of toolnames) (Currently unstable).
180+
3. `messageData`: Optional metadata for the message (A type containing an optional name and optional list of tool calls).
181181
4. `defaultMessageData`: A default value for the metadata, which can be used if no specific metadata is provided.
182182

183183
`chat` takes a `NonEmpty` list of `Message` as input. The `NonEmpty` type ensures that the list is not empty, which is important for chat history.
@@ -200,7 +200,6 @@ main :: IO ()
200200
main = do
201201
let openAI = OpenAI
202202
{ apiKey = "your-api-key"
203-
, openAIModelName = "gpt-4.1-nano"
204203
, callbacks = []
205204
, baseUrl = Nothing
206205
}
@@ -214,7 +213,7 @@ main = do
214213
Right response -> putStrLn $ "Chat Response:\n" ++ T.unpack response
215214
```
216215
In above code:
217-
1. Setup the `OpenAI` LLM with the api key, model name and optional list of callback functions.
216+
1. Setup the `OpenAI` LLM with the api key and optional list of callback functions. You can specify a custom base URL if needed.
218217
2. Create a `chatHistory` using `fromList` with `Message` constructor.
219218
3. Call the `chat` function with the `chatHistory` and optional parameters.
220219
4. Handle the result, which can be either an error or the generated text.
@@ -224,7 +223,7 @@ In above code:
224223
`Message` constructor takes 3 parameters:
225224
1. `role`: The role of the message sender (System, User, Assistant).
226225
2. `content`: The content of the message (Text).
227-
3. `metadata`: Optional metadata for the message (A type containing a optinal name and optional list of toolnames) (Currently unstable).
226+
3. `metadata`: Optional metadata for the message (A type containing a optional name and optional list of toolnames) (Currently unstable).
228227
4. `defaultMessageData`: A default value for the metadata, which can be used if no specific metadata is provided.
229228
`chat` takes a `NonEmpty` list of `Message` as input. The `NonEmpty` type ensures that the list is not empty, which is important for chat history.
230229
:::
@@ -270,7 +269,7 @@ In above code:
270269
`Message` constructor takes 3 parameters:
271270
1. `role`: The role of the message sender (System, User, Assistant).
272271
2. `content`: The content of the message (Text).
273-
3. `metadata`: Optional metadata for the message (A type containing a optinal name and optional list of toolnames) (Currently unstable).
272+
3. `metadata`: Optional metadata for the message (A type containing a optional name and optional list of toolnames) (Currently unstable).
274273
4. `defaultMessageData`: A default value for the metadata, which can be used if no specific metadata is provided.
275274
`chat` takes a `NonEmpty` list of `Message` as input. The `NonEmpty` type ensures that the list is not empty, which is important for chat history.
276275
:::
@@ -332,7 +331,7 @@ The StreamHandler takes two functions:
332331
`Message` constructor takes 3 parameters:
333332
1. `role`: The role of the message sender (System, User, Assistant).
334333
2. `content`: The content of the message (Text).
335-
3. `metadata`: Optional metadata for the message (A type containing a optinal name and optional list of toolnames) (Currently unstable).
334+
3. `metadata`: Optional metadata for the message (A type containing a optional name and optional list of toolnames) (Currently unstable).
336335
4. `defaultMessageData`: A default value for the metadata, which can be used if no specific metadata is provided.
337336
`stream` takes a `NonEmpty` list of `Message` as input. The `NonEmpty` type ensures that the list is not empty, which is important for chat history.
338337
:::
@@ -355,7 +354,6 @@ runApp = do
355354
let openAI =
356355
OpenAI
357356
{ apiKey = "your-api-key"
358-
, openAIModelName = "gpt-4.1-nano"
359357
, callbacks = []
360358
, baseUrl = Nothing
361359
}
@@ -391,7 +389,7 @@ The StreamHandler takes two functions:
391389
`Message` constructor takes 3 parameters:
392390
1. `role`: The role of the message sender (System, User, Assistant).
393391
2. `content`: The content of the message (Text).
394-
3. `metadata`: Optional metadata for the message (A type containing a optinal name and optional list of toolnames) (Currently unstable).
392+
3. `metadata`: Optional metadata for the message (A type containing a optional name and optional list of toolnames) (Currently unstable).
395393
4. `defaultMessageData`: A default value for the metadata, which can be used if no specific metadata is provided.
396394
`stream` takes a `NonEmpty` list of `Message` as input. The `NonEmpty` type ensures that the list is not empty, which is important for chat history.
397395
:::
@@ -449,7 +447,7 @@ The StreamHandler takes two functions:
449447
`Message` constructor takes 3 parameters:
450448
1. `role`: The role of the message sender (System, User, Assistant).
451449
2. `content`: The content of the message (Text).
452-
3. `metadata`: Optional metadata for the message (A type containing a optinal name and optional list of toolnames) (Currently unstable).
450+
3. `metadata`: Optional metadata for the message (A type containing a optional name and optional list of toolnames) (Currently unstable).
453451
4. `defaultMessageData`: A default value for the metadata, which can be used if no specific metadata is provided.
454452
`stream` takes a `NonEmpty` list of `Message` as input. The `NonEmpty` type ensures that the list is not empty, which is important for chat history.
455453
:::

docs/docs/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ sidebar_position: 1
44

55
# langchain-hs Documentation
66

7-
Lanchain-hs is the Haskell implementation of [LangChain](https://www.langchain.com/).
7+
Langchain-hs is the Haskell implementation of [LangChain](https://www.langchain.com/).
88

99
## Welcome to langchain-hs
1010

1111
Langchain-hs brings the power of LangChain to Haskell, enabling type-safe LLM application development with:
1212

1313
- Composable pipelines using Haskell's type system
14-
- Closely following with Offical LangChain concepts
14+
- Closely following with Official LangChain concepts
1515
- Performance through functional programming patterns
1616
- Support for Ollama, OpenAI and custom LLM integrations
1717

@@ -21,7 +21,7 @@ Check out the [Quickstart](getting-started/quick_start) guide to get started wit
2121

2222
## Components
2323

24-
This documenation provides an overview of the core components of langchain-hs. Each component is designed to be modular, composable and interchangeble, allowing you to build complex applications with ease.
24+
This documentation provides an overview of the core components of langchain-hs. Each component is designed to be modular, composable and interchangeable, allowing you to build complex applications with ease.
2525

2626
Langchain-hs is built around the core concepts of LangChain; You will find documentation for each components including:
2727

docs/docusaurus.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const config: Config = {
9191
items: [
9292
{
9393
label: 'Github',
94-
to: 'https://github.com/tusharad/lanchain-hs',
94+
to: 'https://github.com/tusharad/langchain-hs',
9595
},
9696
],
9797
},

examples/langchain-examples/app/Main.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ module Main (main) where
33
-- import App.OpenRouter.PdfQA
44
-- import App.OpenRouter.ToolCall
55
-- import App.Ollama.StructuredOutput
6-
-- import App.OpenRouter.StructuredOutput
6+
import App.OpenRouter.StructuredOutput
7+
78
-- import App.Ollama.MultiAgent
89
-- import App.Ollama.Agent
910
-- import App.Gemini.Embeddings
1011
-- import App.Gemini.Runnable
11-
import App.Gemini.ImageInput
12-
12+
-- import App.Gemini.ImageInput
1313
-- import App.Gemini.Simple
14-
1514
-- import App.Gemini.Streaming
15+
-- import App.OpenAI.ImageInput
1616

1717
main :: IO ()
1818
main = runApp

examples/langchain-examples/langchain-examples.cabal

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ library
5353
, filepath
5454
, langchain-hs
5555
, ollama-haskell
56+
, openai
5657
, scientific
5758
, text
5859
, transformers
60+
, vector
5961
default-language: Haskell2010
6062

6163
executable langchain-examples-exe
@@ -76,9 +78,11 @@ executable langchain-examples-exe
7678
, langchain-examples
7779
, langchain-hs
7880
, ollama-haskell
81+
, openai
7982
, scientific
8083
, text
8184
, transformers
85+
, vector
8286
default-language: Haskell2010
8387

8488
test-suite langchain-examples-test
@@ -100,7 +104,9 @@ test-suite langchain-examples-test
100104
, langchain-examples
101105
, langchain-hs
102106
, ollama-haskell
107+
, openai
103108
, scientific
104109
, text
105110
, transformers
111+
, vector
106112
default-language: Haskell2010

0 commit comments

Comments
 (0)