File

src/star-search/agents/issues.agent.ts

Index

Properties
Methods

Constructor

constructor(configService: ConfigService, openAIWrappedService: OpenAIWrappedService, issuesGithubEventsVectorService: IssuesGithubEventsVectorService)
Parameters :
Name Type Optional
configService ConfigService No
openAIWrappedService OpenAIWrappedService No
issuesGithubEventsVectorService IssuesGithubEventsVectorService No

Methods

Async runAgentTools
runAgentTools(agentParams: IssuesAgentParams)
Parameters :
Name Type Optional
agentParams IssuesAgentParams No
Returns : Promise<string | null | >
Async searchAllIssues
searchAllIssues(undefined: SearchAllIssuesParams)
Parameters :
Name Type Optional
SearchAllIssuesParams No
Returns : unknown
Async searchAllIssuesInDataset
searchAllIssuesInDataset(undefined: SearchAllIssuesInDatasetParams)
Parameters :
Name Type Optional
SearchAllIssuesInDatasetParams No
Returns : unknown
Async searchIssuesByAuthor
searchIssuesByAuthor(undefined: SearchIssuesByAuthorParams)
Parameters :
Name Type Optional
SearchIssuesByAuthorParams No
Returns : unknown
Async searchIssuesByAuthorInDataset
searchIssuesByAuthorInDataset(undefined: SearchIssuesByAuthorInDatasetParams)
Parameters :
Name Type Optional
SearchIssuesByAuthorInDatasetParams No
Returns : unknown
Async searchIssuesByRepoName
searchIssuesByRepoName(undefined: SearchIssuesByRepoNameParams)
Parameters :
Name Type Optional
SearchIssuesByRepoNameParams No
Returns : unknown
Async searchIssuesByRepoNameAndAuthor
searchIssuesByRepoNameAndAuthor(undefined: SearchIssuesByRepoNameAndAuthorParams)
Parameters :
Name Type Optional
SearchIssuesByRepoNameAndAuthorParams No
Returns : unknown

Properties

agentSystemMessage
Type : string
Public searchAllIssuesInDatasetTool
Default value : this.openAIWrappedService.makeRunnableToolFunction({ function: async (params: SearchAllIssuesInDatasetParams) => this.searchAllIssuesInDataset(params), schema: SearchAllIssuesInDatasetParams, name: "searchAllIssuesInDataset", description: "Searches GitHub issues and their context within a given dataset of respositories using cosine similarity search based on the input search query. Returns the most relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.", })
Public searchAllIssuesTool
Default value : this.openAIWrappedService.makeRunnableToolFunction({ function: async (params: SearchAllIssuesParams) => this.searchAllIssues(params), schema: SearchAllIssuesParams, name: "searchAllIssues", description: "Searches ALL GitHub issues and their context using cosine similarity search based on the input search query. Returns the most relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.", })
Public searchIssuesByAuthorInDatasetTool
Default value : this.openAIWrappedService.makeRunnableToolFunction({ function: async (params: SearchIssuesByAuthorInDatasetParams) => this.searchIssuesByAuthorInDataset(params), schema: SearchIssuesByAuthorInDatasetParams, name: "searchIssuesByAuthorInDataset", description: "Searches GitHub issues and their context by a specific issue author within the given dataset of repositories using cosine similarity search based on the input search query. Returns relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.", })
Public searchIssuesByAuthorTool
Default value : this.openAIWrappedService.makeRunnableToolFunction({ function: async (params: SearchIssuesByAuthorParams) => this.searchIssuesByAuthor(params), schema: SearchIssuesByAuthorParams, name: "searchIssuesByAuthor", description: "Searches GitHub issues and their context with a specific issue author using cosine similarity search based on the input search query. Returns relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.", })
Public searchIssuesByRepoNameAndAuthorTool
Default value : this.openAIWrappedService.makeRunnableToolFunction({ function: async (params: SearchIssuesByRepoNameAndAuthorParams) => this.searchIssuesByRepoNameAndAuthor(params), schema: SearchIssuesByRepoNameAndAuthorParams, name: "searchIssuesByRepoNameAndAuthor", description: "Searches GitHub issues and their context in a specific repository and by a specific issue author using cosine similarity search based on the input search query. Returns relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.", })
Public searchIssuesByRepoNameTool
Default value : this.openAIWrappedService.makeRunnableToolFunction({ function: async (params: SearchIssuesByRepoNameParams) => this.searchIssuesByRepoName(params), schema: SearchIssuesByRepoNameParams, name: "searchIssuesByRepoName", description: "Searches GitHub issues and their context in a sole, specific repository using cosine similarity search based on the input search query. Returns relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.", })
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { OpenAIWrappedService } from "../../openai-wrapped/openai-wrapped.service";
import {
  IssuesAgentParams,
  SearchAllIssuesInDatasetParams,
  SearchAllIssuesParams,
  SearchIssuesByAuthorInDatasetParams,
  SearchIssuesByAuthorParams,
  SearchIssuesByRepoNameAndAuthorParams,
  SearchIssuesByRepoNameParams,
} from "../schemas/issues.schema";
import { IssuesGithubEventsVectorService } from "../../timescale/issues_github-events_vector.service";

@Injectable()
export class IssuesAgent {
  agentSystemMessage: string;

  constructor(
    private configService: ConfigService,
    private openAIWrappedService: OpenAIWrappedService,
    private issuesGithubEventsVectorService: IssuesGithubEventsVectorService
  ) {
    this.agentSystemMessage = this.configService.get("starsearch.issuesAgentSystemMessage")!;
  }

  async searchAllIssues({ question }: SearchAllIssuesParams) {
    const queryEmbedding = await this.openAIWrappedService.generateEmbedding(question);

    return this.issuesGithubEventsVectorService.cosineSimilarity({
      embedding: queryEmbedding,
      range: 30,
      prevDaysStartDate: 0,
    });
  }

  public searchAllIssuesTool = this.openAIWrappedService.makeRunnableToolFunction({
    function: async (params: SearchAllIssuesParams) => this.searchAllIssues(params),
    schema: SearchAllIssuesParams,
    name: "searchAllIssues",
    description:
      "Searches ALL GitHub issues and their context using cosine similarity search based on the input search query. Returns the most relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.",
  });

  async searchAllIssuesInDataset({ question, dataset }: SearchAllIssuesInDatasetParams) {
    const queryEmbedding = await this.openAIWrappedService.generateEmbedding(question);

    return this.issuesGithubEventsVectorService.cosineSimilarity({
      embedding: queryEmbedding,
      range: 30,
      prevDaysStartDate: 0,
      repoNames: dataset.split(","),
    });
  }

  public searchAllIssuesInDatasetTool = this.openAIWrappedService.makeRunnableToolFunction({
    function: async (params: SearchAllIssuesInDatasetParams) => this.searchAllIssuesInDataset(params),
    schema: SearchAllIssuesInDatasetParams,
    name: "searchAllIssuesInDataset",
    description:
      "Searches GitHub issues and their context within a given dataset of respositories using cosine similarity search based on the input search query. Returns the most relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.",
  });

  async searchIssuesByRepoName({ question, repoName }: SearchIssuesByRepoNameParams) {
    const queryEmbedding = await this.openAIWrappedService.generateEmbedding(question);

    return this.issuesGithubEventsVectorService.cosineSimilarity({
      embedding: queryEmbedding,
      range: 30,
      prevDaysStartDate: 0,
      repoNames: [repoName],
    });
  }

  public searchIssuesByRepoNameTool = this.openAIWrappedService.makeRunnableToolFunction({
    function: async (params: SearchIssuesByRepoNameParams) => this.searchIssuesByRepoName(params),
    schema: SearchIssuesByRepoNameParams,
    name: "searchIssuesByRepoName",
    description:
      "Searches GitHub issues and their context in a sole, specific repository using cosine similarity search based on the input search query. Returns relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.",
  });

  async searchIssuesByAuthor({ question, author }: SearchIssuesByAuthorParams) {
    const queryEmbedding = await this.openAIWrappedService.generateEmbedding(question);

    return this.issuesGithubEventsVectorService.cosineSimilarity({
      embedding: queryEmbedding,
      range: 30,
      prevDaysStartDate: 0,
      author,
    });
  }

  public searchIssuesByAuthorTool = this.openAIWrappedService.makeRunnableToolFunction({
    function: async (params: SearchIssuesByAuthorParams) => this.searchIssuesByAuthor(params),
    schema: SearchIssuesByAuthorParams,
    name: "searchIssuesByAuthor",
    description:
      "Searches GitHub issues and their context with a specific issue author using cosine similarity search based on the input search query. Returns relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.",
  });

  async searchIssuesByRepoNameAndAuthor({ question, repoName, author }: SearchIssuesByRepoNameAndAuthorParams) {
    const queryEmbedding = await this.openAIWrappedService.generateEmbedding(question);

    return this.issuesGithubEventsVectorService.cosineSimilarity({
      embedding: queryEmbedding,
      range: 30,
      prevDaysStartDate: 0,
      repoNames: [repoName],
      author,
    });
  }

  public searchIssuesByRepoNameAndAuthorTool = this.openAIWrappedService.makeRunnableToolFunction({
    function: async (params: SearchIssuesByRepoNameAndAuthorParams) => this.searchIssuesByRepoNameAndAuthor(params),
    schema: SearchIssuesByRepoNameAndAuthorParams,
    name: "searchIssuesByRepoNameAndAuthor",
    description:
      "Searches GitHub issues and their context in a specific repository and by a specific issue author using cosine similarity search based on the input search query. Returns relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.",
  });

  async searchIssuesByAuthorInDataset({ question, author, dataset }: SearchIssuesByAuthorInDatasetParams) {
    const queryEmbedding = await this.openAIWrappedService.generateEmbedding(question);

    return this.issuesGithubEventsVectorService.cosineSimilarity({
      embedding: queryEmbedding,
      range: 30,
      prevDaysStartDate: 0,
      repoNames: dataset.split(","),
      author,
    });
  }

  public searchIssuesByAuthorInDatasetTool = this.openAIWrappedService.makeRunnableToolFunction({
    function: async (params: SearchIssuesByAuthorInDatasetParams) => this.searchIssuesByAuthorInDataset(params),
    schema: SearchIssuesByAuthorInDatasetParams,
    name: "searchIssuesByAuthorInDataset",
    description:
      "Searches GitHub issues and their context by a specific issue author within the given dataset of repositories using cosine similarity search based on the input search query. Returns relevant summaries and metadata of issues based on a closest neighbor search algorithm. WARNING: this may return irrelevant results if similarity search has no close neighbors. For better and more relevant results, expand search queries at will with related terms. For example, a search query of 'AI' could be expanded to include 'machine learning optimization', 'neural network', and 'model'.",
  });

  async runAgentTools(agentParams: IssuesAgentParams): Promise<string | null | unknown> {
    const tools = [
      this.searchAllIssuesTool,
      this.searchAllIssuesInDatasetTool,
      this.searchIssuesByRepoNameTool,
      this.searchIssuesByAuthorTool,
      this.searchIssuesByRepoNameAndAuthorTool,
      this.searchIssuesByAuthorInDatasetTool,
    ];

    const runner = this.openAIWrappedService
      .runTools(this.agentSystemMessage, agentParams.prompt, tools)
      .on("message", (msg) => console.log("issues agent msg", msg))
      .on("functionCall", (functionCall) => console.log("issues agent functionCall", functionCall))
      .on("functionCallResult", (functionCallResult) =>
        console.log("issues agent functionCallResult", functionCallResult)
      );

    return runner.finalContent();
  }
}

results matching ""

    No results matching ""