Skip to content
Open
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
12 changes: 8 additions & 4 deletions backend/modules/llm/domain/service/llmimpl/eino/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ func ollamaBuilder(ctx context.Context, model *entity.Model, opts ...entity.Opti
if err := checkModelBeforeBuild(model); err != nil {
return nil, err
}
return ollama.NewChatModel(ctx, ollamaChatModelConfig(model, opts...))
}

func ollamaChatModelConfig(model *entity.Model, opts ...entity.Option) *ollama.ChatModelConfig {
p := model.ProtocolConfig
// 不再从default val里拿,而是从opts里拿这些参数
// cp := model.ParamConfig.GetCommonParamDefaultVal()
Expand All @@ -285,9 +289,9 @@ func ollamaBuilder(ctx context.Context, model *entity.Model, opts ...entity.Opti
Options: &api.Options{
// NumKeep: 0,
// Seed: 0,
// NumPredict: 0,
TopK: int(ptr.From(ops.TopK)),
TopP: ptr.From(ops.TopP),
NumPredict: int(ptr.From(ops.MaxTokens)),
TopK: int(ptr.From(ops.TopK)),
TopP: ptr.From(ops.TopP),
// MinP: 0,
// TypicalP: 0,
// RepeatLastN: 0,
Expand All @@ -309,7 +313,7 @@ func ollamaBuilder(ctx context.Context, model *entity.Model, opts ...entity.Opti
cfg.KeepAlive = ptr.Of(time.Duration(*pc.KeepAliveMs) * time.Millisecond)
}
}
return ollama.NewChatModel(ctx, cfg)
return cfg
}

func qwenBuilder(ctx context.Context, model *entity.Model, opts ...entity.Option) (einoModel.ToolCallingChatModel, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2025 coze-dev Authors
// SPDX-License-Identifier: Apache-2.0

package eino

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/coze-dev/coze-loop/backend/modules/llm/domain/entity"
)

func TestOllamaChatModelConfig_MaxTokens(t *testing.T) {
model := &entity.Model{ProtocolConfig: &entity.ProtocolConfig{BaseURL: "http://localhost:11434", Model: "llama3"}}

t.Run("max tokens is passed as num_predict", func(t *testing.T) {
cfg := ollamaChatModelConfig(model, entity.WithMaxTokens(256))
assert.Equal(t, 256, cfg.Options.NumPredict)
})

t.Run("num_predict stays unset without max tokens", func(t *testing.T) {
cfg := ollamaChatModelConfig(model)
assert.Equal(t, 0, cfg.Options.NumPredict)
})
}
Loading