mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
change: replace openai model with ark model
This commit is contained in:
+9
-9
@@ -4,16 +4,17 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/cloudwego/eino-ext/components/model/openai"
|
||||
openai2 "github.com/cloudwego/eino-ext/libs/acl/openai"
|
||||
"github.com/cloudwego/eino-ext/components/model/ark"
|
||||
"github.com/cloudwego/eino/components/model"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/getkin/kin-openapi/openapi3gen"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
arkModel "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/code"
|
||||
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||
"github.com/httprunner/httprunner/v5/uixt/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// IAsserter interface defines the contract for assertion operations
|
||||
@@ -65,10 +66,9 @@ func NewAsserter(ctx context.Context, modelConfig *ModelConfig) (*Asserter, erro
|
||||
return nil, errors.Wrap(code.LLMPrepareRequestError, err.Error())
|
||||
}
|
||||
// set structured response format
|
||||
// https://github.com/cloudwego/eino-ext/blob/main/components/model/openai/examples/structured/structured.go
|
||||
modelConfig.ChatModelConfig.ResponseFormat = &openai2.ChatCompletionResponseFormat{
|
||||
Type: openai2.ChatCompletionResponseFormatTypeJSONSchema,
|
||||
JSONSchema: &openai2.ChatCompletionResponseFormatJSONSchema{
|
||||
modelConfig.ChatModelConfig.ResponseFormat = &ark.ResponseFormat{
|
||||
Type: arkModel.ResponseFormatJSONSchema,
|
||||
JSONSchema: &arkModel.ResponseFormatJSONSchemaJSONSchemaParam{
|
||||
Name: "assertion_result",
|
||||
Description: "data that describes assertion result",
|
||||
Schema: outputFormatSchema.Value,
|
||||
@@ -78,7 +78,7 @@ func NewAsserter(ctx context.Context, modelConfig *ModelConfig) (*Asserter, erro
|
||||
}
|
||||
|
||||
var err error
|
||||
asserter.model, err = openai.NewChatModel(ctx, modelConfig.ChatModelConfig)
|
||||
asserter.model, err = ark.NewChatModel(ctx, modelConfig.ChatModelConfig)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(code.LLMPrepareRequestError, err.Error())
|
||||
}
|
||||
|
||||
+5
-7
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cloudwego/eino-ext/components/model/openai"
|
||||
"github.com/cloudwego/eino-ext/components/model/ark"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
@@ -21,9 +21,7 @@ const (
|
||||
EnvModelName = "LLM_MODEL_NAME"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultTimeout = 120 * time.Second
|
||||
)
|
||||
var defaultTimeout = 120 * time.Second
|
||||
|
||||
// GetModelConfig get OpenAI config
|
||||
func GetModelConfig(modelType option.LLMServiceType) (*ModelConfig, error) {
|
||||
@@ -39,11 +37,11 @@ func GetModelConfig(modelType option.LLMServiceType) (*ModelConfig, error) {
|
||||
// https://www.volcengine.com/docs/82379/1536429
|
||||
temperature := float32(0)
|
||||
topP := float32(0.7)
|
||||
modelConfig := &openai.ChatModelConfig{
|
||||
modelConfig := &ark.ChatModelConfig{
|
||||
BaseURL: baseURL,
|
||||
APIKey: apiKey,
|
||||
Model: modelName,
|
||||
Timeout: defaultTimeout,
|
||||
Timeout: &defaultTimeout,
|
||||
Temperature: &temperature,
|
||||
TopP: &topP,
|
||||
}
|
||||
@@ -63,7 +61,7 @@ func GetModelConfig(modelType option.LLMServiceType) (*ModelConfig, error) {
|
||||
}
|
||||
|
||||
type ModelConfig struct {
|
||||
*openai.ChatModelConfig
|
||||
*ark.ChatModelConfig
|
||||
ModelType option.LLMServiceType
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -3,14 +3,15 @@ package ai
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/eino-ext/components/model/openai"
|
||||
"github.com/cloudwego/eino-ext/components/model/ark"
|
||||
"github.com/cloudwego/eino/components/model"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/code"
|
||||
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||
"github.com/httprunner/httprunner/v5/uixt/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type IPlanner interface {
|
||||
@@ -42,7 +43,7 @@ func NewPlanner(ctx context.Context, modelConfig *ModelConfig) (*Planner, error)
|
||||
}
|
||||
|
||||
var err error
|
||||
planner.model, err = openai.NewChatModel(ctx, modelConfig.ChatModelConfig)
|
||||
planner.model, err = ark.NewChatModel(ctx, modelConfig.ChatModelConfig)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(code.LLMPrepareRequestError, err.Error())
|
||||
}
|
||||
|
||||
+12
-11
@@ -5,16 +5,17 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/cloudwego/eino-ext/components/model/openai"
|
||||
openai2 "github.com/cloudwego/eino-ext/libs/acl/openai"
|
||||
"github.com/cloudwego/eino-ext/components/model/ark"
|
||||
"github.com/cloudwego/eino/components/model"
|
||||
"github.com/cloudwego/eino/schema"
|
||||
"github.com/getkin/kin-openapi/openapi3gen"
|
||||
"github.com/pkg/errors"
|
||||
arkModel "github.com/volcengine/volcengine-go-sdk/service/arkruntime/model"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/code"
|
||||
"github.com/httprunner/httprunner/v5/internal/json"
|
||||
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||
"github.com/httprunner/httprunner/v5/uixt/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// IQuerier interface defines the contract for query operations
|
||||
@@ -68,9 +69,9 @@ func NewQuerier(ctx context.Context, modelConfig *ModelConfig) (*Querier, error)
|
||||
return nil, errors.Wrap(code.LLMPrepareRequestError, err.Error())
|
||||
}
|
||||
// set structured response format
|
||||
modelConfig.ChatModelConfig.ResponseFormat = &openai2.ChatCompletionResponseFormat{
|
||||
Type: openai2.ChatCompletionResponseFormatTypeJSONSchema,
|
||||
JSONSchema: &openai2.ChatCompletionResponseFormatJSONSchema{
|
||||
modelConfig.ChatModelConfig.ResponseFormat = &ark.ResponseFormat{
|
||||
Type: arkModel.ResponseFormatJSONSchema,
|
||||
JSONSchema: &arkModel.ResponseFormatJSONSchemaJSONSchemaParam{
|
||||
Name: "query_result",
|
||||
Description: "data that describes query result",
|
||||
Schema: outputFormatSchema.Value,
|
||||
@@ -80,7 +81,7 @@ func NewQuerier(ctx context.Context, modelConfig *ModelConfig) (*Querier, error)
|
||||
}
|
||||
|
||||
var err error
|
||||
querier.model, err = openai.NewChatModel(ctx, modelConfig.ChatModelConfig)
|
||||
querier.model, err = ark.NewChatModel(ctx, modelConfig.ChatModelConfig)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(code.LLMPrepareRequestError, err.Error())
|
||||
}
|
||||
@@ -207,9 +208,9 @@ func (q *Querier) queryWithCustomSchema(ctx context.Context, opts *QueryOptions)
|
||||
}
|
||||
|
||||
// Create custom response format with the provided schema
|
||||
modelConfig.ChatModelConfig.ResponseFormat = &openai2.ChatCompletionResponseFormat{
|
||||
Type: openai2.ChatCompletionResponseFormatTypeJSONSchema,
|
||||
JSONSchema: &openai2.ChatCompletionResponseFormatJSONSchema{
|
||||
modelConfig.ChatModelConfig.ResponseFormat = &ark.ResponseFormat{
|
||||
Type: arkModel.ResponseFormatJSONSchema,
|
||||
JSONSchema: &arkModel.ResponseFormatJSONSchemaJSONSchemaParam{
|
||||
Name: "custom_query_result",
|
||||
Description: "custom structured data response",
|
||||
Schema: outputFormatSchema.Value,
|
||||
@@ -219,7 +220,7 @@ func (q *Querier) queryWithCustomSchema(ctx context.Context, opts *QueryOptions)
|
||||
}
|
||||
|
||||
// Create a new model instance with custom schema
|
||||
model, err := openai.NewChatModel(ctx, modelConfig.ChatModelConfig)
|
||||
model, err := ark.NewChatModel(ctx, modelConfig.ChatModelConfig)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(code.LLMPrepareRequestError, err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user