Skip to content

Commit f4bdded

Browse files
fix: minor bedrock and ui copy request fixes
1 parent d7b693a commit f4bdded

File tree

2 files changed

+24
-88
lines changed

2 files changed

+24
-88
lines changed

core/providers/bedrock/responses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2432,7 +2432,7 @@ func ConvertBifrostMessagesToBedrockMessages(bifrostMessages []schemas.Responses
24322432
// Handle structured output blocks
24332433
for _, block := range msg.ResponsesToolMessage.Output.ResponsesFunctionToolCallOutputBlocks {
24342434
switch block.Type {
2435-
case schemas.ResponsesOutputMessageContentTypeText:
2435+
case schemas.ResponsesInputMessageContentBlockTypeText:
24362436
if block.Text != nil {
24372437
resultContent = append(resultContent, BedrockContentBlock{
24382438
Text: block.Text,

ui/app/workspace/logs/views/logDetailsSheet.tsx

Lines changed: 23 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -74,110 +74,46 @@ export function LogDetailSheet({ log, open, onOpenChange, handleDelete }: LogDet
7474

7575
const copyRequestBody = async () => {
7676
try {
77-
// Check if request is for responses, chat, speech, text completion, or embedding (exclude transcriptions)
7877
const object = log.object?.toLowerCase() || "";
79-
const isChat = object === "chat_completion" || object === "chat_completion_stream";
80-
const isResponses = object === "responses" || object === "responses_stream";
81-
const isSpeech = object === "speech" || object === "speech_stream";
82-
const isTextCompletion = object === "text_completion" || object === "text_completion_stream";
83-
const isEmbedding = object === "embedding";
8478
const isTranscription = object === "transcription" || object === "transcription_stream";
8579

86-
// Skip if transcription
8780
if (isTranscription) {
8881
toast.error("Copy request body is not available for transcription requests");
8982
return;
9083
}
9184

92-
// Skip if not a supported request type
93-
if (!isChat && !isResponses && !isSpeech && !isTextCompletion && !isEmbedding) {
94-
toast.error("Copy request body is only available for chat, responses, speech, text completion, and embedding requests");
95-
return;
96-
}
97-
98-
// Helper function to extract text content from ChatMessage
99-
const extractTextFromMessage = (message: any): string => {
100-
if (!message || !message.content) {
101-
return "";
102-
}
103-
if (typeof message.content === "string") {
104-
return message.content;
105-
}
106-
if (Array.isArray(message.content)) {
107-
return message.content
108-
.filter((block: any) => block && block.type === "text" && block.text)
109-
.map((block: any) => block.text || "")
110-
.join("");
111-
}
112-
return "";
113-
};
114-
115-
// Helper function to extract texts from ChatMessage content blocks (for embeddings)
116-
const extractTextsFromMessage = (message: any): string[] => {
117-
if (!message || !message.content) {
118-
return [];
119-
}
120-
if (typeof message.content === "string") {
121-
return message.content ? [message.content] : [];
122-
}
123-
if (Array.isArray(message.content)) {
124-
return message.content.filter((block: any) => block && block.type === "text" && block.text).map((block: any) => block.text);
125-
}
126-
return [];
127-
};
128-
129-
// Build request body following OpenAI schema
85+
// Build request body with model and available input/params
13086
const requestBody: any = {
131-
model: log.provider && log.model ? `${log.provider}/${log.model}` : log.model || "",
87+
model: log.model || "",
13288
};
13389

134-
// Add messages/input/prompt based on request type
135-
if (isChat && log.input_history && log.input_history.length > 0) {
90+
// Add provider prefix if available
91+
if (log.provider) {
92+
requestBody.model = `${log.provider}/${requestBody.model}`;
93+
}
94+
95+
// Add request-specific input fields
96+
if (log.input_history?.length > 0) {
13697
requestBody.messages = log.input_history;
137-
} else if (isResponses && log.responses_input_history && log.responses_input_history.length > 0) {
98+
}
99+
if (log.responses_input_history?.length > 0) {
138100
requestBody.input = log.responses_input_history;
139-
} else if (isSpeech && log.speech_input) {
101+
}
102+
if (log.speech_input) {
140103
requestBody.input = log.speech_input.input;
141-
} else if (isTextCompletion && log.input_history && log.input_history.length > 0) {
142-
// For text completions, extract prompt from input_history
143-
const firstMessage = log.input_history[0];
144-
const prompt = extractTextFromMessage(firstMessage);
145-
if (prompt) {
146-
requestBody.prompt = prompt;
147-
}
148-
} else if (isEmbedding && log.input_history && log.input_history.length > 0) {
149-
// For embeddings, extract all texts from input_history
150-
const texts: string[] = [];
151-
for (const message of log.input_history) {
152-
const messageTexts = extractTextsFromMessage(message);
153-
texts.push(...messageTexts);
154-
}
155-
if (texts.length > 0) {
156-
// Use single string if only one text, otherwise use array
157-
requestBody.input = texts.length === 1 ? texts[0] : texts;
158-
}
159104
}
160-
161-
// Add params (excluding tools and instructions as they're handled separately in OpenAI schema)
162-
if (log.params) {
163-
const paramsCopy = { ...log.params };
164-
// Remove tools and instructions from params as they're typically top-level in OpenAI schema
165-
// Keep all other params (temperature, max_tokens, voice, etc.)
166-
delete paramsCopy.tools;
167-
delete paramsCopy.instructions;
168-
169-
// Merge remaining params into request body
170-
Object.assign(requestBody, paramsCopy);
105+
if (log.embedding_output?.length > 0) {
106+
requestBody.embeddings = log.embedding_output;
171107
}
172108

173-
// Add tools if they exist (for chat and responses) - OpenAI schema has tools at top level
174-
if ((isChat || isResponses) && log.params?.tools && Array.isArray(log.params.tools) && log.params.tools.length > 0) {
175-
requestBody.tools = log.params.tools;
176-
}
109+
// Add all params except tools and instructions (handled separately)
110+
if (log.params) {
111+
const { tools, instructions, ...otherParams } = log.params;
112+
Object.assign(requestBody, otherParams);
177113

178-
// Add instructions if they exist (for responses) - OpenAI schema has instructions at top level
179-
if (isResponses && log.params?.instructions) {
180-
requestBody.instructions = log.params.instructions;
114+
// Add tools and instructions at top level if they exist
115+
if (tools) requestBody.tools = tools;
116+
if (instructions) requestBody.instructions = instructions;
181117
}
182118

183119
const requestBodyJson = JSON.stringify(requestBody, null, 2);
@@ -186,7 +122,7 @@ export function LogDetailSheet({ log, open, onOpenChange, handleDelete }: LogDet
186122
.then(() => {
187123
toast.success("Request body copied to clipboard");
188124
})
189-
.catch((error) => {
125+
.catch(() => {
190126
toast.error("Failed to copy request body");
191127
});
192128
} catch (error) {

0 commit comments

Comments
 (0)