Compare commits

...

18 Commits

Author SHA1 Message Date
sweep-ai[bot] 85bc74d320 Merge main into sweep/add-ollama-support 2023-10-26 23:04:32 +00:00
sweep-ai[bot] a00291cd55 Merge main into sweep/add-ollama-support 2023-10-26 22:42:56 +00:00
sweep-ai[bot] 344d1d61dc Merge main into sweep/add-ollama-support 2023-10-26 22:06:56 +00:00
sweep-ai[bot] 8a30bfdd36 Merge main into sweep/add-ollama-support 2023-10-25 23:53:32 +00:00
sweep-ai[bot] bc6d481243 Merge main into sweep/add-ollama-support 2023-10-25 21:13:10 +00:00
sweep-ai[bot] f30734fef6 Merge main into sweep/add-ollama-support 2023-10-25 19:54:20 +00:00
sweep-ai[bot] be1c3b805b feat: Updated packages/core/src/llm/Ollama.ts 2023-10-22 09:49:58 +00:00
sweep-ai[bot] b1ac7ddea9 feat: Updated packages/core/src/llm/Ollama.ts 2023-10-22 09:46:50 +00:00
sweep-ai[bot] 642e4a59c5 feat: Updated packages/core/src/llm/Ollama.ts 2023-10-22 09:45:09 +00:00
sweep-ai[bot] 5a7cc632e8 feat: Updated packages/core/src/llm/Ollama.ts 2023-10-22 09:42:04 +00:00
sweep-ai[bot] 11dd5b6fa6 feat: Updated packages/core/src/llm/Ollama.ts 2023-10-22 09:41:03 +00:00
sweep-ai[bot] 52d94d4458 feat: Updated packages/core/src/llm/Ollama.ts 2023-10-22 09:38:08 +00:00
sweep-ai[bot] 03d2723c12 feat: Updated packages/core/src/llm/Ollama.ts 2023-10-22 09:36:29 +00:00
sweep-ai[bot] aab27fd9dd feat: Updated packages/core/src/llm/Ollama.ts 2023-10-22 09:34:01 +00:00
sweep-ai[bot] efa73858db feat: Updated packages/core/src/llm/Ollama.ts 2023-10-22 09:32:13 +00:00
sweep-ai[bot] e57fc3747c feat: Updated packages/core/src/llm/Ollama.ts 2023-10-22 09:29:49 +00:00
sweep-ai[bot] 2fe4dcda6e feat: Add Ollama class for running large language 2023-10-22 09:25:26 +00:00
sweep-ai[bot] 8675a140e5 feat: Updated packages/core/src/llm/LLM.ts 2023-10-22 09:18:45 +00:00
2 changed files with 90 additions and 0 deletions
+12
View File
@@ -7,6 +7,7 @@ import {
OpenAIStreamToken,
StreamCallbackResponse,
} from "../callbacks/CallbackManager";
import { Ollama } from "./Ollama";
import { LLMOptions } from "portkey-ai";
import { globalsHelper, Tokenizers } from "../GlobalsHelper";
@@ -97,6 +98,17 @@ export interface LLM {
* Calculates the number of tokens needed for the given chat messages
*/
tokens(messages: ChatMessage[]): number;
/**
* Initialize an Ollama instance
*/
initOllama(): Promise<Ollama>;
/**
* Send a prompt to the Ollama instance and get a response
* @param prompt the prompt to send
*/
ollamaChat(prompt: string): Promise<string>;
}
export const GPT4_MODELS = {
+78
View File
@@ -0,0 +1,78 @@
import { LLM, ChatMessage, ChatResponse, Event } from "./LLM";
import { Tokenizers } from "../helpers/GlobalsHelper";
import { OllamaInstance } from "./OllamaInstance";
export class Ollama implements LLM {
private ollama: OllamaInstance; // Add a private property to hold the Ollama instance
private hasStreaming: boolean; // Add a private property to hold the streaming capability of the Ollama instance
constructor(ollamaInstance: OllamaInstance) {
// Initialize Ollama instance
this.ollama = ollamaInstance; // Initialize the Ollama instance with the provided OllamaInstance
}
async runModelLocally(model: string, options: Record<string, any>): Promise<string> {
// Logic for running the model locally
const result = await this.ollama.runModelLocally(model, options); // Run the model locally using the Ollama instance and return the result
if (result.error) {
throw new Error(result.error);
}
return result.output;
}
async complete<
T extends boolean | undefined = undefined,
R = T extends true ? AsyncGenerator<string, void, unknown> : ChatResponse,
>(
prompt: string,
parentEvent?: Event | undefined,
streaming?: T,
): Promise<R> {
return this.chat([{ content: prompt, role: "user" }], parentEvent, streaming);
}
async *streamEndpoint(model: string, prompt: string, options: Record<string, any>): AsyncGenerator<string, void, unknown> {
// Logic for streaming the model's output
if (this.hasStreaming) {
const stream = this.ollama.streamEndpoint(model, prompt, options);
for await (const output of stream) {
yield output;
}
} else {
throw new Error("Streaming is not supported by this Ollama instance.");
}
}
async chat<
T extends boolean | undefined = undefined,
R = T extends true ? AsyncGenerator<string, void, unknown> : ChatResponse,
>(
messages: ChatMessage[],
parentEvent?: Event | undefined,
streaming?: T,
): Promise<R> {
return this.ollama.chat(messages, parentEvent, streaming);
}
// Duplicated complete method removed
tokens(messages: ChatMessage[]): number {
// Logic for calculating tokens
let totalTokens = 0;
for (const message of messages) {
totalTokens += message.content.split(' ').length;
}
return totalTokens;
}
get metadata() {
return {
model: "OllamaModel",
temperature: 0.1,
topP: 0.9,
maxTokens: 1000,
contextWindow: 500,
tokenizer: Tokenizers.CL100K_BASE, // Add tokenizer property
};
}
}