|
| 1 | +/* |
| 2 | +Copyright 2025 The Dapr Authors |
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License. |
| 14 | +*/ |
| 15 | +package conversation |
| 16 | + |
| 17 | +import ( |
| 18 | + "os" |
| 19 | +) |
| 20 | + |
| 21 | +// Default models for conversation components |
| 22 | +// These can be overridden via environment variables for runtime configuration |
| 23 | +const ( |
| 24 | + // Environment variable names |
| 25 | + envOpenAIModel = "OPENAI_MODEL" |
| 26 | + envAzureOpenAIModel = "AZURE_OPENAI_MODEL" |
| 27 | + envAnthropicModel = "ANTHROPIC_MODEL" |
| 28 | + envGoogleAIModel = "GOOGLEAI_MODEL" |
| 29 | + envMistralModel = "MISTRAL_MODEL" |
| 30 | + envHuggingFaceModel = "HUGGINGFACE_MODEL" |
| 31 | + envOllamaModel = "OLLAMA_MODEL" |
| 32 | +) |
| 33 | + |
| 34 | +// Exported default model constants for consumers of the conversation package. |
| 35 | +// These are used as fallbacks when env vars and metadata are not set. |
| 36 | +const ( |
| 37 | + DefaultOpenAIModel = "gpt-5-nano" // Enable GPT-5 (Preview) for all clients |
| 38 | + DefaultAzureOpenAIModel = "gpt-4.1-nano" // Default Azure OpenAI model |
| 39 | + DefaultAnthropicModel = "claude-sonnet-4-20250514" |
| 40 | + DefaultGoogleAIModel = "gemini-2.5-flash-lite" |
| 41 | + DefaultMistralModel = "open-mistral-7b" |
| 42 | + DefaultHuggingFaceModel = "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B" |
| 43 | + DefaultOllamaModel = "llama3.2:latest" |
| 44 | +) |
| 45 | + |
| 46 | +// getModel returns the value of an environment variable or a default value |
| 47 | +func getModel(envVar, defaultValue, metadataValue string) string { |
| 48 | + if value := os.Getenv(envVar); value != "" { |
| 49 | + return value |
| 50 | + } |
| 51 | + if metadataValue != "" { |
| 52 | + return metadataValue |
| 53 | + } |
| 54 | + return defaultValue |
| 55 | +} |
| 56 | + |
| 57 | +// Example usage for model getters with metadata support: |
| 58 | +// Pass metadataValue from your metadata file/struct, or "" if not set. |
| 59 | +func GetOpenAIModel(metadataValue string) string { |
| 60 | + return getModel(envOpenAIModel, DefaultOpenAIModel, metadataValue) |
| 61 | +} |
| 62 | + |
| 63 | +func GetAzureOpenAIModel(metadataValue string) string { |
| 64 | + return getModel(envAzureOpenAIModel, DefaultAzureOpenAIModel, metadataValue) |
| 65 | +} |
| 66 | + |
| 67 | +func GetAnthropicModel(metadataValue string) string { |
| 68 | + return getModel(envAnthropicModel, DefaultAnthropicModel, metadataValue) |
| 69 | +} |
| 70 | + |
| 71 | +func GetGoogleAIModel(metadataValue string) string { |
| 72 | + return getModel(envGoogleAIModel, DefaultGoogleAIModel, metadataValue) |
| 73 | +} |
| 74 | + |
| 75 | +func GetMistralModel(metadataValue string) string { |
| 76 | + return getModel(envMistralModel, DefaultMistralModel, metadataValue) |
| 77 | +} |
| 78 | + |
| 79 | +func GetHuggingFaceModel(metadataValue string) string { |
| 80 | + return getModel(envHuggingFaceModel, DefaultHuggingFaceModel, metadataValue) |
| 81 | +} |
| 82 | + |
| 83 | +func GetOllamaModel(metadataValue string) string { |
| 84 | + return getModel(envOllamaModel, DefaultOllamaModel, metadataValue) |
| 85 | +} |
0 commit comments