Current section

9 Versions

Jump to

Compare versions

9 files changed
+340 additions
-151 deletions
  @@ -0,0 +1,176 @@
1 + # LLMGleam
2 +
3 + A Gleam library for interacting with Large Language Model APIs.
4 + Currently supports Google's Gemini and OpenAI's GPT APIs with a clean,
5 + type-safe interface.
6 +
7 + ## Features
8 +
9 + - đź”’ **Type-safe**: Leverages Gleam's type system for reliable API
10 + interactions
11 + - 🌟 **Clean API**: Fluent builder pattern for constructing requests
12 + - 🔌 **Extensible**: Designed to support multiple LLM providers
13 + - ⚡ **Async**: Built on Gleam's concurrent model
14 +
15 + ## Installation
16 +
17 + `gleam add llmgleam`
18 +
19 + ## Quick Start
20 +
21 + ``` gleam
22 + import llmgleam
23 + import llmgleam/client
24 + import llmgleam/messages
25 +
26 + pub fn main() {
27 + // Create a client
28 + let client = llmgleam.new_client(client.Gemini, "your-api-key-here")
29 +
30 + // Get completion using the builder pattern
31 + let result =
32 + client
33 + |> client.request()
34 + |> client.with_message(messages.user("Hello, how are you?"))
35 + |> client.completion("gemini-2.5-flash")
36 +
37 + case result {
38 + Ok(completion) -> {
39 + io.println("Response: " <> completion.content)
40 + }
41 + Error(error) -> {
42 + io.println("Error: " <> string.inspect(error))
43 + }
44 + }
45 + }
46 + ```
47 +
48 + ## API Reference
49 +
50 + ### Creating a Client
51 +
52 + ``` gleam
53 + import llmgleam
54 + import llmgleam/client
55 +
56 + // For Gemini
57 + let gemini_client = llmgleam.new_client(client.Gemini, "your-gemini-api-key")
58 +
59 + // For GPT
60 + let gpt_client = llmgleam.new_client(client.GPT, "your-openai-api-key")
61 + ```
62 +
63 + ### Building Requests
64 +
65 + The library uses a fluent builder pattern for constructing requests:
66 +
67 + ``` gleam
68 + import llmgleam/client
69 + import llmgleam/messages
70 +
71 + let completion =
72 + client
73 + |> client.request()
74 + |> client.with_message(messages.user("Hello, how are you?"))
75 + |> client.with_system_instruction("You are a helpful assistant")
76 + |> client.completion("gemini-2.5-flash")
77 + ```
78 +
79 + ### Messages
80 +
81 + ``` gleam
82 + import llmgleam/messages
83 +
84 + // Create a user message
85 + let user_msg = messages.user("Hello, how are you?")
86 +
87 + // System instructions are added via with_system_instruction
88 + ```
89 +
90 + ### Functions
91 +
92 + 1. `llmgleam.new_client(provider: Provider, api_key: String) -> Client`
93 +
94 + Creates a new LLM client for the specified provider.
95 +
96 + 2. `client.request(client: Client) -> Request`
97 +
98 + Initializes a new request builder from a client.
99 +
100 + 3. `client.with_message(request: Request, message: Message) -> Request`
101 +
102 + Adds a message to the request.
103 +
104 + 4. `client.with_system_instruction(request: Request, instruction: String) -> Request`
105 +
106 + Adds a system instruction to the request.
107 +
108 + 5. `client.completion(request: Request, model: String) -> Result(Completion, CompletionError)`
109 +
110 + Executes the request and returns a completion.
111 +
112 + ## Supported Providers
113 +
114 + ### Google Gemini
115 +
116 + - **Provider**: `client.Gemini`
117 + - **Authentication**: API key via Google AI Studio
118 +
119 + ### OpenAI GPT
120 +
121 + - **Provider**: `client.GPT`
122 + - **Authentication**: API key via OpenAI
123 +
124 + ## Example with System Instructions
125 +
126 + ``` gleam
127 + import llmgleam
128 + import llmgleam/client
129 + import llmgleam/messages
130 +
131 + let client = llmgleam.new_client(client.Gemini, "your-api-key")
132 +
133 + let completion =
134 + client
135 + |> client.request()
136 + |> client.with_message(messages.user("hello, how are you?"))
137 + |> client.with_system_instruction("you are a helpful conversationalist")
138 + |> client.completion("gemini-2.5-flash")
139 + ```
140 +
141 + ## Development
142 +
143 + ### Running Tests
144 +
145 + ``` bash
146 + gleam test
147 + ```
148 +
149 + For integration tests (requires API keys):
150 +
151 + ``` bash
152 + RUN_INTEGRATION_TESTS=1 GEMINI_KEY=your-key GPT_KEY=your-key gleam test
153 + ```
154 +
155 + ### Building
156 +
157 + ``` bash
158 + gleam build
159 + ```
160 +
161 + ## Contributing
162 +
163 + Contributions are welcome! Areas for improvement:
164 +
165 + - [x] Add support for OpenAI GPT models
166 + - [x] Add support for Gemini API
167 + - [ ] Add support for Gemini through vertex.ai
168 + - [ ] Add support for Anthropic Claude
169 + - [ ] Add streaming support
170 + - [ ] Add function calling support
171 + - [ ] Add image/multimodal support
172 +
173 + ## License
174 +
175 + This project is licensed under the MIT License - see the LICENSE file
176 + for details.
  @@ -1,5 +1,5 @@
1 1 name = "llmgleam"
2 - version = "0.0.6"
2 + version = "0.0.7"
3 3
4 4 description = "Gleam bindings for various LLMs"
5 5 licences = ["MIT"]
  @@ -1,63 +1,64 @@
1 - {<<"name">>, <<"llmgleam">>}.
2 - {<<"app">>, <<"llmgleam">>}.
3 - {<<"version">>, <<"0.0.6">>}.
1 + {<<"name">>, <<"llmgleam"/utf8>>}.
2 + {<<"app">>, <<"llmgleam"/utf8>>}.
3 + {<<"version">>, <<"0.0.7"/utf8>>}.
4 4 {<<"description">>, <<"Gleam bindings for various LLMs"/utf8>>}.
5 - {<<"licenses">>, [<<"MIT">>]}.
6 - {<<"build_tools">>, [<<"gleam">>]}.
5 + {<<"licenses">>, [<<"MIT"/utf8>>]}.
6 + {<<"build_tools">>, [<<"gleam"/utf8>>]}.
7 7 {<<"links">>, [
8 - {<<"Repository">>, <<"https://github.com/Endi1/llmgleam">>}
8 + {<<"Repository"/utf8>>, <<"https://github.com/Endi1/llmgleam"/utf8>>}
9 9 ]}.
10 10 {<<"requirements">>, [
11 - {<<"gleam_http">>, [
12 - {<<"app">>, <<"gleam_http">>},
11 + {<<"gleam_hackney"/utf8>>, [
12 + {<<"app">>, <<"gleam_hackney"/utf8>>},
13 13 {<<"optional">>, false},
14 - {<<"requirement">>, <<">= 4.1.1 and < 5.0.0">>}
14 + {<<"requirement">>, <<">= 1.3.2 and < 2.0.0"/utf8>>}
15 15 ]},
16 - {<<"gleam_stdlib">>, [
17 - {<<"app">>, <<"gleam_stdlib">>},
16 + {<<"gleam_http"/utf8>>, [
17 + {<<"app">>, <<"gleam_http"/utf8>>},
18 18 {<<"optional">>, false},
19 - {<<"requirement">>, <<">= 0.44.0 and < 2.0.0">>}
19 + {<<"requirement">>, <<">= 4.1.1 and < 5.0.0"/utf8>>}
20 20 ]},
21 - {<<"envoy">>, [
22 - {<<"app">>, <<"envoy">>},
21 + {<<"gleam_json"/utf8>>, [
22 + {<<"app">>, <<"gleam_json"/utf8>>},
23 23 {<<"optional">>, false},
24 - {<<"requirement">>, <<">= 1.0.2 and < 2.0.0">>}
24 + {<<"requirement">>, <<">= 3.0.2 and < 4.0.0"/utf8>>}
25 25 ]},
26 - {<<"gleam_hackney">>, [
27 - {<<"app">>, <<"gleam_hackney">>},
26 + {<<"envoy"/utf8>>, [
27 + {<<"app">>, <<"envoy"/utf8>>},
28 28 {<<"optional">>, false},
29 - {<<"requirement">>, <<">= 1.3.2 and < 2.0.0">>}
29 + {<<"requirement">>, <<">= 1.0.2 and < 2.0.0"/utf8>>}
30 30 ]},
31 - {<<"gleam_json">>, [
32 - {<<"app">>, <<"gleam_json">>},
31 + {<<"gleam_stdlib"/utf8>>, [
32 + {<<"app">>, <<"gleam_stdlib"/utf8>>},
33 33 {<<"optional">>, false},
34 - {<<"requirement">>, <<">= 3.0.2 and < 4.0.0">>}
34 + {<<"requirement">>, <<">= 0.44.0 and < 2.0.0"/utf8>>}
35 35 ]}
36 36 ]}.
37 37 {<<"files">>, [
38 - <<"LICENSE">>,
39 - <<"gleam.toml">>,
40 - <<"include/llmgleam@client_GPTClient.hrl">>,
41 - <<"include/llmgleam@client_GeminiClient.hrl">>,
42 - <<"include/llmgleam@client_Request.hrl">>,
43 - <<"include/llmgleam@gemini_GeminiClientInternal.hrl">>,
44 - <<"include/llmgleam@gpt_ChatCompletion.hrl">>,
45 - <<"include/llmgleam@gpt_ChatCompletionRequest.hrl">>,
46 - <<"include/llmgleam@gpt_GPTClientInternal.hrl">>,
47 - <<"include/llmgleam@gpt_Usage.hrl">>,
48 - <<"include/llmgleam@types_ChatMessage.hrl">>,
49 - <<"include/llmgleam@types_Completion.hrl">>,
50 - <<"src/llmgleam.app.src">>,
51 - <<"src/llmgleam.erl">>,
52 - <<"src/llmgleam.gleam">>,
53 - <<"src/llmgleam/client.gleam">>,
54 - <<"src/llmgleam/gemini.gleam">>,
55 - <<"src/llmgleam/gpt.gleam">>,
56 - <<"src/llmgleam/messages.gleam">>,
57 - <<"src/llmgleam/types.gleam">>,
58 - <<"src/llmgleam@client.erl">>,
59 - <<"src/llmgleam@gemini.erl">>,
60 - <<"src/llmgleam@gpt.erl">>,
61 - <<"src/llmgleam@messages.erl">>,
62 - <<"src/llmgleam@types.erl">>
38 + <<"LICENSE"/utf8>>,
39 + <<"README.md"/utf8>>,
40 + <<"gleam.toml"/utf8>>,
41 + <<"include/llmgleam@client_GPTClient.hrl"/utf8>>,
42 + <<"include/llmgleam@client_GeminiClient.hrl"/utf8>>,
43 + <<"include/llmgleam@client_Request.hrl"/utf8>>,
44 + <<"include/llmgleam@gemini_GeminiClientInternal.hrl"/utf8>>,
45 + <<"include/llmgleam@gpt_ChatCompletion.hrl"/utf8>>,
46 + <<"include/llmgleam@gpt_ChatCompletionRequest.hrl"/utf8>>,
47 + <<"include/llmgleam@gpt_GPTClientInternal.hrl"/utf8>>,
48 + <<"include/llmgleam@gpt_Usage.hrl"/utf8>>,
49 + <<"include/llmgleam@types_ChatMessage.hrl"/utf8>>,
50 + <<"include/llmgleam@types_Completion.hrl"/utf8>>,
51 + <<"src/llmgleam.app.src"/utf8>>,
52 + <<"src/llmgleam.erl"/utf8>>,
53 + <<"src/llmgleam.gleam"/utf8>>,
54 + <<"src/llmgleam/client.gleam"/utf8>>,
55 + <<"src/llmgleam/gemini.gleam"/utf8>>,
56 + <<"src/llmgleam/gpt.gleam"/utf8>>,
57 + <<"src/llmgleam/messages.gleam"/utf8>>,
58 + <<"src/llmgleam/types.gleam"/utf8>>,
59 + <<"src/llmgleam@client.erl"/utf8>>,
60 + <<"src/llmgleam@gemini.erl"/utf8>>,
61 + <<"src/llmgleam@gpt.erl"/utf8>>,
62 + <<"src/llmgleam@messages.erl"/utf8>>,
63 + <<"src/llmgleam@types.erl"/utf8>>
63 64 ]}.
  @@ -1,5 +1,5 @@
1 1 {application, llmgleam, [
2 - {vsn, "0.0.6"},
2 + {vsn, "0.0.7"},
3 3 {applications, [envoy,
4 4 gleam_hackney,
5 5 gleam_http,
  @@ -3,7 +3,7 @@
3 3 -define(FILEPATH, "src/llmgleam.gleam").
4 4 -export([new_client/2]).
5 5
6 - -file("src/llmgleam.gleam", 5).
6 + -file("src/llmgleam.gleam", 3).
7 7 -spec new_client(llmgleam@client:provider(), binary()) -> llmgleam@client:client().
8 8 new_client(Provider, Api_key) ->
9 9 llmgleam@client:new_client(Provider, Api_key).
Loading more files…