MCPcopy Index your code
hub / github.com/coder/coder / resolveModelConfig

Method resolveModelConfig

coderd/x/chatd/chatd.go:8852–8884  ·  view source on GitHub ↗

resolveModelConfig looks up the chat's model config by its LastModelConfigID. If the referenced config no longer exists (e.g. it was deleted), it falls back to the default model config. Returns an error when no usable config is available.

(
	ctx context.Context,
	chat database.Chat,
)

Source from the content-addressed store, hash-verified

8850// (e.g. it was deleted), it falls back to the default model
8851// config. Returns an error when no usable config is available.
8852func (p *Server) resolveModelConfig(
8853 ctx context.Context,
8854 chat database.Chat,
8855) (database.ChatModelConfig, error) {
8856 if chat.LastModelConfigID != uuid.Nil {
8857 modelConfig, err := p.configCache.ModelConfigByID(
8858 ctx, chat.LastModelConfigID,
8859 )
8860 if err == nil {
8861 return modelConfig, nil
8862 }
8863 if !xerrors.Is(err, sql.ErrNoRows) {
8864 return database.ChatModelConfig{}, xerrors.Errorf(
8865 "get chat model config %s: %w",
8866 chat.LastModelConfigID, err,
8867 )
8868 }
8869 // Model config was deleted, fall through to default.
8870 }
8871
8872 defaultConfig, err := p.configCache.DefaultModelConfig(ctx)
8873 if err != nil {
8874 if xerrors.Is(err, sql.ErrNoRows) {
8875 return database.ChatModelConfig{}, xerrors.New(
8876 "no default chat model config is available",
8877 )
8878 }
8879 return database.ChatModelConfig{}, xerrors.Errorf(
8880 "get default chat model config: %w", err,
8881 )
8882 }
8883 return defaultConfig, nil
8884}
8885
8886func refreshChatWorkspaceSnapshot(
8887 ctx context.Context,

Callers 2

resolveChatModelMethod · 0.95

Calls 5

ModelConfigByIDMethod · 0.80
DefaultModelConfigMethod · 0.80
NewMethod · 0.65
IsMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected