Compare commits

...

11 Commits

Author SHA1 Message Date
sweep-ai[bot] 5e20c8078d Merge main into sweep/connectors-support 2023-09-12 04:53:33 +00:00
sweep-ai[bot] 76c80f2e0c Merge main into sweep/connectors-support 2023-09-11 18:14:29 +00:00
sweep-ai[bot] c51e43b8f9 Merge main into sweep/connectors-support 2023-09-11 17:45:43 +00:00
sweep-ai[bot] f0a610a476 Merge main into sweep/connectors-support 2023-09-11 17:33:57 +00:00
sweep-ai[bot] 7d3e3aba3c Merge main into sweep/connectors-support 2023-09-11 17:33:05 +00:00
sweep-ai[bot] d8526d44d6 Merge main into sweep/connectors-support 2023-09-11 17:12:44 +00:00
sweep-ai[bot] 56beddfc44 Updated README.md 2023-09-11 15:48:35 +00:00
sweep-ai[bot] c8eaa588da Updated packages/core/src/llm/LLM.ts 2023-09-11 15:38:00 +00:00
sweep-ai[bot] 0d91e4fb95 Add OobaTextGeneration class for ooba text generat 2023-09-11 15:28:15 +00:00
sweep-ai[bot] 90fd77caf5 Add HuggingFacesTextGeneration connector 2023-09-11 15:19:51 +00:00
sweep-ai[bot] d9bc600f35 Added PythonLlamaCpp class for python llama cpp ap 2023-09-11 15:11:24 +00:00
5 changed files with 135 additions and 40 deletions
+31
View File
@@ -89,6 +89,37 @@ Check out our NextJS playground at https://llama-playground.vercel.app/. The sou
- OpenAI GPT-3.5-turbo and GPT-4
- Anthropic Claude Instant and Claude 2
- Llama2 Chat LLMs (70B, 13B, and 7B parameters)
- Python Llama CPP API
- Hugging Faces Text Generation Inference
- Ooba Text Generation API
## New Connectors:
We have added support for three new connectors:
- Python Llama CPP API: This connector allows you to use the Python bindings for the llama.cpp library with LlamaIndex.TS. To use this connector, simply import it and create a new instance of the PythonLlamaCpp class.
```ts
import { PythonLlamaCpp } from "llamaindex";
const pythonLlamaCpp = new PythonLlamaCpp();
```
- Hugging Faces Text Generation Inference: This connector allows you to use the Hugging Faces text generation inference tool with LlamaIndex.TS. To use this connector, simply import it and create a new instance of the HuggingFacesTextGeneration class.
```ts
import { HuggingFacesTextGeneration } from "llamaindex";
const huggingFacesTextGeneration = new HuggingFacesTextGeneration();
```
- Ooba Text Generation API: This connector allows you to use the Ooba text generation API with LlamaIndex.TS. To use this connector, simply import it and create a new instance of the OobaTextGeneration class.
```ts
import { OobaTextGeneration } from "llamaindex";
const oobaTextGeneration = new OobaTextGeneration();
```
## Contributing:
@@ -0,0 +1,25 @@
import axios from 'axios';
class HuggingFacesTextGeneration {
private apiEndpoint: string;
constructor(apiEndpoint: string) {
this.apiEndpoint = apiEndpoint;
}
async sendRequest(prompt: string) {
const response = await axios.post(this.apiEndpoint, {
prompt: prompt,
});
return this.receiveResponse(response);
}
receiveResponse(response: any) {
if (response.status !== 200) {
throw new Error(`Unexpected response code: ${response.status}`);
}
return response.data;
}
}
export default HuggingFacesTextGeneration;
+35 -40
View File
@@ -16,6 +16,9 @@ import {
} from "./azure";
import { OpenAISession, getOpenAISession } from "./openai";
import { ReplicateSession } from "./replicate";
import { PythonLlamaCpp } from "./PythonLlamaCpp";
import { HuggingFacesTextGeneration } from "./HuggingFacesTextGeneration";
import { OobaTextGeneration } from "./OobaTextGeneration";
export type MessageType =
| "user"
@@ -24,21 +27,17 @@ export type MessageType =
| "generic"
| "function";
export interface ChatMessage {
content: string;
role: MessageType;
}
export interface ChatResponse {
message: ChatMessage;
raw?: Record<string, any>;
delta?: string;
}
// NOTE in case we need CompletionResponse to diverge from ChatResponse in the future
export type CompletionResponse = ChatResponse;
/**
export const ALL_AVAILABLE_LLAMAS = {
"openai-gpt3": OpenAI,
"openai-gpt4": OpenAI,
"anthropic-claude": Anthropic,
"llama2-70b": LlamaDeuce,
"llama2-13b": LlamaDeuce,
"llama2-7b": LlamaDeuce,
"python-llama-cpp": PythonLlamaCpp,
"hugging-faces-text-generation": HuggingFacesTextGeneration,
"ooba-text-generation": OobaTextGeneration,
};
* Unified language model interface
*/
export interface LLM {
@@ -49,31 +48,27 @@ export interface LLM {
chat(messages: ChatMessage[], parentEvent?: Event): Promise<ChatResponse>;
/**
* Get a prompt completion from the LLM
* @param prompt the prompt to complete
*/
complete(prompt: string, parentEvent?: Event): Promise<CompletionResponse>;
}
export const GPT4_MODELS = {
"gpt-4": { contextWindow: 8192 },
"gpt-4-32k": { contextWindow: 32768 },
};
export const TURBO_MODELS = {
"gpt-3.5-turbo": { contextWindow: 4096 },
"gpt-3.5-turbo-16k": { contextWindow: 16384 },
};
/**
* We currently support GPT-3.5 and GPT-4 models
*/
export const ALL_AVAILABLE_OPENAI_MODELS = {
...GPT4_MODELS,
...TURBO_MODELS,
};
/**
export function getLLM(llmName: keyof typeof ALL_AVAILABLE_LLAMAS): LLM {
switch (llmName) {
case "openai-gpt3":
case "openai-gpt4":
return new OpenAI();
case "anthropic-claude":
return new Anthropic();
case "llama2-70b":
case "llama2-13b":
case "llama2-7b":
return new LlamaDeuce();
case "python-llama-cpp":
return new PythonLlamaCpp();
case "hugging-faces-text-generation":
return new HuggingFacesTextGeneration();
case "ooba-text-generation":
return new OobaTextGeneration();
default:
throw new Error(`Unsupported LLM: ${llmName}`);
}
}
* OpenAI LLM implementation
*/
export class OpenAI implements LLM {
@@ -0,0 +1,21 @@
import axios from 'axios';
class OobaTextGeneration {
private apiURL: string;
constructor(apiURL: string) {
this.apiURL = apiURL;
}
async sendRequest(input: string): Promise<string> {
try {
const response = await axios.post(this.apiURL, { text: input });
return response.data;
} catch (error) {
console.error(`Error sending request to Ooba Text Generation API: ${error}`);
throw error;
}
}
}
export default OobaTextGeneration;
+23
View File
@@ -0,0 +1,23 @@
import axios from 'axios';
class PythonLlamaCpp {
private apiURL: string;
constructor(apiURL: string) {
this.apiURL = apiURL;
}
async sendRequest(prompt: string) {
const response = await axios.post(this.apiURL, {
prompt: prompt
});
return response.data;
}
async receiveResponse() {
const response = await axios.get(this.apiURL);
return response.data;
}
}
export default PythonLlamaCpp;