Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(go/plugins/ollama): use ollama go client in plugin #751

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions go/ai/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ func conformOutput(req *GenerateRequest) error {
// It will strip JSON markdown delimiters from the response.
func validCandidates(ctx context.Context, resp *GenerateResponse) ([]*Candidate, error) {
var candidates []*Candidate

if resp.Request == nil {
return nil, errors.New("cannot validate candidates, response has no request information")
}

// check if resp.Request.Output is nil first. if it is then just respond with the candidates
if resp.Request.Output == nil {
return resp.Candidates, nil
}

for i, c := range resp.Candidates {
c, err := validCandidate(c, resp.Request.Output)
if err == nil {
Expand Down
16 changes: 15 additions & 1 deletion go/ai/request_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

package ai

// NewGenerateRequest create a new GenerateRequest with provided config and
import "errors"

// NewGenerateRequest create a new GenerateRequest with provided config, output and
// messages.
func NewGenerateRequest(config any, messages ...*Message) *GenerateRequest {
return &GenerateRequest{
Expand All @@ -23,6 +25,18 @@ func NewGenerateRequest(config any, messages ...*Message) *GenerateRequest {
}
}

func NewGenerateRequestWithOutput(config any, output *GenerateRequestOutput, messages ...*Message) (*GenerateRequest, error) {

if output == nil {
return nil, errors.New("output cannot be nil")
}
return &GenerateRequest{
Config: config,
Messages: messages,
Output: output,
}, nil
}

// NewUserMessage creates a new Message with role "user" and provided parts.
// Use NewUserTextMessage if you have a text-only message.
func NewUserMessage(parts ...*Part) *Message {
Expand Down
1 change: 1 addition & 0 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/invopop/jsonschema v0.12.0
github.com/jba/slog v0.2.0
github.com/lib/pq v1.10.9
github.com/ollama/ollama v0.3.4
github.com/pgvector/pgvector-go v0.2.0
github.com/weaviate/weaviate v1.26.0-rc.1
github.com/weaviate/weaviate-go-client/v4 v4.15.0
Expand Down
2 changes: 2 additions & 0 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJ
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/ollama/ollama v0.3.4 h1:WHXyMmDZ+c0OQVQV9FKj4PrKLB5IB522dKA0X0tbYa4=
github.com/ollama/ollama v0.3.4/go.mod h1:USAVO5xFaXAoVWJ0rkPYgCVhTxE/oJ81o7YGcJxvyp8=
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
github.com/pgvector/pgvector-go v0.2.0 h1:NZdW4NxUxdSCzaev3LVHb9ORf+LdX+uZOQVqQ6s2Zyg=
github.com/pgvector/pgvector-go v0.2.0/go.mod h1:OQpvU5QZGQOPI9quIXAyHaRZ5yGk/RGUDbs9C3DPUNE=
Expand Down
Loading
Loading