Skip to content
Snippets Groups Projects
Commit 5584d1ae authored by Yi Ding's avatar Yi Ding
Browse files

start building language model

parent 1b941d2c
No related branches found
No related tags found
No related merge requests found
interface LLMResult {}
interface BaseLanguageModel {}
type MessageType = "human" | "ai" | "system" | "chat";
interface BaseMessage {
content: string;
type: MessageType;
}
interface Generation {
text: string;
generationInfo?: { [key: string]: any };
}
interface LLMResult {
generations: Generation[][]; // Each input can have more than one generations
}
class BaseChatModel implements BaseLanguageModel {}
class ChatOpenAI extends BaseChatModel {
model: string = "gpt-3.5-turbo";
temperature: number = 0.7;
openAIKey: string | null = null;
requestTimeout: number | null = null;
maxRetries: number = 6;
n: number = 1;
maxTokens?: number;
async agenerate(messages: BaseMessage[], stop: string[] | null = null) {
return;
}
}
/** /**
* A prompt is a function that takes a dictionary of inputs and returns a string. * A SimplePrompt is a function that takes a dictionary of inputs and returns a string.
* NOTE this is a different interface compared to LlamaIndex Python * NOTE this is a different interface compared to LlamaIndex Python
*/ */
export type Prompt = (input: { [key: string]: string }) => string; export type SimplePrompt = (input: { [key: string]: string }) => string;
/* /*
DEFAULT_TEXT_QA_PROMPT_TMPL = ( DEFAULT_TEXT_QA_PROMPT_TMPL = (
...@@ -15,9 +15,7 @@ DEFAULT_TEXT_QA_PROMPT_TMPL = ( ...@@ -15,9 +15,7 @@ DEFAULT_TEXT_QA_PROMPT_TMPL = (
) )
*/ */
export const defaultTextQaPrompt: Prompt = (input: { export const defaultTextQaPrompt: SimplePrompt = (input) => {
[key: string]: string;
}) => {
const { context, query } = input; const { context, query } = input;
return `Context information is below. return `Context information is below.
...@@ -42,9 +40,7 @@ DEFAULT_SUMMARY_PROMPT_TMPL = ( ...@@ -42,9 +40,7 @@ DEFAULT_SUMMARY_PROMPT_TMPL = (
) )
*/ */
export const defaultSummaryPrompt: Prompt = (input: { export const defaultSummaryPrompt: SimplePrompt = (input) => {
[key: string]: string;
}) => {
const { context } = input; const { context } = input;
return `Write a summary of the following. Try to use only the information provided. Try to include as many key details as possible. return `Write a summary of the following. Try to use only the information provided. Try to include as many key details as possible.
......
...@@ -4,6 +4,12 @@ import { ...@@ -4,6 +4,12 @@ import {
CreateCompletionResponse, CreateCompletionResponse,
CreateChatCompletionRequest, CreateChatCompletionRequest,
CreateChatCompletionResponse, CreateChatCompletionResponse,
CreateEmbeddingRequest,
CreateEmbeddingResponse,
CreateModerationRequest,
CreateModerationResponse,
CreateEditRequest,
CreateEditResponse,
} from "openai"; } from "openai";
import { AxiosRequestConfig, AxiosResponse } from "axios"; import { AxiosRequestConfig, AxiosResponse } from "axios";
import fetchAdapter from "./fetchAdapter"; import fetchAdapter from "./fetchAdapter";
...@@ -28,6 +34,36 @@ export class OpenAIWrapper extends OpenAIApi { ...@@ -28,6 +34,36 @@ export class OpenAIWrapper extends OpenAIApi {
...options, ...options,
}); });
} }
createEmbedding(
createEmbeddingRequest: CreateEmbeddingRequest,
options?: AxiosRequestConfig<any> | undefined
): Promise<AxiosResponse<CreateEmbeddingResponse, any>> {
return super.createEmbedding(createEmbeddingRequest, {
adapter: fetchAdapter,
...options,
});
}
createModeration(
createModerationRequest: CreateModerationRequest,
options?: AxiosRequestConfig<any> | undefined
): Promise<AxiosResponse<CreateModerationResponse, any>> {
return super.createModeration(createModerationRequest, {
adapter: fetchAdapter,
...options,
});
}
createEdit(
createEditRequest: CreateEditRequest,
options?: AxiosRequestConfig<any> | undefined
): Promise<AxiosResponse<CreateEditResponse, any>> {
return super.createEdit(createEditRequest, {
adapter: fetchAdapter,
...options,
});
}
} }
export * from "openai"; export * from "openai";
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
"preserveWatchOutput": true, "preserveWatchOutput": true,
"skipLibCheck": true, "skipLibCheck": true,
"noEmit": true, "noEmit": true,
"strict": true "strict": true,
"lib": ["es2015", "dom"]
}, },
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment