Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
8740c90
updated model version consistently to "gpt-4.1-nano" in various files
giterinhub Jul 1, 2025
cff0983
feat: centralize model management with environment variable configura…
giterinhub Aug 29, 2025
7adfd70
feat: centralize model management with environment variable configura…
giterinhub Aug 29, 2025
6931a29
feat: centralize model management with environment variable configura…
giterinhub Aug 29, 2025
e7a68a8
feat: update model examples to use environment variable placeholders
giterinhub Aug 29, 2025
03e24a7
Merge branch 'main' into main
giterinhub Sep 1, 2025
2d151c1
feat: enhance model retrieval with metadata support in getters. Updat…
giterinhub Sep 3, 2025
fa9ace4
Merge branch 'main' of https://github.com/giterinhub/components-contrib
giterinhub Sep 3, 2025
2c99617
feat: centralize conversation model management with fallback hierarchy
giterinhub Sep 4, 2025
059b3a4
Fix GPT-5 temperature issue in conversation conformance tests
giterinhub Sep 4, 2025
571ebe1
feat: update environment variable names for conversation models and i…
giterinhub Sep 4, 2025
4b860f4
Standardize conversation component metadata with env vars and defaults
giterinhub Sep 4, 2025
d4a7ae5
refactor: replace getModelValue with getModel for consistency in mode…
giterinhub Sep 4, 2025
09e0376
refactor: update conversation test configs to use centralized model d…
giterinhub Sep 9, 2025
0332efb
Merge branch 'main' into main
giterinhub Sep 9, 2025
3f8b574
fix: correct model resolution precedence and update metadata examples
giterinhub Sep 10, 2025
8c81a6e
fix: reorder logic in getModel function to prioritize Environment Var…
giterinhub Sep 11, 2025
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
4 changes: 1 addition & 3 deletions conversation/anthropic/anthropic.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ func NewAnthropic(logger logger.Logger) conversation.Conversation {
return a
}

const defaultModel = "claude-3-5-sonnet-20240620"

func (a *Anthropic) Init(ctx context.Context, meta conversation.Metadata) error {
m := conversation.LangchainMetadata{}
err := kmeta.DecodeMetadata(meta.Properties, &m)
if err != nil {
return err
}

model := defaultModel
model := conversation.DefaultAnthropicModel
if m.Model != "" {
model = m.Model
}
Expand Down
4 changes: 1 addition & 3 deletions conversation/googleai/googleai.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ func NewGoogleAI(logger logger.Logger) conversation.Conversation {
return g
}

const defaultModel = "gemini-1.5-flash"

func (g *GoogleAI) Init(ctx context.Context, meta conversation.Metadata) error {
md := conversation.LangchainMetadata{}
err := kmeta.DecodeMetadata(meta.Properties, &md)
if err != nil {
return err
}

model := defaultModel
model := conversation.DefaultGoogleAIModel
if md.Model != "" {
model = md.Model
}
Expand Down
3 changes: 1 addition & 2 deletions conversation/googleai/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ metadata:
description: |
The GoogleAI LLM to use.
type: string
example: 'gemini-2.0-flash'
default: 'gemini-2.0-flash'
example: '${{DAPR_CONVERSATION_GOOGLEAI_MODEL}}'
- name: cacheTTL
required: false
description: |
Expand Down
5 changes: 1 addition & 4 deletions conversation/huggingface/huggingface.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ func NewHuggingface(logger logger.Logger) conversation.Conversation {
return h
}

// Default model - using a popular and reliable model
const defaultModel = "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B"

// Default HuggingFace OpenAI-compatible endpoint
const defaultEndpoint = "https://router.huggingface.co/hf-inference/models/{{model}}/v1"

Expand All @@ -55,7 +52,7 @@ func (h *Huggingface) Init(ctx context.Context, meta conversation.Metadata) erro
return err
}

model := defaultModel
model := conversation.DefaultHuggingFaceModel
if m.Model != "" {
model = m.Model
}
Expand Down
3 changes: 1 addition & 2 deletions conversation/huggingface/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ metadata:
description: |
The Huggingface model to use. Uses OpenAI-compatible API.
type: string
example: 'deepseek-ai/DeepSeek-R1-Distill-Qwen-32B'
default: 'deepseek-ai/DeepSeek-R1-Distill-Qwen-32B'
example: '${{DAPR_CONVERSATION_HUGGINGFACE_MODEL}}'
- name: endpoint
required: false
description: |
Expand Down
2 changes: 1 addition & 1 deletion conversation/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestLangchainMetadata(t *testing.T) {
t.Run("json marshaling with endpoint", func(t *testing.T) {
metadata := LangchainMetadata{
Key: "test-key",
Model: "gpt-4",
Model: DefaultOpenAIModel,
CacheTTL: "10m",
Endpoint: "https://custom-endpoint.example.com",
}
Expand Down
2 changes: 1 addition & 1 deletion conversation/mistral/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ metadata:
description: |
The Mistral LLM to use.
type: string
example: 'open-mistral-7b'
example: '${{DAPR_CONVERSATION_MISTRAL_MODEL}}'
default: 'open-mistral-7b'
- name: cacheTTL
required: false
Expand Down
4 changes: 1 addition & 3 deletions conversation/mistral/mistral.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ func NewMistral(logger logger.Logger) conversation.Conversation {
return m
}

const defaultModel = "open-mistral-7b"

func (m *Mistral) Init(ctx context.Context, meta conversation.Metadata) error {
md := conversation.LangchainMetadata{}
err := kmeta.DecodeMetadata(meta.Properties, &md)
if err != nil {
return err
}

model := defaultModel
model := conversation.DefaultMistralModel
if md.Model != "" {
model = md.Model
}
Expand Down
70 changes: 70 additions & 0 deletions conversation/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package conversation

import (
"os"
)

// Default models for conversation components
// These can be overridden via environment variables for runtime configuration
const (
// Environment variable names
envOpenAIModel = "DAPR_CONVERSATION_OPENAI_MODEL"
envAnthropicModel = "DAPR_CONVERSATION_ANTHROPIC_MODEL"
envGoogleAIModel = "DAPR_CONVERSATION_GOOGLEAI_MODEL"
envMistralModel = "DAPR_CONVERSATION_MISTRAL_MODEL"
envHuggingFaceModel = "DAPR_CONVERSATION_HUGGINGFACE_MODEL"
envOllamaModel = "DAPR_CONVERSATION_OLLAMA_MODEL"
)

// Default model values (used as fallbacks when env vars are not set)
const (
defaultOpenAIModel = "gpt-5-nano"
defaultAnthropicModel = "claude-3-5-sonnet-20240620"
defaultGoogleAIModel = "gemini-1.5-flash"
defaultMistralModel = "open-mistral-7b"
defaultHuggingFaceModel = "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B"
defaultOllamaModel = "llama3.2:latest"
)

// getEnvOrDefault returns the value of an environment variable or a default value
func getEnvOrDefault(envVar, defaultValue string) string {
if value := os.Getenv(envVar); value != "" {
return value
}
return defaultValue
}

// Default model getters that check environment variables first
var (
// DefaultOpenAIModel returns the OpenAI model, checking env var first
DefaultOpenAIModel = getEnvOrDefault(envOpenAIModel, defaultOpenAIModel)

// DefaultAnthropicModel returns the Anthropic model, checking env var first
DefaultAnthropicModel = getEnvOrDefault(envAnthropicModel, defaultAnthropicModel)

// DefaultGoogleAIModel returns the Google AI model, checking env var first
DefaultGoogleAIModel = getEnvOrDefault(envGoogleAIModel, defaultGoogleAIModel)

// DefaultMistralModel returns the Mistral model, checking env var first
DefaultMistralModel = getEnvOrDefault(envMistralModel, defaultMistralModel)

// DefaultHuggingFaceModel returns the HuggingFace model, checking env var first
DefaultHuggingFaceModel = getEnvOrDefault(envHuggingFaceModel, defaultHuggingFaceModel)

// DefaultOllamaModel returns the Ollama model, checking env var first
DefaultOllamaModel = getEnvOrDefault(envOllamaModel, defaultOllamaModel)
)
3 changes: 1 addition & 2 deletions conversation/ollama/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ metadata:
description: |
The Ollama LLM to use.
type: string
example: 'llama3.2:latest'
default: 'llama3.2:latest'
example: '${{DAPR_CONVERSATION_OLLAMA_MODEL}}'
- name: cacheTTL
required: false
description: |
Expand Down
4 changes: 1 addition & 3 deletions conversation/ollama/ollama.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ func NewOllama(logger logger.Logger) conversation.Conversation {
return o
}

const defaultModel = "llama3.2:latest"

func (o *Ollama) Init(ctx context.Context, meta conversation.Metadata) error {
md := conversation.LangchainMetadata{}
err := kmeta.DecodeMetadata(meta.Properties, &md)
if err != nil {
return err
}

model := defaultModel
model := conversation.DefaultOllamaModel
if md.Model != "" {
model = md.Model
}
Expand Down
5 changes: 2 additions & 3 deletions conversation/openai/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ metadata:
- name: model
required: false
description: |
The OpenAI LLM to use.
The OpenAI LLM to use. Defaults to gpt-5-nano (configurable via DAPR_CONVERSATION_OPENAI_MODEL environment variable)
type: string
example: 'gpt-4-turbo'
default: 'gpt-4o'
example: '${{DAPR_CONVERSATION_OPENAI_MODEL}}'
- name: endpoint
required: false
description: |
Expand Down
4 changes: 1 addition & 3 deletions conversation/openai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ func NewOpenAI(logger logger.Logger) conversation.Conversation {
return o
}

const defaultModel = "gpt-4o"

func (o *OpenAI) Init(ctx context.Context, meta conversation.Metadata) error {
md := OpenAILangchainMetadata{}
err := kmeta.DecodeMetadata(meta.Properties, &md)
if err != nil {
return err
}

model := defaultModel
model := conversation.DefaultOpenAIModel
if md.Model != "" {
model = md.Model
}
Expand Down
10 changes: 5 additions & 5 deletions conversation/openai/openai_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestInit(t *testing.T) {
name: "with default endpoint",
metadata: map[string]string{
"key": "test-key",
"model": "gpt-4",
"model": conversation.DefaultOpenAIModel,
},
testFn: func(t *testing.T, o *OpenAI, err error) {
require.NoError(t, err)
Expand All @@ -45,7 +45,7 @@ func TestInit(t *testing.T) {
name: "with custom endpoint",
metadata: map[string]string{
"key": "test-key",
"model": "gpt-4",
"model": conversation.DefaultOpenAIModel,
"endpoint": "https://api.openai.com/v1",
},
testFn: func(t *testing.T, o *OpenAI, err error) {
Expand All @@ -59,7 +59,7 @@ func TestInit(t *testing.T) {
name: "with apiType azure and missing apiVersion",
metadata: map[string]string{
"key": "test-key",
"model": "gpt-4",
"model": conversation.DefaultOpenAIModel,
"apiType": "azure",
"endpoint": "https://custom-endpoint.openai.azure.com/",
},
Expand All @@ -72,7 +72,7 @@ func TestInit(t *testing.T) {
name: "with apiType azure and custom apiVersion",
metadata: map[string]string{
"key": "test-key",
"model": "gpt-4",
"model": conversation.DefaultOpenAIModel,
"apiType": "azure",
"endpoint": "https://custom-endpoint.openai.azure.com/",
"apiVersion": "2025-01-01-preview",
Expand All @@ -86,7 +86,7 @@ func TestInit(t *testing.T) {
name: "with apiType azure but missing endpoint",
metadata: map[string]string{
"key": "test-key",
"model": "gpt-4",
"model": conversation.DefaultOpenAIModel,
"apiType": "azure",
"apiVersion": "2025-01-01-preview",
},
Expand Down
54 changes: 40 additions & 14 deletions tests/config/conversation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,21 @@ cp env.template .env

Alternatively, you can set the following environment variables to run the respective tests:

### OpenAI
#### Model Configuration (Optional)

You can override the default models used by each component by setting these environment variables:

```bash
export DAPR_CONVERSATION_OPENAI_MODEL="gpt-5-nano" # Default: gpt-5-nano
export DAPR_CONVERSATION_ANTHROPIC_MODEL="claude-3-5-sonnet-20240620" # Default: claude-3-5-sonnet-20240620
export DAPR_CONVERSATION_GOOGLEAI_MODEL="gemini-1.5-flash" # Default: gemini-1.5-flash
export DAPR_CONVERSATION_MISTRAL_MODEL="open-mistral-7b" # Default: open-mistral-7b
export DAPR_CONVERSATION_HUGGINGFACE_MODEL="deepseek-ai/DeepSeek-R1-Distill-Qwen-32B" # Default: deepseek-ai/DeepSeek-R1-Distill-Qwen-32B
export DAPR_CONVERSATION_OLLAMA_MODEL="llama3.2:latest" # Default: llama3.2:latest
```

#### OpenAI

```bash
export OPENAI_API_KEY="your_openai_api_key"
```
Expand All @@ -60,50 +74,60 @@ export AZURE_OPENAI_API_VERSION="your_azreopenai_api_version_here"
```
Get your configuration values from: https://ai.azure.com/

### Anthropic
```bash
export ANTHROPIC_API_KEY="your_anthropic_api_key"
```
Get your API key from: https://console.anthropic.com/

### Google AI
Get your API key from: <https://console.anthropic.com/>

#### Google AI

```bash
export GOOGLE_AI_API_KEY="your_google_ai_api_key"
```
Get your API key from: https://aistudio.google.com/app/apikey

### Mistral
Get your API key from: <https://aistudio.google.com/app/apikey>

#### Mistral

```bash
export MISTRAL_API_KEY="your_mistral_api_key"
```
Get your API key from: https://console.mistral.ai/

### HuggingFace
Get your API key from: <https://console.mistral.ai/>

#### HuggingFace

```bash
export HUGGINGFACE_API_KEY="your_huggingface_api_key"
```
Get your API key from: https://huggingface.co/settings/tokens

### AWS Bedrock
Get your API key from: <https://huggingface.co/settings/tokens>

#### AWS Bedrock

```bash
export AWS_ACCESS_KEY_ID="your_aws_access_key"
export AWS_SECRET_ACCESS_KEY="your_aws_secret_key"
export AWS_REGION="us-east-1" # Optional, defaults to us-east-1
```

Get your credentials from AWS Console

### Ollama
#### Ollama

```bash
export OLLAMA_ENABLED="1"
```

Requires a local Ollama server running with the `llama3.2:latest` model available.

## Test Configuration

Each component has its own configuration file in this directory:

- `echo/echo.yml` - Echo component configuration
- `openai/openai.yml` - OpenAI configuration with gpt-4o-mini model
- `openai/openai.yml` - OpenAI configuration with gpt-5-nano model
- `anthropic/anthropic.yml` - Anthropic configuration with Claude 3 Haiku
- `googleai/googleai.yml` - Google AI configuration with Gemini 1.5 Flash
- `mistral/mistral.yml` - Mistral configuration with open-mistral-7b
Expand All @@ -117,13 +141,15 @@ The configurations use cost-effective models where possible to minimize testing

The HuggingFace component uses a workaround due to issues with the native HuggingFace implementation in langchaingo. Instead of using the HuggingFace SDK directly, it uses the OpenAI SDK with HuggingFace's OpenAI-compatible API endpoints.

### How it works:
### How it works

- **Model Selection**: Any HuggingFace model can be used by specifying its full name (e.g., `deepseek-ai/DeepSeek-R1-Distill-Qwen-32B`)
- **Dynamic Endpoints**: The endpoint URL is automatically generated based on the model name using the template: `https://router.huggingface.co/hf-inference/models/{{model}}/v1`
- **Custom Endpoints**: You can override the endpoint by specifying a custom `endpoint` parameter
- **Authentication**: Uses the same HuggingFace API key authentication

### Example Configuration:
### Example Configuration

```yaml
apiVersion: dapr.io/v1alpha1
kind: Component
Expand Down
Loading