Effect CommunityEC
Effect Community4w ago
5 replies
alexhwoods

Exploring Interaction Between `Prompt` and `Response` in TypeScript

Morning everybody!

This morning I'm exploring how Prompt and Response interact. This seems like a pretty typical use case, like I would imagine any chat to have this interaction. The way I'm doing it feels a bit awkward. I'm wondering if I'm doing it correctly.

Here's an example program. Particularly this part I'm curious about:
  /**
   * This part feels a bit weird to me.
   *
   * Is this the intended usage?
   */
  messages.push(
    // Add tool-call as the first tool-related message
    Prompt.makeMessage("assistant", {
      content: firstResponse.toolCalls.map((call: any) =>
        Prompt.makePart("tool-call", {
          id: call.id,
          name: call.name,
          params: call.params,
          providerExecuted: call.providerExecuted ?? false,
        })
      ),
    }),
    // Add tool results as their own messages
    // I believe this format has to do with the OpenAI API
    // https://platform.openai.com/docs/guides/function-calling#the-tool-calling-flow
    ...firstResponse.toolResults.map((tr: any) =>
      Prompt.makeMessage("tool", {
        content: [
          Prompt.makePart("tool-result", {
            id: tr.id,
            name: tr.name,
            result: tr.result,
            isFailure: tr.isFailure ?? false,
          }),
        ],
      })
    )
  );
Was this page helpful?