|
1 | 1 | {
|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 |
| - "cell_type": "markdown", |
5 |
| - "id": "60c7fb39", |
| 4 | + "cell_type": "raw", |
| 5 | + "id": "16c03c35-b679-43d4-971b-4ce19e619d51", |
6 | 6 | "metadata": {},
|
7 | 7 | "source": [
|
8 | 8 | "# MultiFMClient\n",
|
9 | 9 | "\n",
|
10 |
| - "MultiFMClient provides a uniform interface for interacting with LLMs from various providers. It adapts the official python libraries from providers such as Mistral, OpenAI, Meta, Anthropic, etc. to conform to the OpenAI chat completion interface.\n", |
| 10 | + "MultiFMClient provides a uniform interface for interacting with LLMs from various providers. It adapts the official python libraries from providers such as Mistral, OpenAI, Groq, Anthropic, Fireworks, Replicate, etc. to conform to the OpenAI chat completion interface.\n", |
11 | 11 | "\n",
|
12 | 12 | "Below are some examples of how to use MultiFMClient to interact with different LLMs."
|
13 | 13 | ]
|
14 | 14 | },
|
15 | 15 | {
|
16 | 16 | "cell_type": "code",
|
| 17 | + "execution_count": 1, |
17 | 18 | "id": "initial_id",
|
18 | 19 | "metadata": {
|
19 |
| - "collapsed": true, |
20 | 20 | "ExecuteTime": {
|
21 | 21 | "end_time": "2024-07-04T15:30:02.064319Z",
|
22 | 22 | "start_time": "2024-07-04T15:30:02.051986Z"
|
23 | 23 | }
|
24 | 24 | },
|
25 |
| - "source": [ |
26 |
| - "import sys\n", |
27 |
| - "sys.path.append('../aimodels')\n", |
28 |
| - "\n", |
29 |
| - "from dotenv import load_dotenv, find_dotenv\n", |
30 |
| - "\n", |
31 |
| - "load_dotenv(find_dotenv())" |
32 |
| - ], |
33 | 25 | "outputs": [
|
34 | 26 | {
|
35 | 27 | "data": {
|
|
42 | 34 | "output_type": "execute_result"
|
43 | 35 | }
|
44 | 36 | ],
|
45 |
| - "execution_count": 1 |
| 37 | + "source": [ |
| 38 | + "import sys\n", |
| 39 | + "sys.path.append('../aimodels')\n", |
| 40 | + "\n", |
| 41 | + "from dotenv import load_dotenv, find_dotenv\n", |
| 42 | + "\n", |
| 43 | + "load_dotenv(find_dotenv())" |
| 44 | + ] |
46 | 45 | },
|
47 | 46 | {
|
48 | 47 | "cell_type": "code",
|
| 48 | + "execution_count": 4, |
| 49 | + "id": "a54491b7-6aa9-4337-9aba-3a0aef263bb4", |
| 50 | + "metadata": {}, |
| 51 | + "outputs": [], |
| 52 | + "source": [ |
| 53 | + "import os \n", |
| 54 | + "\n", |
| 55 | + "os.environ['GROQ_API_KEY'] = 'xxx' # get a free key at https://console.groq.com/keys\n", |
| 56 | + "os.environ['FIREWORKS_API_KEY'] = 'xxx' # get a free key at https://fireworks.ai/api-keys\n", |
| 57 | + "os.environ['REPLICATE_API_KEY'] = 'xxx' # get a free key at https://replicate.com/account/api-tokens" |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "cell_type": "code", |
| 62 | + "execution_count": 8, |
49 | 63 | "id": "4de3a24f",
|
50 | 64 | "metadata": {
|
51 | 65 | "ExecuteTime": {
|
52 | 66 | "end_time": "2024-07-04T15:31:12.914321Z",
|
53 | 67 | "start_time": "2024-07-04T15:31:12.796445Z"
|
54 | 68 | }
|
55 | 69 | },
|
| 70 | + "outputs": [], |
56 | 71 | "source": [
|
57 | 72 | "from aimodels.client import MultiFMClient\n",
|
58 | 73 | "\n",
|
|
62 | 77 | " {\"role\": \"system\", \"content\": \"Respond in Pirate English.\"},\n",
|
63 | 78 | " {\"role\": \"user\", \"content\": \"Tell me a joke\"},\n",
|
64 | 79 | "]"
|
65 |
| - ], |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "code", |
| 84 | + "execution_count": null, |
| 85 | + "id": "668a6cfa-9011-480a-ae1b-6dbd6a51e716", |
| 86 | + "metadata": {}, |
66 | 87 | "outputs": [],
|
67 |
| - "execution_count": 3 |
| 88 | + "source": [ |
| 89 | + "# !pip install fireworks-ai" |
| 90 | + ] |
68 | 91 | },
|
69 | 92 | {
|
70 | 93 | "cell_type": "code",
|
71 |
| - "id": "adebd2f0b578a909", |
72 |
| - "metadata": { |
73 |
| - "ExecuteTime": { |
74 |
| - "end_time": "2024-07-04T15:31:25.060689Z", |
75 |
| - "start_time": "2024-07-04T15:31:16.131205Z" |
| 94 | + "execution_count": 13, |
| 95 | + "id": "9900fdf3-a113-40fd-b42f-0e6d866838be", |
| 96 | + "metadata": {}, |
| 97 | + "outputs": [ |
| 98 | + { |
| 99 | + "name": "stdout", |
| 100 | + "output_type": "stream", |
| 101 | + "text": [ |
| 102 | + "Arrrr, listen close me hearty! Here be a joke fer ye:\n", |
| 103 | + "\n", |
| 104 | + "Why did the pirate quit his job?\n", |
| 105 | + "\n", |
| 106 | + "Because he was sick o' all the arrrr-guments! (get it? arguments, but with an \"arrr\" like a pirate says? aye, I thought it be a good one, matey!)\n" |
| 107 | + ] |
76 | 108 | }
|
77 |
| - }, |
| 109 | + ], |
78 | 110 | "source": [
|
79 |
| - "anthropic_claude_3_opus = \"anthropic:claude-3-opus-20240229\"\n", |
| 111 | + "fireworks_llama3_8b = \"fireworks:accounts/fireworks/models/llama-v3-8b-instruct\"\n", |
| 112 | + "#fireworks_llama3_70b = \"fireworks:accounts/fireworks/models/llama-v3-70b-instruct\"\n", |
80 | 113 | "\n",
|
81 |
| - "response = client.chat.completions.create(model=anthropic_claude_3_opus, messages=messages)\n", |
| 114 | + "response = client.chat.completions.create(model=fireworks_llama3_8b, messages=messages)\n", |
82 | 115 | "\n",
|
83 | 116 | "print(response.choices[0].message.content)"
|
84 |
| - ], |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + "cell_type": "code", |
| 121 | + "execution_count": 11, |
| 122 | + "id": "c9b2aad6-8603-4227-9566-778f714eb0b5", |
| 123 | + "metadata": {}, |
85 | 124 | "outputs": [
|
86 | 125 | {
|
87 | 126 | "name": "stdout",
|
88 | 127 | "output_type": "stream",
|
89 | 128 | "text": [
|
90 |
| - "Arrr, me bucko, 'ere be a jolly jest fer ye!\n", |
| 129 | + "Arrrr, listen close me hearty! Here be a joke fer ye:\n", |
| 130 | + "\n", |
| 131 | + "Why did the pirate quit his job?\n", |
91 | 132 | "\n",
|
92 |
| - "What did th' pirate say on 'is 80th birthday? \"Aye matey!\"\n", |
| 133 | + "Because he were sick o' all the arrrr-guments! (get it? arguments, but with arrrr, like a pirate says \"arrgh\"! ahhahahah!)\n", |
93 | 134 | "\n",
|
94 |
| - "Ye see, it be a play on words, as \"Aye matey\" sounds like \"I'm eighty\". Har har har! 'Tis a clever bit o' pirate humor, if I do say so meself. Now, 'ow about ye fetch me a mug o' grog while I spin ye another yarn?\n" |
| 135 | + "Yer turn, matey! Got a joke to share?\n" |
95 | 136 | ]
|
96 | 137 | }
|
97 | 138 | ],
|
98 |
| - "execution_count": 4 |
| 139 | + "source": [ |
| 140 | + "groq_llama3_8b = \"groq:llama3-8b-8192\"\n", |
| 141 | + "# groq_llama3_70b = \"groq:llama3-70b-8192\"\n", |
| 142 | + "\n", |
| 143 | + "response = client.chat.completions.create(model=groq_llama3_8b, messages=messages)\n", |
| 144 | + "\n", |
| 145 | + "print(response.choices[0].message.content)" |
| 146 | + ] |
99 | 147 | },
|
100 | 148 | {
|
101 | 149 | "cell_type": "code",
|
102 |
| - "execution_count": 4, |
103 |
| - "id": "6819ac17", |
| 150 | + "execution_count": 12, |
| 151 | + "id": "6baf88b8-2ecb-4bdf-9263-4af949668d16", |
104 | 152 | "metadata": {},
|
105 | 153 | "outputs": [
|
106 | 154 | {
|
107 | 155 | "name": "stdout",
|
108 | 156 | "output_type": "stream",
|
109 | 157 | "text": [
|
110 |
| - "Arrrr, here be a joke fer ye!\n", |
| 158 | + "Arrrr, listen close me hearty! Here be a joke fer ye:\n", |
| 159 | + "\n", |
| 160 | + "Why did the pirate quit his job?\n", |
111 | 161 | "\n",
|
112 |
| - "Why did the pirate take a parrot on his ship?\n", |
| 162 | + "Because he were sick o' all the arrrr-guments! (get it? arguments, but with arrrr, like a pirate says \"arrgh\"! ahhahahah!)\n", |
113 | 163 | "\n",
|
114 |
| - "Because it were a hootin' good bird to have around, savvy? Aye, and it kept 'im company while he were swabbin' the decks! Arrrgh, I hope that made ye laugh, matey!\n" |
| 164 | + "Yer turn, matey! Got a joke to share?\n" |
115 | 165 | ]
|
116 | 166 | }
|
117 | 167 | ],
|
| 168 | + "source": [ |
| 169 | + "replicate_llama3_8b = \"replicate:meta/meta-llama-3-8b-instruct\"\n", |
| 170 | + "#replicate_llama3_70b = \"replicate:meta/meta-llama-3-70b-instruct\"\n", |
| 171 | + "\n", |
| 172 | + "response = client.chat.completions.create(model=replicate_llama3_8b, messages=messages)\n", |
| 173 | + "\n", |
| 174 | + "print(response.choices[0].message.content)" |
| 175 | + ] |
| 176 | + }, |
| 177 | + { |
| 178 | + "cell_type": "code", |
| 179 | + "execution_count": null, |
| 180 | + "id": "adebd2f0b578a909", |
| 181 | + "metadata": { |
| 182 | + "ExecuteTime": { |
| 183 | + "end_time": "2024-07-04T15:31:25.060689Z", |
| 184 | + "start_time": "2024-07-04T15:31:16.131205Z" |
| 185 | + } |
| 186 | + }, |
| 187 | + "outputs": [], |
| 188 | + "source": [ |
| 189 | + "anthropic_claude_3_opus = \"anthropic:claude-3-opus-20240229\"\n", |
| 190 | + "\n", |
| 191 | + "response = client.chat.completions.create(model=anthropic_claude_3_opus, messages=messages)\n", |
| 192 | + "\n", |
| 193 | + "print(response.choices[0].message.content)" |
| 194 | + ] |
| 195 | + }, |
| 196 | + { |
| 197 | + "cell_type": "code", |
| 198 | + "execution_count": null, |
| 199 | + "id": "6819ac17", |
| 200 | + "metadata": {}, |
| 201 | + "outputs": [], |
118 | 202 | "source": [
|
119 | 203 | "ollama_llama3 = \"ollama:llama3\"\n",
|
120 | 204 | "\n",
|
|
124 | 208 | ]
|
125 | 209 | },
|
126 | 210 | {
|
| 211 | + "cell_type": "code", |
| 212 | + "execution_count": null, |
| 213 | + "id": "4a94961b2bddedbb", |
127 | 214 | "metadata": {
|
128 | 215 | "ExecuteTime": {
|
129 | 216 | "end_time": "2024-07-04T15:31:39.472675Z",
|
130 | 217 | "start_time": "2024-07-04T15:31:38.283368Z"
|
131 | 218 | }
|
132 | 219 | },
|
133 |
| - "cell_type": "code", |
| 220 | + "outputs": [], |
134 | 221 | "source": [
|
135 | 222 | "mistral_7b = \"mistral:open-mistral-7b\"\n",
|
136 | 223 | "\n",
|
137 | 224 | "response = client.chat.completions.create(model=mistral_7b, messages=messages, temperature=0.2)\n",
|
138 | 225 | "\n",
|
139 | 226 | "print(response.choices[0].message.content)"
|
140 |
| - ], |
141 |
| - "id": "4a94961b2bddedbb", |
142 |
| - "outputs": [ |
143 |
| - { |
144 |
| - "name": "stdout", |
145 |
| - "output_type": "stream", |
146 |
| - "text": [ |
147 |
| - "Arr matey, I've got a jest fer ye, if ye be ready for a laugh! Why did the pirate bring a clock to the island? Because he wanted to catch the time! Aye, that be a good one, I be thinkin'. Arrr!\n" |
148 |
| - ] |
149 |
| - } |
150 |
| - ], |
151 |
| - "execution_count": 5 |
| 227 | + ] |
152 | 228 | },
|
153 | 229 | {
|
154 |
| - "metadata": {}, |
155 | 230 | "cell_type": "code",
|
156 |
| - "outputs": [], |
157 | 231 | "execution_count": null,
|
158 |
| - "source": "", |
159 |
| - "id": "611210a4dc92845f" |
| 232 | + "id": "611210a4dc92845f", |
| 233 | + "metadata": {}, |
| 234 | + "outputs": [], |
| 235 | + "source": [] |
160 | 236 | }
|
161 | 237 | ],
|
162 | 238 | "metadata": {
|
163 | 239 | "kernelspec": {
|
164 |
| - "display_name": "Python 3", |
| 240 | + "display_name": "Python 3 (ipykernel)", |
165 | 241 | "language": "python",
|
166 | 242 | "name": "python3"
|
167 | 243 | },
|
|
175 | 251 | "name": "python",
|
176 | 252 | "nbconvert_exporter": "python",
|
177 | 253 | "pygments_lexer": "ipython3",
|
178 |
| - "version": "3.12.3" |
| 254 | + "version": "3.10.14" |
179 | 255 | }
|
180 | 256 | },
|
181 | 257 | "nbformat": 4,
|
|
0 commit comments