- var call functionCall
- err = json.Unmarshal(raw, &call)
- if err != nil {
- return nil, fmt.Errorf("decode output item: %w", err)
- }
-
- switch call.Type {
- case "message":
- text, err := outputText([]json.RawMessage{raw})
- if err != nil {
- return nil, err
- }
-
- text = strings.TrimSpace(text)
- if text == "" {
- continue
- }
-
- _, err = l.Append("reply", text)
- if err != nil {
- return nil, fmt.Errorf("%w: %w", errLogWrite, err)
- }
- case "function_call":
- output, err := l.tools.Call(ctx, call.Name, call.Arguments)
- if err != nil {
- return nil, fmt.Errorf("%w: %w", errLogWrite, err)
- }
-
- outputs = append(outputs, functionCallOutput{
- Type: "function_call_output",
- CallID: call.CallID,
- Output: output,
- })
- }
- }
-
- if len(outputs) == 0 {
- return nil, nil
- }
-
- input = append(input, outputs...)
- for _, message := range l.take() {
- input = append(input, userMessage(message.Text))
- }
-
- return input, nil