Skip to content

Commit

Permalink
refactor: improve typings
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Aug 31, 2023
1 parent 5045355 commit f80921f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 9 additions & 2 deletions packages/api/src/lib/approaches/approach.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
// TODO: improve typings
import { HistoryMessage } from '../message';

export interface ChatQueryResponse {
data_points: string[];
answer: string;
thoughts: string;
}

export interface ChatApproach {
run(history: any[], overrides: Record<string, any>): Promise<any>;
run(history: HistoryMessage[], overrides: Record<string, any>): Promise<ChatQueryResponse>;
}

// TODO: improve typing
export interface AskApproach {
run(q: string, overrides: Record<string, any>): Promise<any>;
}
10 changes: 2 additions & 8 deletions packages/api/src/lib/approaches/chat-read-retrieve-read.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { SearchClient } from '@azure/search-documents';
import { ChatApproach } from './approach.js';
import { ChatApproach, ChatQueryResponse } from './approach.js';
import { OpenAiClients } from '../../plugins/openai.js';
import { removeNewlines } from '../util/index.js';
import { MessageBuilder } from '../message-builder.js';
import { getTokenLimit } from '../model-helpers.js';
import { HistoryMessage, Message, messageToString } from '../message.js';

export interface QueryResponse {
data_points: string[];
answer: string;
thoughts: string;
}

const SYSTEM_MESSAGE_CHAT_CONVERSATION = `Assistant helps the company employees with their healthcare plan questions, and questions about the employee handbook. Be brief in your answers.
Answer ONLY with the facts listed in the list of sources below. If there isn't enough information below, say you don't know. Do not generate answers that don't use the sources below. If asking a clarifying question to the user would help, ask the question.
For tabular information return it as an html table. Do not return markdown format. If the question is not in English, answer in the language used in the question.
Expand Down Expand Up @@ -59,7 +53,7 @@ export class ChatReadRetrieveReadApproach implements ChatApproach {
this.chatGptTokenLimit = getTokenLimit(chatGptModel);
}

async run(history: HistoryMessage[], overrides: Record<string, any>): Promise<QueryResponse> {
async run(history: HistoryMessage[], overrides: Record<string, any>): Promise<ChatQueryResponse> {
const hasText = ['text', 'hybrid', undefined].includes(overrides?.retrieval_mode);
// const hasVectors = ['vectors', 'hybrid', undefined].includes(overrides?.retrieval_mode);
const useSemanticCaption = Boolean(overrides?.use_semantic_caption) && hasText;
Expand Down

0 comments on commit f80921f

Please sign in to comment.