Skip to content

Commit

Permalink
feat: make datasetId optional for experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
willydouhard committed Jul 24, 2024
1 parent 28fc8c4 commit 9888db1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
16 changes: 9 additions & 7 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
PaginatedResponse,
Prompt,
Score,
ScoreConstructor,
Step,
StepType,
Thread,
Expand Down Expand Up @@ -234,7 +235,7 @@ function ingestStepsQueryBuilder(steps: Step[]) {
`;
}

function createScoresFieldsBuilder(scores: Score[]) {
function createScoresFieldsBuilder(scores: ScoreConstructor[]) {
let generated = '';
for (let id = 0; id < scores.length; id++) {
generated += `$name_${id}: String!
Expand All @@ -251,7 +252,7 @@ function createScoresFieldsBuilder(scores: Score[]) {
return generated;
}

function createScoresArgsBuilder(scores: Score[]) {
function createScoresArgsBuilder(scores: ScoreConstructor[]) {
let generated = '';
for (let id = 0; id < scores.length; id++) {
generated += `
Expand All @@ -278,7 +279,7 @@ function createScoresArgsBuilder(scores: Score[]) {
return generated;
}

function createScoresQueryBuilder(scores: Score[]) {
function createScoresQueryBuilder(scores: ScoreConstructor[]) {
return `
mutation CreateScores(${createScoresFieldsBuilder(scores)}) {
${createScoresArgsBuilder(scores)}
Expand Down Expand Up @@ -749,6 +750,7 @@ export class API {
error
type
tags
metadata
}
}
}
Expand Down Expand Up @@ -1741,12 +1743,12 @@ export class API {

public async createExperiment(datasetExperiment: {
name: string;
datasetId: string;
datasetId?: string;
promptId?: string;
params?: Record<string, any> | Array<Record<string, any>>;
}) {
const query = `
mutation CreateDatasetExperiment($name: String!, $datasetId: String! $promptId: String, $params: Json) {
mutation CreateDatasetExperiment($name: String!, $datasetId: String $promptId: String, $params: Json) {
createDatasetExperiment(name: $name, datasetId: $datasetId, promptId: $promptId, params: $params) {
id
}
Expand All @@ -1771,7 +1773,7 @@ export class API {
scores
}: DatasetExperimentItem) {
const query = `
mutation CreateDatasetExperimentItem($datasetExperimentId: String!, $datasetItemId: String!, $input: Json, $output: Json) {
mutation CreateDatasetExperimentItem($datasetExperimentId: String!, $datasetItemId: String, $input: Json, $output: Json) {
createDatasetExperimentItem(datasetExperimentId: $datasetExperimentId, datasetItemId: $datasetItemId, input: $input, output: $output) {
id
input
Expand All @@ -1791,7 +1793,7 @@ export class API {
scores.map((score) => {
score.datasetExperimentItemId =
result.data.createDatasetExperimentItem.id;
return score;
return new Score(score);
})
);

Expand Down
1 change: 1 addition & 0 deletions src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class BaseGeneration extends Utils {
model?: Maybe<string>;
id?: Maybe<string>;
tags?: Maybe<string[]>;
metadata?: Maybe<Record<string, any>>;
error?: Maybe<string>;
variables?: Maybe<Record<string, any>>;
settings?: Maybe<ILLMSettings>;
Expand Down
9 changes: 6 additions & 3 deletions src/instrumentation/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ export type OpenAIOutput =

export interface InstrumentOpenAIOptions {
tags?: Maybe<string[]>;
metadata?: Maybe<Record<string, any>>;
}

export interface ProcessOpenAIOutput extends InstrumentOpenAIOptions {
Expand All @@ -301,13 +302,14 @@ function isStream(obj: any): boolean {
const processOpenAIOutput = async (
client: LiteralClient,
output: OpenAIOutput,
{ start, tags, inputs }: ProcessOpenAIOutput
{ start, tags, metadata, inputs }: ProcessOpenAIOutput
) => {
const baseGeneration = {
provider: 'openai',
model: inputs.model,
settings: getSettings(inputs),
tags: tags
tags: tags,
metadata: metadata
};

let threadFromStore: Thread | null = null;
Expand Down Expand Up @@ -336,7 +338,8 @@ const processOpenAIOutput = async (
output: output,
startTime: new Date(start).toISOString(),
endTime: new Date().toISOString(),
tags: tags
tags: tags,
metadata: metadata
};

const step = parent
Expand Down
24 changes: 15 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ export class Utils {

export type ScoreType = 'HUMAN' | 'AI';

/**
* Represents a score entity with properties to track various aspects of scoring.
* It extends the `Utils` class for serialization capabilities.
*/
export class Score extends Utils {
class ScoreFields extends Utils {
id?: Maybe<string>;
stepId?: Maybe<string>;
generationId?: Maybe<string>;
Expand All @@ -93,13 +89,23 @@ export class Score extends Utils {
scorer?: Maybe<string>;
comment?: Maybe<string>;
tags?: Maybe<string[]>;
}

export type ScoreConstructor = OmitUtils<ScoreFields>;

constructor(data: OmitUtils<Score>) {
/**
* Represents a score entity with properties to track various aspects of scoring.
* It extends the `Utils` class for serialization capabilities.
*/
export class Score extends ScoreFields {
constructor(data: ScoreConstructor) {
super();
Object.assign(this, data);
}
}

export type ScoreCons = OmitUtils<StepFields>;

/**
* Represents an attachment with optional metadata, MIME type, and other properties.
* It extends the `Utils` class for serialization capabilities.
Expand Down Expand Up @@ -631,8 +637,8 @@ export class DatasetItem extends Utils {
class DatasetExperimentItemFields extends Utils {
id?: string;
datasetExperimentId!: string;
datasetItemId!: string;
scores!: Score[];
datasetItemId?: string;
scores!: ScoreConstructor[];
input?: Record<string, any>;
output?: Record<string, any>;
}
Expand All @@ -641,7 +647,7 @@ export class DatasetExperiment extends Utils {
id!: string;
createdAt!: string;
name!: string;
datasetId!: string;
datasetId?: string;
promptId?: string;
api: API;
params!: Record<string, any> | Array<Record<string, any>>;
Expand Down

0 comments on commit 9888db1

Please sign in to comment.