Skip to content

Commit 11ec895

Browse files
authored
Merge pull request #2 from mutablelogic/dev
Added README
2 parents 410db6e + 74300b6 commit 11ec895

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

README.md

+102-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,103 @@
11
# go-llm
2-
Large Language Model API interface
2+
3+
Large Language Model API interface. This is a simple API interface for large language models
4+
which run on [Ollama](https://github.com/ollama/ollama/blob/main/docs/api.md)
5+
and [Anthopic](https://docs.anthropic.com/en/api/getting-started).
6+
7+
The module includes the ability to utilize:
8+
9+
* Maintaining a session of messages
10+
* Tool calling support
11+
* Streaming responses
12+
13+
There is a command-line tool included in the module which can be used to interact with the API.
14+
For example,
15+
16+
```bash
17+
# Display help
18+
docker run ghcr.io/mutablelogic/go-llm:latest --help
19+
20+
# Interact with Claude to retrieve news headlines, assuming
21+
# you have an API key for Anthropic and NewsAPI
22+
docker run \
23+
--interactive -e ANTHROPIC_API_KEY -e NEWSAPI_KEY \
24+
ghcr.io/mutablelogic/go-llm:latest \
25+
chat claude-3-5-haiku-20241022
26+
```
27+
28+
## Programmatic Usage
29+
30+
See the documentation [here](https://pkg.go.dev/github.com/mutablelogic/go-llm)
31+
for integration into your own Go programs. To create an
32+
[Ollama](https://pkg.go.dev/github.com/mutablelogic/go-llm/pkg/anthropic)
33+
agent,
34+
35+
```go
36+
import (
37+
"github.com/mutablelogic/go-llm/pkg/ollama"
38+
)
39+
40+
func main() {
41+
// Create a new agent
42+
agent, err := ollama.New("https://ollama.com/api/v1/")
43+
if err != nil {
44+
panic(err)
45+
}
46+
// ...
47+
}
48+
```
49+
50+
To create an
51+
[Anthropic](https://pkg.go.dev/github.com/mutablelogic/go-llm/pkg/anthropic)
52+
agent,
53+
54+
```go
55+
import (
56+
"github.com/mutablelogic/go-llm/pkg/anthropic"
57+
)
58+
59+
func main() {
60+
// Create a new agent
61+
agent, err := anthropic.New(os.Getev("ANTHROPIC_API_KEY"))
62+
if err != nil {
63+
panic(err)
64+
}
65+
// ...
66+
}
67+
```
68+
69+
You create a **chat session** with a model as follows,
70+
71+
```go
72+
import (
73+
"github.com/mutablelogic/go-llm"
74+
)
75+
76+
func session(ctx context.Context, agent llm.Agent) error {
77+
// Create a new chat session
78+
session := agent.Model("claude-3-5-haiku-20241022").Context()
79+
80+
// Repeat forever
81+
for {
82+
err := session.FromUser(ctx, "hello")
83+
if err != nil {
84+
return err
85+
}
86+
87+
// Print the response
88+
fmt.Println(session.Text())
89+
}
90+
}
91+
```
92+
93+
## Contributing & Distribution
94+
95+
*This module is currently in development and subject to change*. Please do file
96+
feature requests and bugs [here](https://github.com/mutablelogic/go-llm/issues).
97+
The [license is Apache 2](LICENSE) so feel free to redistribute. Redistributions in either source
98+
code or binary form must reproduce the copyright notice, and please link back to this
99+
repository for more information:
100+
101+
> **go-llm**\
102+
> [https://github.com/mutablelogic/go-llm/](https://github.com/mutablelogic/go-llm/)\
103+
> Copyright (c) 2025 David Thorpe, All rights reserved.

0 commit comments

Comments
 (0)