Skip to content

Commit 90558ac

Browse files
amirai21asafgardin
authored andcommitted
feat: quality fix
1 parent af51e52 commit 90558ac

File tree

8 files changed

+44
-48
lines changed

8 files changed

+44
-48
lines changed

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run lint && npm run format && npm run quality:fix

src/examples/chatExample.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AI21 } from "../AI21";
1+
import { AI21 } from '../AI21';
22

33
/*
44
This is a temporary example to test the API streaming/non-streaming functionality.
@@ -7,7 +7,6 @@ async function main() {
77
const client = new AI21({ apiKey: process.env.AI21_API_KEY });
88

99
try {
10-
1110
console.log('-------------------------------- streaming flow --------------------------------');
1211

1312
const streamResponse = await client.chat.completions.create({

src/examples/convRagExample.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import { AI21 } from "../AI21";
1+
import { AI21 } from '../AI21';
22

33
/*
44
This is a temporary example to test the Conversational RAG functionality.
55
*/
66
async function main() {
7-
8-
/* TODO - add a file upload example when library support is added and combine it with the below flow */
7+
/* TODO - add a file upload example when library support is added and combine it with the below flow */
98

109
const client = new AI21({ apiKey: process.env.AI21_API_KEY });
1110
try {
12-
1311
/* The following example is for a question that is not in the context of files uploaded to RAG */
14-
12+
1513
const answer_not_in_ctx_response = await client.conversationalRag.create({
1614
messages: [{ role: 'user', content: 'Who is the Russian president?' }],
1715
});

src/resources/rag/conversationalRag.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ import { ConversationalRagRequest } from '../../types/rag/ConversationalRagReque
44
import { ConversationalRagResponse } from '../../types/rag/ConversationalRagResponse';
55

66
export class ConversationalRag extends APIResource {
7-
8-
create(body: ConversationalRagRequest, options?: Models.RequestOptions){
9-
return this.client.post<ConversationalRagRequest, ConversationalRagResponse>(
10-
'/conversational-rag',
11-
{
12-
body,
13-
...options,
14-
} as Models.RequestOptions<ConversationalRagRequest>,
15-
) as Promise<ConversationalRagResponse>;
7+
create(body: ConversationalRagRequest, options?: Models.RequestOptions) {
8+
return this.client.post<ConversationalRagRequest, ConversationalRagResponse>('/conversational-rag', {
9+
body,
10+
...options,
11+
} as Models.RequestOptions<ConversationalRagRequest>) as Promise<ConversationalRagResponse>;
1612
}
1713
}
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { ChatMessageParam } from "../chat";
2-
import { RetrievalStrategy } from "./RetrievalStrategy";
1+
import { ChatMessageParam } from '../chat';
2+
import { RetrievalStrategy } from './RetrievalStrategy';
33

44
export interface ConversationalRagRequest {
5-
messages: ChatMessageParam[];
6-
path?: string | null;
7-
labels?: string[] | null;
8-
file_ids?: string[] | null;
9-
max_segments?: number | null;
10-
retrieval_strategy?: RetrievalStrategy | string | null;
11-
retrieval_similarity_threshold?: number | null;
12-
max_neighbors?: number | null;
13-
hybrid_search_alpha?: number | null;
14-
[key: string]: any;
15-
}
5+
messages: ChatMessageParam[];
6+
path?: string | null;
7+
labels?: string[] | null;
8+
file_ids?: string[] | null;
9+
max_segments?: number | null;
10+
retrieval_strategy?: RetrievalStrategy | string | null;
11+
retrieval_similarity_threshold?: number | null;
12+
max_neighbors?: number | null;
13+
hybrid_search_alpha?: number | null;
14+
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { ChatMessage } from "../chat";
2-
import { ConversationalRagSource } from "./ConversationalRagSource";
1+
import { ChatMessage } from '../chat';
2+
import { ConversationalRagSource } from './ConversationalRagSource';
33

44
export interface ConversationalRagResponse {
5-
id: string;
6-
choices: ChatMessage[];
7-
search_queries?: string[] | null;
8-
context_retrieved: boolean;
9-
answer_in_context: boolean;
10-
sources: ConversationalRagSource[];
5+
id: string;
6+
choices: ChatMessage[];
7+
search_queries?: string[] | null;
8+
context_retrieved: boolean;
9+
answer_in_context: boolean;
10+
sources: ConversationalRagSource[];
1111
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export interface ConversationalRagSource {
2-
text: string;
3-
file_id: string;
4-
file_name: string;
5-
score: number;
6-
order?: number | null;
7-
public_url?: string | null;
8-
labels?: string[] | null;
2+
text: string;
3+
file_id: string;
4+
file_name: string;
5+
score: number;
6+
order?: number | null;
7+
public_url?: string | null;
8+
labels?: string[] | null;
99
}

src/types/rag/RetrievalStrategy.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export enum RetrievalStrategy {
2-
DEFAULT = "default",
3-
SEGMENTS = "segments",
4-
ADD_NEIGHBORS = "add_neighbors",
5-
FULL_DOC = "full_doc"
2+
DEFAULT = 'default',
3+
SEGMENTS = 'segments',
4+
ADD_NEIGHBORS = 'add_neighbors',
5+
FULL_DOC = 'full_doc',
66
}

0 commit comments

Comments
 (0)