Skip to content

Commit

Permalink
chore(client): remove axios for fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
arielweinberger committed Aug 5, 2023
1 parent 2664e74 commit 0a038d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
4 changes: 1 addition & 3 deletions libs/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"gpt-4",
"gpt-3.5-turbo"
],
"dependencies": {
"axios": "^1.4.0"
},
"dependencies": {},
"repository": {
"type": "git",
"url": "https://github.com/pezzolabs/pezzo.git"
Expand Down
21 changes: 9 additions & 12 deletions libs/client/src/client/Pezzo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios, { AxiosInstance } from "axios";
import { ReportData } from "../types";
import { Prompt } from "../types/prompts";

Expand All @@ -19,21 +18,12 @@ const defaultOptions: Partial<PezzoClientOptions> = {

export class Pezzo {
options: PezzoClientOptions;
private readonly axios: AxiosInstance; // TODO: swap with fetch for Vercel AI

constructor(options: PezzoClientOptions) {
this.options = {
...defaultOptions,
...options,
};

this.axios = axios.create({
baseURL: `${this.options.serverUrl}/api`,
headers: {
"x-pezzo-api-key": this.options.apiKey,
"x-pezzo-client-version": "0.0.1", // TODO: make dynamic, handdle in backend
},
});
}

async getPrompt(promptName: string): Promise<{ pezzo: Prompt }> {
Expand Down Expand Up @@ -74,15 +64,22 @@ export class Pezzo {
}

async reportPromptExecution(dto: ReportData) {
await axios.post(
const response = await fetch(
`${this.options.serverUrl}/api/reporting/v2/request`,
dto,
{
method: "POST",
headers: {
"Content-Type": "application/json",
"x-pezzo-api-key": this.options.apiKey,
"x-pezzo-project-id": this.options.projectId,
},
body: JSON.stringify(dto),
}
);

if (!response.ok) {
const json = await response.json();
console.warn("Could not report prompt execution", json);
}
}
}

0 comments on commit 0a038d1

Please sign in to comment.