File

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

Index

Properties
Methods

Constructor

constructor(configService: ConfigService, openAIWrappedService: OpenAIWrappedService, releaseGithubEventsService: ReleaseGithubEventsService)
Parameters :
Name Type Optional
configService ConfigService No
openAIWrappedService OpenAIWrappedService No
releaseGithubEventsService ReleaseGithubEventsService No

Methods

Public Async getReleasesByReponame
getReleasesByReponame(undefined: ReleasesParams)
Parameters :
Name Type Optional
ReleasesParams No
Returns : unknown
Public Async getReleasesInDataset
getReleasesInDataset(undefined: ReleasesInDatasetParams)
Parameters :
Name Type Optional
ReleasesInDatasetParams No
Returns : unknown
Async runAgentTools
runAgentTools(agentParams: ReleaseAgentParams)
Parameters :
Name Type Optional
agentParams ReleaseAgentParams No
Returns : Promise<string | null | >

Properties

agentSystemMessage
Type : string
Public getReleasesByRepoNameTool
Default value : this.openAIWrappedService.makeRunnableToolFunction({ function: async (params: ReleasesParams) => this.getReleasesByReponame(params), schema: ReleasesParams, name: "getReleasesByReponame", description: "Gets the latest GitHub releases and their context for a specific repository. The repoName parameter should be of the form: 'organization/name'. Example: facebook/react.", })
Public getReleasesInDatasetTool
Default value : this.openAIWrappedService.makeRunnableToolFunction({ function: async (params: ReleasesInDatasetParams) => this.getReleasesInDataset(params), schema: ReleasesInDatasetParams, name: "getReleasesInDataset", description: `Gets the latest GitHub releases and their metadata within the given dataset over a range of days.`, })
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { OpenAIWrappedService } from "../../openai-wrapped/openai-wrapped.service";
import { ReleaseGithubEventsService } from "../../timescale/release_github_events.service";
import { ReleaseAgentParams, ReleasesInDatasetParams, ReleasesParams } from "../schemas/releases.schema";

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

  constructor(
    private configService: ConfigService,
    private openAIWrappedService: OpenAIWrappedService,
    private releaseGithubEventsService: ReleaseGithubEventsService
  ) {
    this.agentSystemMessage = this.configService.get("starsearch.releaseAgentSystemMessage")!;
  }

  public async getReleasesByReponame({ repoName, range }: ReleasesParams) {
    const results = await this.releaseGithubEventsService.getReleases({
      repos: repoName,
      range,
      skip: 0,
    });

    if (results.length === 0) {
      return "no releases found";
    }

    return results;
  }

  public getReleasesByRepoNameTool = this.openAIWrappedService.makeRunnableToolFunction({
    function: async (params: ReleasesParams) => this.getReleasesByReponame(params),
    schema: ReleasesParams,
    name: "getReleasesByReponame",
    description:
      "Gets the latest GitHub releases and their context for a specific repository. The repoName parameter should be of the form: 'organization/name'. Example: facebook/react.",
  });

  public async getReleasesInDataset({ dataset, range }: ReleasesInDatasetParams) {
    const results = await this.releaseGithubEventsService.getReleases({
      repos: dataset,
      range,
      skip: 0,
    });

    if (results.length === 0) {
      return "no releases found";
    }

    return results;
  }

  public getReleasesInDatasetTool = this.openAIWrappedService.makeRunnableToolFunction({
    function: async (params: ReleasesInDatasetParams) => this.getReleasesInDataset(params),
    schema: ReleasesInDatasetParams,
    name: "getReleasesInDataset",
    description: `Gets the latest GitHub releases and their metadata within the given dataset over a range of days.`,
  });

  async runAgentTools(agentParams: ReleaseAgentParams): Promise<string | null | unknown> {
    const tools = [this.getReleasesByRepoNameTool, this.getReleasesInDatasetTool];

    if (agentParams.dataset) {
      agentParams.prompt += `\n\nDataset: ${agentParams.dataset}`;
    }

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

    return runner.finalContent();
  }
}

results matching ""

    No results matching ""