mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
fix: load env
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2503221523
|
v5.0.0-beta-2503231006
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ func loadEnv() {
|
|||||||
Str("path", envFile).Msg("overload env file failed")
|
Str("path", envFile).Msg("overload env file failed")
|
||||||
}
|
}
|
||||||
log.Info().Str("path", envFile).Msg("overload env success")
|
log.Info().Str("path", envFile).Msg("overload env success")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// reached root directory
|
// reached root directory
|
||||||
@@ -154,6 +155,12 @@ func (c *CustomTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||||||
return c.Transport.RoundTrip(req)
|
return c.Transport.RoundTrip(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OutputFormat struct {
|
||||||
|
Thought string `json:"thought"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// GetModelConfig get OpenAI config
|
// GetModelConfig get OpenAI config
|
||||||
func GetModelConfig() (*openai.ChatModelConfig, error) {
|
func GetModelConfig() (*openai.ChatModelConfig, error) {
|
||||||
loadEnv()
|
loadEnv()
|
||||||
@@ -169,6 +176,11 @@ func GetModelConfig() (*openai.ChatModelConfig, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// outputFormatSchema, err := openapi3gen.NewSchemaRefForValue(&OutputFormat{}, nil)
|
||||||
|
// if err != nil {
|
||||||
|
// log.Fatal().Err(err).Msg("NewSchemaRefForValue failed")
|
||||||
|
// }
|
||||||
|
|
||||||
config := &openai.ChatModelConfig{
|
config := &openai.ChatModelConfig{
|
||||||
HTTPClient: &http.Client{
|
HTTPClient: &http.Client{
|
||||||
Timeout: defaultTimeout,
|
Timeout: defaultTimeout,
|
||||||
@@ -177,6 +189,17 @@ func GetModelConfig() (*openai.ChatModelConfig, error) {
|
|||||||
Headers: envConfig.Headers,
|
Headers: envConfig.Headers,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
// TODO: set structured response format
|
||||||
|
// https://github.com/cloudwego/eino-ext/blob/main/components/model/openai/examples/structured/structured.go
|
||||||
|
// ResponseFormat: &openai2.ChatCompletionResponseFormat{
|
||||||
|
// Type: openai2.ChatCompletionResponseFormatTypeJSONSchema,
|
||||||
|
// JSONSchema: &openai2.ChatCompletionResponseFormatJSONSchema{
|
||||||
|
// Name: "thought_and_action",
|
||||||
|
// Description: "data that describes planning thought and action",
|
||||||
|
// Schema: outputFormatSchema.Value,
|
||||||
|
// Strict: false,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
}
|
}
|
||||||
|
|
||||||
if baseURL := GetEnvConfig(EnvOpenAIBaseURL); baseURL != "" {
|
if baseURL := GetEnvConfig(EnvOpenAIBaseURL); baseURL != "" {
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ type ActionParser struct {
|
|||||||
|
|
||||||
// Parse parses the prediction text and extracts actions
|
// Parse parses the prediction text and extracts actions
|
||||||
func (p *ActionParser) Parse(predictionText string) ([]ParsedAction, error) {
|
func (p *ActionParser) Parse(predictionText string) ([]ParsedAction, error) {
|
||||||
// try parsing JSON format, from VLM like GPT-4o
|
// try parsing JSON format, from VLM like openai/gpt-4o
|
||||||
var jsonActions []ParsedAction
|
var jsonActions []ParsedAction
|
||||||
jsonActions, jsonErr := p.parseJSON(predictionText)
|
jsonActions, jsonErr := p.parseJSON(predictionText)
|
||||||
if jsonErr == nil {
|
if jsonErr == nil {
|
||||||
|
|||||||
+13
-3
@@ -42,6 +42,7 @@ func NewPlanner(ctx context.Context) (*Planner, error) {
|
|||||||
parser := NewActionParser(1000)
|
parser := NewActionParser(1000)
|
||||||
return &Planner{
|
return &Planner{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
|
config: config,
|
||||||
model: model,
|
model: model,
|
||||||
parser: parser,
|
parser: parser,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -50,6 +51,7 @@ func NewPlanner(ctx context.Context) (*Planner, error) {
|
|||||||
type Planner struct {
|
type Planner struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
model model.ChatModel
|
model model.ChatModel
|
||||||
|
config *openai.ChatModelConfig
|
||||||
parser *ActionParser
|
parser *ActionParser
|
||||||
history []*schema.Message // conversation history
|
history []*schema.Message // conversation history
|
||||||
}
|
}
|
||||||
@@ -79,7 +81,8 @@ func (p *Planner) Call(opts *PlanningOptions) (*PlanningResult, error) {
|
|||||||
logRequest(p.history)
|
logRequest(p.history)
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
resp, err := p.model.Generate(p.ctx, p.history)
|
resp, err := p.model.Generate(p.ctx, p.history)
|
||||||
log.Info().Float64("elapsed(s)", time.Since(startTime).Seconds()).Msg("call model service")
|
log.Info().Float64("elapsed(s)", time.Since(startTime).Seconds()).
|
||||||
|
Str("model", p.config.Model).Msg("call model service")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("request model service failed: %w", err)
|
return nil, fmt.Errorf("request model service failed: %w", err)
|
||||||
}
|
}
|
||||||
@@ -153,8 +156,15 @@ func logRequest(messages []*schema.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func logResponse(resp *schema.Message) {
|
func logResponse(resp *schema.Message) {
|
||||||
log.Info().Str("role", string(resp.Role)).
|
logger := log.Info().Str("role", string(resp.Role)).
|
||||||
Str("content", resp.Content).Msg("log response message")
|
Str("content", resp.Content)
|
||||||
|
if resp.ResponseMeta != nil {
|
||||||
|
logger = logger.Interface("response_meta", resp.ResponseMeta)
|
||||||
|
}
|
||||||
|
if resp.Extra != nil {
|
||||||
|
logger = logger.Interface("extra", resp.Extra)
|
||||||
|
}
|
||||||
|
logger.Msg("log response message")
|
||||||
}
|
}
|
||||||
|
|
||||||
// appendConversationHistory adds a message to the conversation history
|
// appendConversationHistory adds a message to the conversation history
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ Thought: ...
|
|||||||
Action: ...
|
Action: ...
|
||||||
|
|
||||||
## Action Space
|
## Action Space
|
||||||
click(start_box='<|box_start|>(x1,y1)<|box_end|>')
|
click(start_box='[x1,y1]')
|
||||||
long_press(start_box='<|box_start|>(x1,y1)<|box_end|>', time='')
|
long_press(start_box='[x1,y1]', time='')
|
||||||
type(content='')
|
type(content='')
|
||||||
drag(start_box='<|box_start|>(x1,y1)<|box_end|>', end_box='<|box_start|>(x3,y3)<|box_end|>')
|
drag(start_box='[x1,y1]', end_box='[x2,y2]')
|
||||||
press_home()
|
press_home()
|
||||||
press_back()
|
press_back()
|
||||||
finished(content='') # Submit the task regardless of whether it succeeds or fails.
|
finished(content='') # Submit the task regardless of whether it succeeds or fails.
|
||||||
|
|||||||
Reference in New Issue
Block a user