mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 16:40:50 +08:00
feat: add Query method to ILLMService interface
- Add Query method to ILLMService interface for unified AI service access - Update combinedLLMService to include querier functionality - Add comprehensive tests for ILLMService Query method - Support both basic query and custom schema query through unified interface - Add environment variable checks for test reliability This allows users to access all AI capabilities (planning, assertion, and query) through a single ILLMService interface, providing better API consistency and ease of use.
This commit is contained in:
+16
-4
@@ -7,10 +7,11 @@ import (
|
||||
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||
)
|
||||
|
||||
// ILLMService 定义了 LLM 服务接口,包括规划和断言功能
|
||||
// ILLMService 定义了 LLM 服务接口,包括规划、断言和查询功能
|
||||
type ILLMService interface {
|
||||
Call(ctx context.Context, opts *PlanningOptions) (*PlanningResult, error)
|
||||
Assert(ctx context.Context, opts *AssertOptions) (*AssertionResult, error)
|
||||
Query(ctx context.Context, opts *QueryOptions) (*QueryResult, error)
|
||||
// RegisterTools registers tools for function calling
|
||||
RegisterTools(tools []*schema.ToolInfo) error
|
||||
}
|
||||
@@ -29,18 +30,24 @@ func NewLLMService(modelType option.LLMServiceType) (ILLMService, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
querier, err := NewQuerier(context.Background(), modelConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &combinedLLMService{
|
||||
planner: planner,
|
||||
asserter: asserter,
|
||||
querier: querier,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// combinedLLMService 实现了 ILLMService 接口,组合了规划和断言功能
|
||||
// ⭐️支持采用不同的模型服务进行规划和断言
|
||||
// combinedLLMService 实现了 ILLMService 接口,组合了规划、断言和查询功能
|
||||
// ⭐️支持采用不同的模型服务进行规划、断言和查询
|
||||
type combinedLLMService struct {
|
||||
planner IPlanner // 提供规划功能
|
||||
asserter IAsserter // 提供断言功能
|
||||
querier IQuerier // 提供查询功能
|
||||
}
|
||||
|
||||
// Call 执行规划功能
|
||||
@@ -53,9 +60,14 @@ func (c *combinedLLMService) Assert(ctx context.Context, opts *AssertOptions) (*
|
||||
return c.asserter.Assert(ctx, opts)
|
||||
}
|
||||
|
||||
// Query 执行查询功能
|
||||
func (c *combinedLLMService) Query(ctx context.Context, opts *QueryOptions) (*QueryResult, error) {
|
||||
return c.querier.Query(ctx, opts)
|
||||
}
|
||||
|
||||
// RegisterTools registers tools for function calling
|
||||
func (c *combinedLLMService) RegisterTools(tools []*schema.ToolInfo) error {
|
||||
// Only register tools to planner since asserter doesn't need tools
|
||||
// Only register tools to planner since asserter and querier don't need tools
|
||||
if planner, ok := c.planner.(*Planner); ok {
|
||||
return planner.RegisterTools(tools)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user