Skip to content

Commit

Permalink
Use separate API for wingman (#6)
Browse files Browse the repository at this point in the history
Use the new REST API Gateway for the wingman llm proxy
  • Loading branch information
harveysmurf authored Aug 8, 2024
1 parent 63352aa commit 1fabf5e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22002,10 +22002,12 @@ var core = __toESM(require_core());
var import_http_client = __toESM(require_lib());
var import_auth = __toESM(require_auth());
var FLYCI_URL = "https://api.flyci.net";
var WINGMAN_URL = "https://wingman.flyci.net";
var getFlyCIUrl = (path = "") => {
const url = core.getInput("flyci-url") || FLYCI_URL;
return `${url}${path}`;
};
var getWingmanUrl = () => core.getInput("wingman-url") || WINGMAN_URL;
var getOidcToken = () => core.getIDToken(getFlyCIUrl());
var getAccessToken = async () => {
const oidcToken = await getOidcToken();
Expand Down Expand Up @@ -22051,7 +22053,7 @@ var WingmanClient = class _WingmanClient {
run = async () => {
const env = {
...process.env,
LLM_SERVER_URL: getFlyCIUrl(),
LLM_SERVER_URL: getWingmanUrl(),
LLM_API_KEY: this.accessToken,
FLYCI_WINGMAN_OUTPUT_FILE: import_node_path.default.join(getTempDir(), "wingman.json")
};
Expand Down
27 changes: 24 additions & 3 deletions src/__tests__/wingman.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import fs from "node:fs/promises";

import { downloadTool } from "@actions/tool-cache";
import { exec } from "@actions/exec";
import { getInput } from "@actions/core";

import { WingmanClient } from "../wingman";
import { getFlyCIUrl } from "../utils";

import { getFlyCIUrl, getWingmanUrl } from "../utils";
jest.mock("@actions/core", () => ({
getInput: jest.fn(),
}));
jest.mock("@actions/tool-cache");
jest.mock("@actions/exec");

Expand All @@ -20,6 +23,7 @@ describe("WingmanClient", () => {
const accessToken = "secret-access-token";
const mockDownloadTool = downloadTool as jest.Mock;
const mockExec = exec as jest.Mock;
const mockGetInput = getInput as jest.Mock;

const downloadWingman = async () => {
mockDownloadTool.mockResolvedValueOnce(path);
Expand Down Expand Up @@ -75,13 +79,30 @@ describe("WingmanClient", () => {

expect(exec).toHaveBeenCalledExactlyOnceWith(path, [], {
env: expect.objectContaining({
LLM_SERVER_URL: getFlyCIUrl(),
LLM_SERVER_URL: getWingmanUrl(),
LLM_API_KEY: accessToken,
FLYCI_WINGMAN_OUTPUT_FILE: p.join(tmpPath, "wingman.json"),
}),
});
});

it("when wingman url input is set should use it", async () => {
mockGetInput.mockReturnValue("mock-url");

mockExec.mockResolvedValueOnce(0);

const wingman = await downloadWingman();

await wingman.run();

expect(mockGetInput).toHaveBeenNthCalledWith(2, "wingman-url");
expect(exec).toHaveBeenCalledExactlyOnceWith(path, [], {
env: expect.objectContaining({
LLM_SERVER_URL: "mock-url",
}),
});
});

it("when wingman execution exits with 0 exit code should return the output file path", async () => {
mockExec.mockResolvedValueOnce(0);

Expand Down
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import { HttpClient } from "@actions/http-client";
import { BearerCredentialHandler } from "@actions/http-client/lib/auth";

export const FLYCI_URL = "https://api.flyci.net";
export const WINGMAN_URL = "https://wingman.flyci.net";

export const getFlyCIUrl = (path: string = "") => {
const url = core.getInput("flyci-url") || FLYCI_URL;

return `${url}${path}`;
};

export const getWingmanUrl = () => core.getInput("wingman-url") || WINGMAN_URL;

const getOidcToken = () => core.getIDToken(getFlyCIUrl());

export const getAccessToken = async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/wingman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from "node:fs/promises";
import { exec } from "@actions/exec";
import { downloadTool } from "@actions/tool-cache";

import { getFlyCIUrl, getTempDir } from "./utils";
import { getFlyCIUrl, getTempDir, getWingmanUrl } from "./utils";

const getWingmanDestinationPath = (platform: string) => {
return p.format({
Expand Down Expand Up @@ -43,7 +43,7 @@ export class WingmanClient {
run = async () => {
const env = {
...process.env,
LLM_SERVER_URL: getFlyCIUrl(),
LLM_SERVER_URL: getWingmanUrl(),
LLM_API_KEY: this.accessToken,
FLYCI_WINGMAN_OUTPUT_FILE: p.join(getTempDir(), "wingman.json"),
};
Expand Down

0 comments on commit 1fabf5e

Please sign in to comment.