From 05191dc892e6b8bb2815560b1a29a7a6198a6d2c Mon Sep 17 00:00:00 2001 From: Yasir Ekinci Date: Fri, 18 Oct 2024 13:38:02 +0200 Subject: [PATCH 1/3] ModelFromString: support gpt-4o-mini --- .../grafana-llm-app/pkg/plugin/llm_provider.go | 4 ++-- .../pkg/plugin/llm_provider_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/grafana-llm-app/pkg/plugin/llm_provider.go b/packages/grafana-llm-app/pkg/plugin/llm_provider.go index 2921fcbd..d35fc3d9 100644 --- a/packages/grafana-llm-app/pkg/plugin/llm_provider.go +++ b/packages/grafana-llm-app/pkg/plugin/llm_provider.go @@ -25,9 +25,9 @@ const ( // compatability, or the new abstract model names. func ModelFromString(m string) (Model, error) { switch { - case m == ModelLarge || strings.HasPrefix(m, "gpt-4"): + case m == ModelLarge || (strings.HasPrefix(m, "gpt-4") && !strings.Contains(m, "-mini")): return ModelLarge, nil - case m == ModelBase || strings.HasPrefix(m, "gpt-3.5"): + case m == ModelBase || strings.HasPrefix(m, "gpt-3.5") || strings.Contains(m, "-mini"): return ModelBase, nil } // TODO: Give users the ability to specify a default model abstraction in settings, and use that here. diff --git a/packages/grafana-llm-app/pkg/plugin/llm_provider_test.go b/packages/grafana-llm-app/pkg/plugin/llm_provider_test.go index a15e1c4b..cf387fff 100644 --- a/packages/grafana-llm-app/pkg/plugin/llm_provider_test.go +++ b/packages/grafana-llm-app/pkg/plugin/llm_provider_test.go @@ -49,6 +49,16 @@ func TestModelFromString(t *testing.T) { expected: ModelBase, wantErr: false, }, + { + input: "gpt-4o-mini", + expected: ModelBase, + wantErr: false, + }, + { + input: "gpt-4o-mini-2024-07-18", + expected: ModelBase, + wantErr: false, + }, { input: "gpt-4-turbo", expected: ModelLarge, @@ -64,6 +74,11 @@ func TestModelFromString(t *testing.T) { expected: ModelLarge, wantErr: false, }, + { + input: "gpt-4o", + expected: ModelLarge, + wantErr: false, + }, { input: "gpt-4-32k-0613", expected: ModelLarge, From ff6a8a7c662f47ed12b17882785878eadd42fdba Mon Sep 17 00:00:00 2001 From: Yasir Ekinci Date: Fri, 18 Oct 2024 13:31:08 +0200 Subject: [PATCH 2/3] update default models to 4o / 4o-mini --- packages/grafana-llm-app/llmclient/llmclient.go | 4 ++-- packages/grafana-llm-app/pkg/plugin/llm_provider.go | 4 ++-- packages/grafana-llm-app/pkg/plugin/settings.go | 4 ++-- .../grafana-llm-app/src/components/AppConfig/ModelConfig.tsx | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/grafana-llm-app/llmclient/llmclient.go b/packages/grafana-llm-app/llmclient/llmclient.go index 9bf69019..a68ddd1d 100644 --- a/packages/grafana-llm-app/llmclient/llmclient.go +++ b/packages/grafana-llm-app/llmclient/llmclient.go @@ -23,9 +23,9 @@ const ( type Model string const ( - // ModelBase is the base model, for efficient and high-throughput tasks. OpenAI default: gpt-3.5-turbo + // ModelBase is the base model, for efficient and high-throughput tasks. OpenAI default: gpt-4o-mini ModelBase = "base" - // ModelLarge is the large model, for more advanced tasks with longer context windows. OpenAI default: gpt-4-turbo + // ModelLarge is the large model, for more advanced tasks with longer context windows. OpenAI default: gpt-4o ModelLarge = "large" ) diff --git a/packages/grafana-llm-app/pkg/plugin/llm_provider.go b/packages/grafana-llm-app/pkg/plugin/llm_provider.go index d35fc3d9..ed23783d 100644 --- a/packages/grafana-llm-app/pkg/plugin/llm_provider.go +++ b/packages/grafana-llm-app/pkg/plugin/llm_provider.go @@ -54,9 +54,9 @@ func (m Model) toOpenAI(modelSettings *ModelSettings) string { if modelSettings == nil || len(modelSettings.Mapping) == 0 { switch m { case ModelBase: - return "gpt-3.5-turbo" + return "gpt-4o-mini" case ModelLarge: - return "gpt-4-turbo" + return "gpt-4o" } panic(fmt.Sprintf("unrecognized model: %s", m)) } diff --git a/packages/grafana-llm-app/pkg/plugin/settings.go b/packages/grafana-llm-app/pkg/plugin/settings.go index b2c37c3c..a2572620 100644 --- a/packages/grafana-llm-app/pkg/plugin/settings.go +++ b/packages/grafana-llm-app/pkg/plugin/settings.go @@ -100,8 +100,8 @@ func (c ModelSettings) getModel(model Model) string { var DEFAULT_MODEL_SETTINGS = &ModelSettings{ Default: ModelBase, Mapping: map[Model]string{ - ModelBase: "gpt-3.5-turbo", - ModelLarge: "gpt-4-turbo", + ModelBase: "gpt-4o-mini", + ModelLarge: "gpt-4o", }, } diff --git a/packages/grafana-llm-app/src/components/AppConfig/ModelConfig.tsx b/packages/grafana-llm-app/src/components/AppConfig/ModelConfig.tsx index 43734894..00187d4d 100644 --- a/packages/grafana-llm-app/src/components/AppConfig/ModelConfig.tsx +++ b/packages/grafana-llm-app/src/components/AppConfig/ModelConfig.tsx @@ -22,13 +22,13 @@ const DEFAULT_MODEL_ID = openai.Model.BASE; const MODEL_MAPPING_CONFIG: ModelMappingConfig[] = [ { id: openai.Model.BASE, - name: 'gpt-3.5-turbo', + name: 'gpt-4o-mini', label: 'Base', description: 'A fast and cost-effective model for efficient, high-throughput tasks.', }, { id: openai.Model.LARGE, - name: 'gpt-4-turbo', + name: 'gpt-4o', label: 'Large', description: 'A larger, higher cost model for more advanced tasks with longer context windows.', }, From 2d2f25858171393691c5608601ef4f7603098bad Mon Sep 17 00:00:00 2001 From: Yasir Ekinci Date: Fri, 18 Oct 2024 13:39:11 +0200 Subject: [PATCH 3/3] update README with model abstraction --- packages/grafana-llm-app/README.md | 2 +- packages/grafana-llm-app/src/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/grafana-llm-app/README.md b/packages/grafana-llm-app/README.md index ddc4055c..e080a3ce 100644 --- a/packages/grafana-llm-app/README.md +++ b/packages/grafana-llm-app/README.md @@ -224,7 +224,7 @@ const MyComponent = (): JSX.Element => { // Stream the completions. Each element is the next stream chunk. const stream = llms.openai .streamChatCompletions({ - model: 'gpt-3.5-turbo', + model: llms.openai.Model.BASE, messages: [ { role: 'system', content: 'You are a cynical assistant.' }, { role: 'user', content: message }, diff --git a/packages/grafana-llm-app/src/README.md b/packages/grafana-llm-app/src/README.md index bb6d8f22..21c7f4bd 100644 --- a/packages/grafana-llm-app/src/README.md +++ b/packages/grafana-llm-app/src/README.md @@ -78,7 +78,7 @@ const MyComponent = (): JSX.Element => { // Stream the completions. Each element is the next stream chunk. const stream = llms.openai .streamChatCompletions({ - model: 'gpt-3.5-turbo', + model: llms.openai.Model.BASE messages: [ { role: 'system', content: 'You are a cynical assistant.' }, { role: 'user', content: message },