adadd conformance tests for azure open ai

Signed-off-by: fabistb <fabian0401@online.de>
This commit is contained in:
fabistb 2025-07-31 12:01:45 +02:00
parent 84e3fe6667
commit 77e1ced4a6
7 changed files with 47 additions and 5 deletions

View File

@ -5,7 +5,7 @@ This directory contains conformance tests for all conversation components, inclu
## Available Components
- **echo** - Simple echo component for testing (no configuration needed)
- **openai** - OpenAI GPT models
- **openai** - OpenAI GPT models (also supports Azure OpenAI)
- **anthropic** - Anthropic Claude models
- **googleai** - Google Gemini models
- **mistral** - Mistral AI models
@ -52,6 +52,14 @@ export OPENAI_API_KEY="your_openai_api_key"
```
Get your API key from: https://platform.openai.com/api-keys
### Azure OpenAI
```bash
export AZURE_OPENAI_API_KEY="your_openai_api_key"
export AZURE_OPENAI_ENDPOINT="your_azureopenai_endpoint_here"
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"
@ -142,4 +150,5 @@ This approach provides better reliability and compatibility while maintaining ac
- Cost-effective models are used by default to minimize API costs
- HuggingFace uses the OpenAI compatibility layer as a workaround due to langchaingo API issues
- Ollama requires a local server and must be explicitly enabled
- OpenAI component is tested for OpenAI and Azure
- All tests include proper initialization and basic conversation functionality testing

View File

@ -4,6 +4,11 @@
# OpenAI API Key - Get from https://platform.openai.com/api-keys
OPENAI_API_KEY=your_openai_api_key_here
# Azure OpenAI - Get from https://ai.azure.com/
AZURE_OPENAI_API_KEY=your_azureopenai_api_key_here
AZURE_OPENAI_ENDPOINT=your_azureopenai_endpoint_here
AZURE_OPENAI_API_VERSION=your_azreopenai_api_version_here
# Anthropic API Key - Get from https://console.anthropic.com/
ANTHROPIC_API_KEY=your_anthropic_api_key_here

View File

@ -0,0 +1,18 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: openai
spec:
type: conversation.openai
version: v1
metadata:
- name: key
value: "${{AZURE_OPENAI_API_KEY}}"
- name: model
value: "gpt-4o-mini"
- name: endpoint
value: "${{AZURE_OPENAI_ENDPOINT}}"
- name: apiType
value: "azure"
- name: apiVersion
value: "${{AZURE_OPENAI_API_VERSION}}"

View File

@ -9,4 +9,4 @@ spec:
- name: key
value: "${{OPENAI_API_KEY}}"
- name: model
value: "gpt-4o-mini"
value: "gpt-4.1"

View File

@ -21,6 +21,9 @@ echo " ./test_conformance.sh"
echo ""
echo "Option 2: Set environment variables directly:"
echo " export OPENAI_API_KEY=\"your_openai_api_key\""
echo " export AZURE_OPENAI_API_KEY=\"your_azureopenai_api_key\""
echo " export AZURE_OPENAI_ENDPOINT=\"your_azureopenai_endpoint\""
echo " export AZURE_OPENAI_API_VERSION=\"your_azureopenai_api_version\""
echo " export ANTHROPIC_API_KEY=\"your_anthropic_api_key\""
echo " export GOOGLE_AI_API_KEY=\"your_google_ai_api_key\""
echo " export MISTRAL_API_KEY=\"your_mistral_api_key\""

View File

@ -2,7 +2,9 @@ componentType: conversation
components:
- component: echo
operations: []
- component: openai
- component: openai.openai
operations: []
- component: openai.azure
operations: []
- component: anthropic
operations: []

View File

@ -73,11 +73,16 @@ func TestConversationConformance(t *testing.T) {
// shouldSkipComponent checks if a component test should be skipped due to missing environment variables
func shouldSkipComponent(t *testing.T, componentName string) bool {
switch componentName {
case "openai":
case "openai.openai":
if os.Getenv("OPENAI_API_KEY") == "" {
t.Skipf("Skipping OpenAI conformance test: OPENAI_API_KEY environment variable not set")
return true
}
case "openai.azure":
if os.Getenv("AZURE_OPENAI_API_KEY") == "" || os.Getenv("AZURE_OPENAI_ENDPOINT") == "" || os.Getenv("AZURE_OPENAI_API_TYPE") == "" || os.Getenv("AZURE_OPENAI_API_VERSION") == "" {
t.Skipf("Skipping Azure OpenAI conformance test: AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_TYPE, and AZURE_OPENAI_API_VERSION environment variables must be set")
return true
}
case "anthropic":
if os.Getenv("ANTHROPIC_API_KEY") == "" {
t.Skipf("Skipping Anthropic conformance test: ANTHROPIC_API_KEY environment variable not set")
@ -117,7 +122,7 @@ func loadConversationComponent(name string) conversation.Conversation {
switch name {
case "echo":
return echo.NewEcho(testLogger)
case "openai":
case "openai.openai", "openai.azure":
return openai.NewOpenAI(testLogger)
case "anthropic":
return anthropic.NewAnthropic(testLogger)