improve request logging

This commit is contained in:
ramnique 2025-03-18 23:09:25 +05:30
parent 349992f558
commit 4b5c0fffb1
4 changed files with 10 additions and 7 deletions

View file

@ -51,6 +51,7 @@ def health():
def chat():
try:
request_data = ApiRequest(**request.json)
print(f"received /chat request: {request_data}")
validate_request(request_data)
response = get_response(
@ -61,7 +62,7 @@ def chat():
copilot_instructions=copilot_instructions
)
api_response = ApiResponse(response=response).model_dump()
print(f"sending /chat response: {api_response}")
return jsonify(api_response)
except ValidationError as ve:
@ -88,6 +89,7 @@ def chat():
def edit_agent_instructions():
try:
request_data = ApiRequest(**request.json)
print(f"received /edit_agent_instructions request: {request_data}")
validate_request(request_data)
response = get_response(
@ -99,6 +101,7 @@ def edit_agent_instructions():
)
api_response = ApiResponse(response=response).model_dump()
print(f"sending /edit_agent_instructions response: {api_response}")
return jsonify(api_response)
except ValidationError as ve:

View file

@ -540,7 +540,6 @@ User: {last_message.content}
updated_msgs = [{"role": "system", "content": sys_prompt}] + [
message.model_dump() for message in messages
]
print(json.dumps(updated_msgs, indent=2))
response = openai_client.chat.completions.create(
model=MODEL_NAME,

View file

@ -36,7 +36,7 @@ export async function getCopilotResponse(
current_workflow_config: JSON.stringify(convertToCopilotWorkflow(current_workflow_config)),
context: context ? convertToCopilotApiChatContext(context) : null,
};
console.log(`copilot request`, JSON.stringify(request, null, 2));
console.log(`sending copilot request`, JSON.stringify(request));
// call copilot api
const response = await fetch(process.env.COPILOT_API_URL + '/chat', {
@ -54,7 +54,7 @@ export async function getCopilotResponse(
// parse and return response
const json: z.infer<typeof CopilotAPIResponse> = await response.json();
console.log(`copilot response`, JSON.stringify(json, null, 2));
console.log(`received copilot response`, JSON.stringify(json));
if ('error' in json) {
throw new Error(`Failed to call copilot api: ${json.error}`);
}
@ -182,7 +182,7 @@ export async function getCopilotAgentInstructions(
agentName: agentName,
}
};
console.log(`copilot request`, JSON.stringify(request, null, 2));
console.log(`sending copilot agent instructions request`, JSON.stringify(request));
// call copilot api
const response = await fetch(process.env.COPILOT_API_URL + '/edit_agent_instructions', {
@ -201,7 +201,7 @@ export async function getCopilotAgentInstructions(
// parse and return response
const json = await response.json();
console.log(`copilot response`, JSON.stringify(json, null, 2));
console.log(`received copilot agent instructions response`, JSON.stringify(json));
let copilotResponse: z.infer<typeof CopilotAPIResponse>;
let agent_instructions: string;
try {

View file

@ -140,7 +140,7 @@ export async function getAgenticApiResponse(
rawAPIResponse: unknown,
}> {
// call agentic api
console.log(`agentic request`, JSON.stringify(request, null, 2));
console.log(`sending agentic api request`, JSON.stringify(request));
const response = await fetch(process.env.AGENTS_API_URL + '/chat', {
method: 'POST',
body: JSON.stringify(request),
@ -154,6 +154,7 @@ export async function getAgenticApiResponse(
throw new Error(`Failed to call agentic api: ${response.statusText}`);
}
const responseJson = await response.json();
console.log(`received agentic api response`, JSON.stringify(responseJson));
const result: z.infer<typeof AgenticAPIChatResponse> = responseJson;
return {
messages: result.messages,