private createVertexRequest()

in firestore-palm-chatbot/functions/src/discussion.ts [133:169]


  private createVertexRequest(
    prompt: PaLMPrompt,
    options: GenerateMessageOptions
  ) {
    const temperature = options.temperature || this.temperature;
    const topP = options.topP || this.topP;
    const topK = options.topK || this.topK;
    const context = prompt.context || options.context || this.context || '';

    const parameter: Record<string, string | number> = {};

    // We have to set these conditionally or they get nullified and the request fails with a serialization error.
    if (temperature) {
      parameter.temperature = temperature;
    }
    if (topP) {
      parameter.top_p = topP;
    }
    if (topK) {
      parameter.top_k = topK;
    }

    if (context) {
      parameter.context = context;
    }

    const parameters = helpers.toValue(parameter);
    const instanceValue = helpers.toValue(prompt);
    const instances = [instanceValue!];

    const request = {
      endpoint: this.endpoint,
      instances,
      parameters,
    };
    return request;
  }