Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Nov 11, 2023
1 parent d14835b commit 237594c
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 177 deletions.
6 changes: 3 additions & 3 deletions docs/content/en/docs/getting_started/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ go get github.com/hupe1980/golc
## Getting Predictions from Large Language Models
The core functionality of the GoLC project revolves around Language Models (LLMs), which excel at generating text based on input text. GoLC offers extensive support for a variety of pre-trained LLMs, providing developers with a wide range of options to choose from.

To leverage the power of LLMs in your application, you can initialize an LLM model, such as the OpenAI model, and make predictions. For example, you can use the OpenAI model to determine the birth year of Albert Einstein:
To leverage the power of LLMs in your application, you can initialize a model, such as the OpenAI model, and make predictions. For example, you can use the OpenAI model to determine the birth year of Albert Einstein:
```go
import (
"context"
"os"

"github.com/hupe1980/golc/model"
"github.com/hupe1980/golc/prompt"
"github.com/hupe1980/golc/model/llm"
"github.com/hupe1980/golc/model/chatmodel"
)

func main() {
openai, err := llm.NewOpenAI(os.Getenv("OPENAI_API_KEY"))
openai, err := chatmodel.NewOpenAI(os.Getenv("OPENAI_API_KEY"))
if err != nil {
// Handle error
}
Expand Down
4 changes: 2 additions & 2 deletions evaluation/context_qa_eval_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ContextQAEvalChain struct {
predictionKey string
}

func NewContextQAEvalChain(llm schema.LLM, optFns ...func(o *ContextQAEvalChainOptions)) (*ContextQAEvalChain, error) {
func NewContextQAEvalChain(model schema.Model, optFns ...func(o *ContextQAEvalChainOptions)) (*ContextQAEvalChain, error) {
opts := ContextQAEvalChainOptions{
QuestionKey: "query",
ContextKey: "context",
Expand All @@ -59,7 +59,7 @@ func NewContextQAEvalChain(llm schema.LLM, optFns ...func(o *ContextQAEvalChainO
opts.Prompt = prompt.NewTemplate(contextQAEvalTemplate)
}

llmChain, err := chain.NewLLM(llm, opts.Prompt)
llmChain, err := chain.NewLLM(model, opts.Prompt)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions evaluation/cot_qa_eval_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type COTQAEvalChain struct {
*ContextQAEvalChain
}

func NewCOTQAEvalChain(llm schema.LLM, optFns ...func(o *COTQAEvalChainOptions)) (*COTQAEvalChain, error) {
func NewCOTQAEvalChain(model schema.Model, optFns ...func(o *COTQAEvalChainOptions)) (*COTQAEvalChain, error) {
opts := COTQAEvalChainOptions{
QuestionKey: "query",
ContextKey: "context",
Expand All @@ -50,7 +50,7 @@ func NewCOTQAEvalChain(llm schema.LLM, optFns ...func(o *COTQAEvalChainOptions))
opts.Prompt = prompt.NewTemplate(cotQAEvalTemplate)
}

contextQAEvalChain, err := NewContextQAEvalChain(llm, func(o *ContextQAEvalChainOptions) {
contextQAEvalChain, err := NewContextQAEvalChain(model, func(o *ContextQAEvalChainOptions) {
o.Prompt = opts.Prompt
o.QuestionKey = opts.QuestionKey
o.ContextKey = opts.ContextKey
Expand Down
4 changes: 2 additions & 2 deletions evaluation/qa_eval_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type QAEvalChain struct {
predictionKey string
}

func NewQAEvalChain(llm schema.LLM, optFns ...func(o *QAEvalChainOptions)) (*QAEvalChain, error) {
func NewQAEvalChain(model schema.Model, optFns ...func(o *QAEvalChainOptions)) (*QAEvalChain, error) {
opts := QAEvalChainOptions{
Prompt: prompt.NewTemplate(qaEvalTemplate),
QuestionKey: "query",
Expand All @@ -52,7 +52,7 @@ func NewQAEvalChain(llm schema.LLM, optFns ...func(o *QAEvalChainOptions)) (*QAE
fn(&opts)
}

llmChain, err := chain.NewLLM(llm, opts.Prompt)
llmChain, err := chain.NewLLM(model, opts.Prompt)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions examples/openai_streaming/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (

"github.com/hupe1980/golc/callback"
"github.com/hupe1980/golc/model"
"github.com/hupe1980/golc/model/llm"
"github.com/hupe1980/golc/model/chatmodel"
"github.com/hupe1980/golc/prompt"
"github.com/hupe1980/golc/schema"
)

func main() {
openai, err := llm.NewOpenAI(os.Getenv("OPENAI_API_KEY"), func(o *llm.OpenAIOptions) {
openai, err := chatmodel.NewOpenAI(os.Getenv("OPENAI_API_KEY"), func(o *chatmodel.OpenAIOptions) {
o.MaxTokens = 256
o.Stream = true
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions examples/qa_evaluation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"os"

"github.com/hupe1980/golc/evaluation"
"github.com/hupe1980/golc/model/llm"
"github.com/hupe1980/golc/model/chatmodel"
)

func main() {
openai, err := llm.NewOpenAI(os.Getenv("OPENAI_API_KEY"))
openai, err := chatmodel.NewOpenAI(os.Getenv("OPENAI_API_KEY"))
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/react_description_agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/hupe1980/golc"
"github.com/hupe1980/golc/agent"
"github.com/hupe1980/golc/model/llm"
"github.com/hupe1980/golc/model/chatmodel"
"github.com/hupe1980/golc/toolkit"
"github.com/playwright-community/playwright-go"
)
Expand All @@ -30,7 +30,7 @@ func main() {
log.Fatal(err)
}

openai, err := llm.NewOpenAI(os.Getenv("OPENAI_API_KEY"))
openai, err := chatmodel.NewOpenAI(os.Getenv("OPENAI_API_KEY"))
if err != nil {
log.Fatal(err)
}
Expand Down
86 changes: 43 additions & 43 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ module github.com/hupe1980/golc
go 1.20

require (
cloud.google.com/go/ai v0.1.2
cloud.google.com/go/aiplatform v1.51.1
cloud.google.com/go/ai v0.1.4
cloud.google.com/go/aiplatform v1.53.0
github.com/Masterminds/sprig/v3 v3.2.3
github.com/aws/aws-sdk-go-v2 v1.22.1
github.com/aws/aws-sdk-go-v2/service/sagemakerruntime v1.22.0
github.com/aws/aws-sdk-go-v2 v1.22.2
github.com/aws/aws-sdk-go-v2/service/sagemakerruntime v1.24.2
github.com/cohere-ai/tokenizer v1.1.2
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-openapi/strfmt v0.21.7
github.com/googleapis/gax-go/v2 v2.12.0
github.com/sashabaranov/go-openai v1.16.0
github.com/sashabaranov/go-openai v1.17.5
github.com/stretchr/testify v1.8.4
github.com/weaviate/weaviate v1.21.8
github.com/weaviate/weaviate v1.22.3
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
)

require (
cloud.google.com/go/longrunning v0.5.2 // indirect
cloud.google.com/go/longrunning v0.5.4 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect
Expand All @@ -29,30 +29,30 @@ require (
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.15.1 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.15.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.37 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.17.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.25.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.15.2 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.6.0 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.17.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.17.1 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.25.1 // indirect
github.com/aws/smithy-go v1.16.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.5 // indirect
github.com/cloudflare/circl v1.3.6 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.4 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
Expand All @@ -66,7 +66,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1 // indirect
github.com/hashicorp/hcl/v2 v2.19.1 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand All @@ -83,19 +83,19 @@ require (
github.com/stretchr/objx v0.5.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
go.mongodb.org/mongo-driver v1.12.1 // indirect
go.mongodb.org/mongo-driver v1.13.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/api v0.148.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.15.0 // indirect
google.golang.org/api v0.150.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand All @@ -107,11 +107,11 @@ require (
github.com/PuerkitoBio/goquery v1.8.1
github.com/antonmedv/expr v1.15.3
github.com/avast/retry-go v3.0.0+incompatible
github.com/aws/aws-sdk-go-v2/config v1.22.1
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.43
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.1.2
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.23.0
github.com/aws/aws-sdk-go-v2/service/kendra v1.44.0
github.com/aws/aws-sdk-go-v2/config v1.23.0
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.12.1
github.com/aws/aws-sdk-go-v2/service/bedrockruntime v1.3.1
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.1
github.com/aws/aws-sdk-go-v2/service/kendra v1.46.1
github.com/cohere-ai/cohere-go v1.2.2
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-git/go-git/v5 v5.10.0
Expand All @@ -123,16 +123,16 @@ require (
github.com/hupe1980/go-tiktoken v0.0.5
github.com/imdario/mergo v0.3.16 // indirect
github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80
github.com/mattn/go-sqlite3 v1.14.17
github.com/mattn/go-sqlite3 v1.14.18
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pinecone-io/go-pinecone v0.3.0
github.com/playwright-community/playwright-go v0.3800.1
github.com/playwright-community/playwright-go v0.3900.1
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/serpapi/google-search-results-golang v0.0.0-20230616000151-95707d993dc6
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/weaviate/weaviate-go-client/v4 v4.10.0
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/sync v0.4.0
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/sync v0.5.0
)
Loading

0 comments on commit 237594c

Please sign in to comment.