Skip to content

Commit

Permalink
feat: sits analyze types and schema
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeocodes committed Jan 22, 2024
1 parent aa2acda commit a9fed04
Show file tree
Hide file tree
Showing 8 changed files with 424 additions and 89 deletions.
21 changes: 19 additions & 2 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Headers as CrossFetchHeaders } from "cross-fetch";
import { DeepgramClientOptions, FileSource, PrerecordedSource, UrlSource } from "./types";
import {
DeepgramClientOptions,
FileSource,
PrerecordedSource,
UrlSource,
TextSource,
AnalyzeSource,
} from "./types";
import { Readable } from "stream";
import merge from "deepmerge";

Expand Down Expand Up @@ -41,12 +48,22 @@ export const resolveHeadersConstructor = () => {
return Headers;
};

export const isUrlSource = (providedSource: PrerecordedSource): providedSource is UrlSource => {
export const isUrlSource = (
providedSource: PrerecordedSource | AnalyzeSource
): providedSource is UrlSource => {
if ((providedSource as UrlSource).url) return true;

return false;
};

export const isTextSource = (
providedSource: PrerecordedSource | AnalyzeSource
): providedSource is TextSource => {
if ((providedSource as TextSource).text) return true;

return false;
};

export const isFileSource = (providedSource: PrerecordedSource): providedSource is FileSource => {
if (isReadStreamSource(providedSource) || isBufferSource(providedSource)) return true;

Expand Down
28 changes: 28 additions & 0 deletions src/lib/types/AnalyzeSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Options for read analysis
*/
interface AnalyzeSchema extends Record<string, unknown> {
callback?: string;

callback_method?: string;

custom_intent?: string | string[];

custom_intent_mode?: "strict" | "extended";

custom_topic?: string | string[];

custom_topic_mode?: "strict" | "extended";

intents?: boolean;

language?: string;

summarize?: boolean;

sentiment?: boolean;

topics?: boolean;
}

export type { AnalyzeSchema };
3 changes: 3 additions & 0 deletions src/lib/types/AsyncAnalyzeResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface AsyncAnalyzeResponse {
request_id: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ export type FileSource = Buffer | Readable;
export interface UrlSource {
url: string;
}

export interface TextSource {
text: string;
}

export type AnalyzeSource = UrlSource | TextSource;
88 changes: 88 additions & 0 deletions src/lib/types/SyncAnalyzeResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
export interface SyncAnalyzeResponse {
model_uuid: string;
metadata: Metadata;
results: Results;
}

interface IntentsInfo {
model_uuid: string;
input_tokens: number;
output_tokens: number;
}

interface SentimentInfo {
model_uuid: string;
input_tokens: number;
output_tokens: number;
}

interface SummaryInfo {
model_uuid: string;
input_tokens: number;
output_tokens: number;
}

interface TopicsInfo {
model_uuid: string;
input_tokens: number;
output_tokens: number;
}

interface Metadata {
request_id: string;
created: string;
language: string;
intents_info: IntentsInfo;
sentiment_info: SentimentInfo;
summary_info: SummaryInfo;
topics_info: TopicsInfo;
}

interface Average {
sentiment: string;
sentiment_score: number;
}

interface Summary {
text: string;
}

interface Topic {
topic: string;
confidence_score: number;
}

interface Intent {
intent: string;
confidence_score: number;
}

interface Segment {
text: string;
start_word: number;
end_word: number;
sentiment: "positive" | "neutral" | "negative";
sentiment_score?: number;
topics?: Topic[];
intents?: Intent[];
}

interface Sentiments {
segments: Segment[];
average: Average;
}

interface Topics {
segments: Segment[];
}

interface Intents {
segments: Segment[];
}

interface Results {
sentiments?: Sentiments;
summary?: Summary;
topics?: Topics;
intents?: Intents;
}
Loading

0 comments on commit a9fed04

Please sign in to comment.