From 747473ebfea23a3125bd85a1e6784a76e470f333 Mon Sep 17 00:00:00 2001 From: Edward Donner Date: Wed, 11 Dec 2024 09:46:01 -0500 Subject: [PATCH] Updated README with Free API code snippet --- README.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 94285b3..5b133d8 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,30 @@ Hopefully I've done a decent job of making these guides bulletproof - but please During the course, I'll suggest you try out the leading models at the forefront of progress, known as the Frontier models. I'll also suggest you run open-source models using Google Colab. These services have some charges, but I'll keep cost minimal - like, a few cents at a time. And I'll provide alternatives if you'd prefer not to use them. -Please do monitor your API usage to ensure you're comfortable with spend; I've included links below. There's no need to spend anything more than a couple of dollars for the entire course. Some AI providers such as OpenAI require a minimum credit like \$5 or local equivalent; we should only spend a fraction of it, and you'll have plenty of opportunity to put it to good use in your own projects. During Week 7 you have an option to spend a bit more if you're enjoying the process - I spend about $10 myself and the results make me very happy indeed! But it's not necessary in the least; the important part is that you focus on learning. +Please do monitor your API usage to ensure you're comfortable with spend; I've included links below. There's no need to spend anything more than a couple of dollars for the entire course. Some AI providers such as OpenAI require a minimum credit like \$5 or local equivalent; we should only spend a fraction of it, and you'll have plenty of opportunity to put it to good use in your own projects. During Week 7 you have an option to spend a bit more if you're enjoying the process - I spend about \$10 myself and the results make me very happy indeed! But it's not necessary in the least; the important part is that you focus on learning. -I'll also show you an alternative if you'd rather not spend anything on APIs. +### Free alternative to Paid APIs + +Early in the course, I show you an alternative if you'd rather not spend anything on APIs: +Any time that we have code like: +`openai = OpenAI()` +You can use this as a direct replacement: +`openai = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')` + +Below is a full example: + +``` +from openai import OpenAI +MODEL = "llama3.2" +openai = OpenAI(base_url='http://localhost:11434/v1';, api_key='ollama') + +response = openai.chat.completions.create( + model=MODEL, + messages=[{"role": "user", "content": "What is 2 + 2?"}] +) + +print(response.choices[0].message.content) +``` ### How this Repo is organized