| 1 | import OpenAI from "./OpenAI.js"; |
| 2 | |
| 3 | import type { CompletionOptions, LLMOptions } from "../../index.js"; |
| 4 | |
| 5 | class Together extends OpenAI { |
| 6 | static providerName = "together"; |
| 7 | static defaultOptions: Partial<LLMOptions> = { |
| 8 | apiBase: "https://api.together.xyz/v1/", |
| 9 | }; |
| 10 | |
| 11 | private static MODEL_IDS: { [name: string]: string } = { |
| 12 | "codellama-7b": "togethercomputer/CodeLlama-7b-Instruct", |
| 13 | "codellama-13b": "togethercomputer/CodeLlama-13b-Instruct", |
| 14 | "codellama-34b": "togethercomputer/CodeLlama-34b-Instruct", |
| 15 | "codellama-70b": "codellama/CodeLlama-70b-Instruct-hf", |
| 16 | "llama3-8b": "meta-llama/Llama-3-8b-chat-hf", |
| 17 | "llama3-70b": "meta-llama/Llama-3-70b-chat-hf", |
| 18 | "llama3.1-8b": "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo", |
| 19 | "llama3.1-70b": "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo", |
| 20 | "llama3.1-405b": "meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo", |
| 21 | "llama3.2-3b": "meta-llama/Llama-3.2-3B-Instruct-Turbo", |
| 22 | "llama3.2-11b": "meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo", |
| 23 | "llama3.2-90b": "meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo", |
| 24 | "llama2-7b": "togethercomputer/llama-2-7b-chat", |
| 25 | "llama2-13b": "togethercomputer/llama-2-13b-chat", |
| 26 | "llama2-70b": "togethercomputer/llama-2-70b-chat", |
| 27 | "mistral-7b": "mistralai/Mistral-7B-Instruct-v0.1", |
| 28 | "mistral-8x7b": "mistralai/Mixtral-8x7B-Instruct-v0.1", |
| 29 | "phind-codellama-34b": "Phind/Phind-CodeLlama-34B-v2", |
| 30 | "wizardcoder-34b": "WizardLM/WizardCoder-Python-34B-V1.0", |
| 31 | }; |
| 32 | |
| 33 | protected _convertModelName(model: string) { |
| 34 | return Together.MODEL_IDS[model] || this.model; |
| 35 | } |
| 36 | |
| 37 | protected async *_streamComplete( |
| 38 | prompt: string, |
| 39 | signal: AbortSignal, |
| 40 | options: CompletionOptions, |
| 41 | ): AsyncGenerator<string> { |
| 42 | for await (const chunk of this._legacystreamComplete( |
| 43 | prompt, |
| 44 | signal, |
| 45 | options, |
| 46 | )) { |
| 47 | yield chunk; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | export default Together; |