Skip to content

Conversation

giterinhub
Copy link
Contributor

@giterinhub giterinhub commented Apr 14, 2025

Description

This PR implements a comprehensive centralized model management system for all conversation components, providing runtime flexibility and infrastructure-as-code capabilities.

What Changed

🎯 Centralized Model Management

  • Created conversation/models.go with environment variable-driven model constants
  • All conversation providers now use centralized defaults instead of hardcoded values
  • Supports OpenAI, Anthropic, Google AI, Mistral, HuggingFace, and Ollama

🔧 Environment Variable Configuration

  • Models can be overridden at runtime using environment variables:
    • OPENAI_MODEL (default: gpt-5-nano)
    • AZURE_OPENAI_MODEL (default: gpt-4.1-mini)
    • ANTHROPIC_MODEL (default: claude-sonnet-4-20250514)
    • GOOGLEAI_MODEL (default: gemini-2.5-flash-lite)
    • MISTRAL_MODEL (default: open-mistral-7b)
    • HUGGINGFACE_MODEL (default: deepseek-ai/DeepSeek-R1-Distill-Qwen-32B)
    • OLLAMA_MODEL (default: llama3.2:latest)

📁 Updated Files

  • Core: conversation/models.go (new centralized constants)
  • Providers: Updated all 6 conversation provider implementations
  • Config: Updated all YAML configuration files to use environment variables
  • Metadata: Updated metadata.yaml files with environment variable examples
  • Docs: Enhanced README.md with comprehensive environment variable documentation
  • Tests: Updated test configurations where applicable

Benefits

🚀 Runtime Flexibility: Change models without rebuilding/redeploying
🏗️ Infrastructure as Code: Configure models in Docker, Kubernetes, CI/CD
📋 Environment-Specific: Different models for dev/staging/prod
🛡️ Backward Compatible: Sensible defaults when env vars not set
🎯 Future-Proof: Single point of control for model updates

Usage Examples

# Development (cost-effective)
export OPENAI_MODEL="gpt-5-nano"

# Production (best performance)  
export OPENAI_MODEL="gpt-5"

# Testing (fast & cheap)
export OPENAI_MODEL="gpt-5-mini"

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

Copy link

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale label May 25, 2025
@giterinhub
Copy link
Contributor Author

giterinhub commented May 25, 2025

Perhaps 4.1 nano or mini could also now be considered, as 4o-mini has been retired from OpenAI and will retire in September 2025 in Azure.

@github-actions github-actions bot removed the stale label May 25, 2025
@filintod
Copy link
Contributor

@giterinhub you probably want to actually change https://github.com/dapr/components-contrib/blame/main/conversation/openai/openai.go#L44 that is the "real" default, as Metadata.yaml is more like a reference. Also the description in the metadata.yaml would need to change to reflect the default

@cicoyle
Copy link
Contributor

cicoyle commented Jun 24, 2025

Hey @giterinhub - mind fixing the conflicts?

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
@giterinhub
Copy link
Contributor Author

Consistently changed all references to OpenAI models to use "gpt-4.1-nano".

@giterinhub giterinhub reopened this Jul 1, 2025
@giterinhub giterinhub changed the title Set OpenAI Model to gpt-4o-mini and Updated Example Set OpenAI Model to gpt-4.1-nano and Updated Example Jul 1, 2025
Copy link

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale label Jul 31, 2025
Copy link

github-actions bot commented Aug 7, 2025

This pull request has been automatically closed because it has not had activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot closed this Aug 7, 2025
@cicoyle cicoyle reopened this Aug 19, 2025
@cicoyle cicoyle removed the stale label Aug 19, 2025
@cicoyle
Copy link
Contributor

cicoyle commented Aug 19, 2025

Hey @giterinhub - I just noticed the daprbot closed this... Mind fixing the conflicts again?

@filintod
Copy link
Contributor

filintod commented Aug 19, 2025

@giterinhub probably this could now be updated to gpt-5 nano or mini https://platform.openai.com/docs/models

@msfussell
Copy link
Member

@giterinhub - PTAL and update this PR

…tion

- Add conversation/models.go with centralized model constants using env vars
- Update all conversation providers (OpenAI, Anthropic, Google AI, Mistral, HuggingFace, Ollama) to use centralized models
- Replace hardcoded model values in config files with environment variables
- Update metadata.yaml files to document environment variable usage
- Enhance README.md with comprehensive environment variable documentation
- Maintain backward compatibility with sensible fallback defaults

This enables runtime model configuration without code changes, supporting different models per environment (dev/staging/prod) and infrastructure-as-code

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
…tion

- Add conversation/models.go with centralized model constants using env vars
- Update all conversation providers (OpenAI, Anthropic, Google AI, Mistral, HuggingFace, Ollama) to use centralized models
- Replace hardcoded model values in config files with environment variables
- Update metadata.yaml files to document environment variable usage
- Enhance README.md with comprehensive environment variable documentation
- Maintain backward compatibility with sensible fallback defaults

This enables runtime model configuration without code changes, supporting different models per environment (dev/staging/prod) and infrastructure-as-code deployments.

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
…tion

- Add conversation/models.go with centralized model constants using env vars
- Update all conversation providers (OpenAI, Anthropic, Google AI, Mistral, HuggingFace, Ollama) to use centralized models
- Replace hardcoded model values in config files with environment variables
- Update metadata.yaml files to document environment variable usage
- Enhance README.md with comprehensive environment variable documentation
- Maintain backward compatibility with sensible fallback defaults

This enables runtime model configuration without code changes, supporting different models per environment (dev/staging/prod) and infrastructure-as-code deployments.

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
@giterinhub giterinhub changed the title Set OpenAI Model to gpt-4.1-nano and Updated Example Reference Models Centrally, set OpenAI Model to gpt-5-nano and Updated Example Aug 29, 2025
Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
…ed anthropic and google model to latest defaults

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
@filintod
Copy link
Contributor

filintod commented Sep 4, 2025

can you please try running the conformance tests as shown in https://github.com/dapr/components-contrib/blob/fa9ace4ebf8d99d3b124906ca0cf2881b9d72709/tests/config/conversation/README.md.

I checked it out and it shows issues, like all the conversation.Default... do not work as they are defined as lowercase in conversation package. Let me know when it runs ok to test again. Thanks

- Add centralized model management in conversation/models.go with default constants
- Implement Get*Model() functions supporting metadata > env var > default fallback
- Update all conversation providers (openai, anthropic, googleai, mistral, huggingface, ollama) to use centralized model getters
- Add Azure OpenAI model support with AZURE_OPENAI_MODEL env var
- Update test configurations to use optional environment variables with empty string fallbacks
- Enhance test framework to support ${{ENV_VAR||}} syntax for optional env vars
- Remove hardcoded model defaults from test configs, allowing Go code defaults to be used

This enables flexible model configuration: specified in metadata, environment variables, or fallback to sensible

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
@giterinhub
Copy link
Contributor Author

I'm out of credits for the openai API platform, but the tests seem to work now.

@filintod
Copy link
Contributor

filintod commented Sep 4, 2025

tested locally and it did work for the providers. One thing I noticed that I think i've seen before, on gpt-5 temperature should not be provided or be set to 1, or we get an error like. By default we don't provide it but langchaing go still sends the zero value default and we get:

                        Error Trace:    components-contrib/tests/conformance/conversation/conversation.go:84
                        Error:          Received unexpected error:
                                        API returned unexpected status code: 400: Unsupported value: 'temperature' does not support 0 with this model. Only the default (1) value is supported.
                        Test:           TestConversationConformance/openai.openai/converse/get_a_non-empty_response_without_errors

There is a fix in langchaingo main branch tmc/langchaingo#1374 but it is not in a release tag for now, not sure we want to wait for it or not @sicoyle ??

So it would be good to put a comment about this restriction somewhere, that for now (until we update langchainggo) we should add Temperature: 1 to the request. For example in the conformance test file https://github.com/dapr/components-contrib/blob/8d675f486059f77f21b2f0ad7cd303b914d85cbd/tests/conformance/conversation/conversation.go, every request:

			req1 := &conversation.Request{
				Message:     &messages,
				Tools:       &tools,
			}

should be written as

			req1 := &conversation.Request{
				Message:     &messages,
				Tools:       &tools,
				Temperature: 1,
			}

Copy link
Contributor

@sicoyle sicoyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few last comments. Thank you for working through a few review cycles with us on this, but I think it is super close 🎉 🙌

* Conditionally set Temperature=1 for OpenAI models to avoid unsupported temperature=0
* Preserve default behavior for other providers (Grok, Gemini, Anthropic, DeepSeek)
* Reference upstream langchaingo fix: tmc/langchaingo#1374

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
…mprove documentation

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
- Add environment variable references to all model descriptions
- Update defaults to match models.go constants
- Fix environment variable names in examples
- Remove typo in OpenAI description

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
…l retrieval functions

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
@sicoyle
Copy link
Contributor

sicoyle commented Sep 4, 2025

@giterinhub Hi - thanks for being so quick to address feedback :) I am monitoring your PR in my email notifications so I can rereview asap for ya! I was curious if there were any issues with letting the conformance tests use the default vals on the model field in the test config instead of the || suffix approach?

@giterinhub
Copy link
Contributor Author

@giterinhub Hi - thanks for being so quick to address feedback :) I am monitoring your PR in my email notifications so I can rereview asap for ya! I was curious if there were any issues with letting the conformance tests use the default vals on the model field in the test config instead of the || suffix approach?

Hi Sam, thanks for your attention. I had issues when the environment variables weren't set, and needed a way to reference both the environment variables and the default variables, and this seems the most elegant way...

…efaults

- Set model value to empty string in all provider YAML test configs (openai, azure, anthropic, googleai, mistral, huggingface, ollama)

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
Signed-off-by: Erin Lalor <107987318+giterinhub@users.noreply.github.com>
Copy link
Contributor

@sicoyle sicoyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final comments from me - thank you!!

- Swap getModel() order: metadatav> env var > default
- Remove || syntax from test framework
- Update metadata.yaml examples to use actual defaults

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
…iable value

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
@sicoyle
Copy link
Contributor

sicoyle commented Sep 11, 2025

thank you for your efforts and contribution! once build is green we can look to merge 🙌

@yaron2 yaron2 merged commit a9c2ecd into dapr:main Sep 11, 2025
90 checks passed
filintod pushed a commit to filintod/components-contrib that referenced this pull request Sep 14, 2025
…d Example (dapr#3792)

Signed-off-by: Erin La <107987318+giterinhub@users.noreply.github.com>
Signed-off-by: Erin Lalor <107987318+giterinhub@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants