Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4 refactored code to fix issue with close-ended chat + added tests #5

Merged
merged 2 commits into from
Jul 8, 2024

Conversation

pranav-kural
Copy link
Collaborator

Added Jest tests for close-ended chat endpoint.

Also:

Refactored the getFormattedInput method to accept object instead of positional arguments.

/**
   * Gets the formatted input based on the agent type.
   * @param agentType - The type of agent.
   * @param topic - Topic for close-ended and rag agents.
   * @param query - The query string.
   * @param context - The context object.
   * @returns Returns the formatted input.
   * @throws Throws an error if the agent type is invalid.
   */
  private static getFormattedInput({
    agentType,
    query,
    context,
    topic,
  }: {
    agentType?: ChatAgentType;
    query?: string;
    topic?: string;
    context?: string;
  }) {
    switch (agentType) {
      case "open-ended":
        return {
          query,
        };
      case "close-ended":
        return {
          query,
          topic: topic,
        };
      case "rag":
        return {
          query,
          topic: topic,
          context,
        };
      default:
        throw new Error("Invalid agent type");
    }
  }

  /**
   * Generates a response using the system prompt.
   * @param agentType - The type of agent.
   * @param model - The supported model name.
   * @param modelConfig - The model configuration.
   * @param query - The query string.
   * @param context - The context string.
   * @param topic - The topic string.
   * @param tools - The tool arguments.
   * @returns Returns the generated response.
   */
  private static generateSystemPromptResponse({
    agentType,
    prompt,
    model,
    modelConfig,
    query,
    context,
    topic,
    tools,
  }: GenerateSystemPromptResponseParams) {
    // generate the response
    const res = prompt.generate({
      // if undefined, will use model defined in the dotprompt
      model: model,
      config: modelConfig,
      input: ChatAgent.getFormattedInput({ agentType, query, context, topic }),
      tools: tools,
    });
    // return the response
    return res;
  }

@pranav-kural pranav-kural added the bug Something isn't working label Jul 8, 2024
@pranav-kural pranav-kural requested a review from HarryKural July 8, 2024 03:28
@pranav-kural pranav-kural self-assigned this Jul 8, 2024
Copy link

github-actions bot commented Jul 8, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

@pranav-kural pranav-kural enabled auto-merge July 8, 2024 04:50
@pranav-kural pranav-kural removed the request for review from HarryKural July 8, 2024 04:50
@pranav-kural pranav-kural added this pull request to the merge queue Jul 8, 2024
Merged via the queue into main with commit 605356b Jul 8, 2024
4 checks passed
@pranav-kural pranav-kural deleted the close-ended-chat-fix branch July 8, 2024 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant