Refactor logging and formatting in OpenAI provider and test files
- Adjusted indentation and formatting in the OpenAI provider's logging statements to enhance readability and maintainability. - Cleaned up test files by removing unnecessary blank lines, improving overall code clarity and consistency. - Ensured that logging for request and response details is properly structured for better debugging capabilities.
This commit is contained in:
parent
71cd7b9993
commit
c6b9ef500c
7 changed files with 24 additions and 28 deletions
|
|
@ -647,7 +647,7 @@ func (p *Provider) streamWithRetry(ctx *context.Context, messages []context.Mess
|
|||
|
||||
// Log request for debugging
|
||||
if trace != nil {
|
||||
if requestBodyJSON, marshalErr := jsoniter.Marshal(requestBody); marshalErr == nil {
|
||||
if requestBodyJSON, marshalErr := jsoniter.Marshal(requestBody); marshalErr == nil {
|
||||
trace.Debug("OpenAI Stream Request", map[string]any{
|
||||
"url": url,
|
||||
"body": string(requestBodyJSON),
|
||||
|
|
@ -766,12 +766,12 @@ func (p *Provider) streamWithRetry(ctx *context.Context, messages []context.Mess
|
|||
if trace != nil {
|
||||
trace.Warn("OpenAI stream completed but no data was received")
|
||||
|
||||
// Log request details for debugging
|
||||
if requestBodyJSON, err := jsoniter.Marshal(requestBody); err == nil {
|
||||
// Log request details for debugging
|
||||
if requestBodyJSON, err := jsoniter.Marshal(requestBody); err == nil {
|
||||
trace.Error("Request body that caused empty response", map[string]any{
|
||||
"body": string(requestBodyJSON),
|
||||
})
|
||||
}
|
||||
}
|
||||
trace.Error("Request details", map[string]any{
|
||||
"url": url,
|
||||
"model": accumulator.model,
|
||||
|
|
@ -1057,7 +1057,7 @@ func (p *Provider) postWithRetry(ctx *context.Context, messages []context.Messag
|
|||
}
|
||||
// Log full response data for debugging
|
||||
if trace != nil {
|
||||
if respJSON, err := jsoniter.Marshal(resp.Data); err == nil {
|
||||
if respJSON, err := jsoniter.Marshal(resp.Data); err == nil {
|
||||
trace.Error("OpenAI API error response", map[string]any{
|
||||
"response": string(respJSON),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -14,17 +14,17 @@ import (
|
|||
|
||||
// testTraceData holds the prepared test trace and related information
|
||||
type testTraceData struct {
|
||||
TraceID string
|
||||
Manager types.Manager
|
||||
RootNodeID string
|
||||
Node1ID string
|
||||
Node2ID string
|
||||
Node3ID string
|
||||
TokenInfo *testutils.TokenInfo
|
||||
TestClient *oauthtypes.ClientInfo
|
||||
ServerURL string
|
||||
BaseURL string
|
||||
Ctx context.Context
|
||||
TraceID string
|
||||
Manager types.Manager
|
||||
RootNodeID string
|
||||
Node1ID string
|
||||
Node2ID string
|
||||
Node3ID string
|
||||
TokenInfo *testutils.TokenInfo
|
||||
TestClient *oauthtypes.ClientInfo
|
||||
ServerURL string
|
||||
BaseURL string
|
||||
Ctx context.Context
|
||||
}
|
||||
|
||||
// prepareTestTrace creates a test trace with sample nodes, logs, and spaces
|
||||
|
|
@ -161,4 +161,3 @@ func cleanupTestTrace(t *testing.T, data *testTraceData) {
|
|||
}
|
||||
testutils.Clean()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func TestGetLogs(t *testing.T) {
|
|||
// Parse response
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
||||
var responseData map[string]interface{}
|
||||
err = json.Unmarshal(body, &responseData)
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -46,7 +46,7 @@ func TestGetLogs(t *testing.T) {
|
|||
logs, ok := responseData["logs"].([]interface{})
|
||||
assert.True(t, ok, "Logs should be an array")
|
||||
assert.NotEmpty(t, logs, "Logs array should not be empty")
|
||||
|
||||
|
||||
count := int(responseData["count"].(float64))
|
||||
assert.GreaterOrEqual(t, count, 6, "Should have at least 6 log entries (6 node logs)")
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func TestGetNodes(t *testing.T) {
|
|||
// Parse response
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
||||
var responseData map[string]interface{}
|
||||
err = json.Unmarshal(body, &responseData)
|
||||
assert.NoError(t, err)
|
||||
|
|
@ -46,7 +46,7 @@ func TestGetNodes(t *testing.T) {
|
|||
nodes, ok := responseData["nodes"].([]interface{})
|
||||
assert.True(t, ok, "Nodes should be an array")
|
||||
assert.NotEmpty(t, nodes, "Nodes array should not be empty")
|
||||
|
||||
|
||||
count := int(responseData["count"].(float64))
|
||||
assert.Equal(t, 3, count, "Should have 3 nodes (3 child nodes created)")
|
||||
assert.Equal(t, count, len(nodes), "Count should match array length")
|
||||
|
|
@ -60,7 +60,7 @@ func TestGetNodes(t *testing.T) {
|
|||
assert.NotNil(t, node["label"], "Node should have label")
|
||||
assert.NotNil(t, node["status"], "Node should have status")
|
||||
assert.NotNil(t, node["created_at"], "Node should have created_at")
|
||||
|
||||
|
||||
// Check if metadata is present (should be for all our test nodes)
|
||||
if node["metadata"] != nil {
|
||||
metadata, ok := node["metadata"].(map[string]interface{})
|
||||
|
|
@ -71,7 +71,7 @@ func TestGetNodes(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
assert.Equal(t, 3, metadataFound, "All 3 nodes should have metadata with node_order")
|
||||
|
||||
t.Logf("Retrieved %d nodes for trace %s (all with metadata)", count, data.TraceID)
|
||||
|
|
@ -109,13 +109,13 @@ func TestGetNodeByID(t *testing.T) {
|
|||
assert.Equal(t, "First Node", responseData["label"], "Node label should match")
|
||||
assert.Equal(t, "icon1", responseData["icon"], "Node icon should match")
|
||||
assert.Equal(t, "First test node", responseData["description"], "Node description should match")
|
||||
|
||||
|
||||
// Verify metadata is present and correct
|
||||
assert.NotNil(t, responseData["metadata"], "Metadata should be present")
|
||||
metadata, ok := responseData["metadata"].(map[string]interface{})
|
||||
assert.True(t, ok, "Metadata should be a map")
|
||||
assert.Equal(t, float64(1), metadata["node_order"], "Metadata node_order should be 1")
|
||||
|
||||
|
||||
// Verify input and output are present
|
||||
assert.NotNil(t, responseData["input"], "Input should be present")
|
||||
assert.NotNil(t, responseData["output"], "Output should be present")
|
||||
|
|
|
|||
|
|
@ -165,4 +165,3 @@ func TestGetSpaceByIDNotFound(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.NotNil(t, result["error"])
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -152,4 +152,3 @@ func GetNode(c *gin.Context) {
|
|||
|
||||
response.RespondWithSuccess(c, response.StatusOK, nodeData)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,4 +136,3 @@ func GetSpace(c *gin.Context) {
|
|||
|
||||
response.RespondWithSuccess(c, response.StatusOK, responseData)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue