Skip to content

Commit

Permalink
update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
lfunderburk committed Nov 15, 2023
1 parent bb358f9 commit 8809a80
Show file tree
Hide file tree
Showing 5 changed files with 422 additions and 171 deletions.
62 changes: 42 additions & 20 deletions ch2/jupyter-notebooks/interacting-with-llms-haystack2.0.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -61,7 +61,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -83,36 +83,53 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"prompt_template = \"\"\"\n",
" Given a question, you provide a short answer.\n",
" \\nQuestion: {{question}}\n",
" \\nAnswer:\n",
" \"\"\"\n"
"gpt = GPTGenerator(api_key=os.getenv(\"OPENAI_API_KEY\"), \n",
" model_name='gpt-4', \n",
" api_base_url = 'https://api.openai.com/v1',\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'replies': ['The capital of France is Paris.'],\n",
" 'metadata': [{'model': 'gpt-4-0613',\n",
" 'index': 0,\n",
" 'finish_reason': 'stop',\n",
" 'usage': {'prompt_tokens': 25,\n",
" 'completion_tokens': 7,\n",
" 'total_tokens': 32}}]}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gpt = GPTGenerator(api_key=os.getenv(\"OPENAI_API_KEY\"), \n",
" model_name='gpt-4', \n",
" api_base_url = 'https://api.openai.com/v1',\n",
" )"
"gpt.run(\"You are a helpful assistant who provides answers to questions. What is the capital of France?\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"gpt.run(\"Who lives in Paris?\")"
"prompt_template = \"\"\"\n",
" Given a question, you provide a short answer.\n",
" \\nQuestion: {{question}}\n",
" \\nAnswer:\n",
" \"\"\"\n"
]
},
{
Expand Down Expand Up @@ -207,7 +224,7 @@
"metadata": {},
"outputs": [],
"source": [
"question = \"Who is the smartest man in the universe\"\n",
"question = \"You are a helpful assistant who provides answers to questions. What is the capital of France?\"\n",
"result = hf_pipeline.run(\n",
" {\n",
" \"prompt_builder\": {\"question\": question},\n",
Expand Down Expand Up @@ -240,8 +257,6 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"from scripts.huggingfaceendpoints import InferenceEndpointAPI"
]
},
Expand Down Expand Up @@ -283,13 +298,20 @@
"mistral_pipeline.draw( \"pipeline-diagrams/mistral-pipeline.png\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"question = \"What is the capital of France?\"\n",
"question = \"What is the capital of Rome?\"\n",
"result = mistral_pipeline.run(\n",
" {\n",
" \"prompt_builder\": {\"question\": question},\n",
Expand Down
131 changes: 40 additions & 91 deletions ch2/jupyter-notebooks/interacting-with-llms-hugging-face.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,80 +47,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2527b40cc0134ed2b7e5d27f804755f3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading (…)okenizer_config.json: 0%| | 0.00/199 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d853bb35ec4742e2830a39062de02785",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading tokenizer.json: 0%| | 0.00/14.5M [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "22d8e2038d064db79eed6d05c7b5cf8e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading (…)cial_tokens_map.json: 0%| | 0.00/85.0 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "67c7cda044b5420ebb19be2e9a1d2a1e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading (…)lve/main/config.json: 0%| | 0.00/715 [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "32ec5cd195004c8ea4d598a07cc2596e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Downloading model.safetensors: 0%| | 0.00/6.01G [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
"\n",
Expand Down Expand Up @@ -221,25 +150,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/macpro/anaconda3/envs/llm-pipelines/lib/python3.10/site-packages/bitsandbytes/cextension.py:34: UserWarning: The installed version of bitsandbytes was compiled without GPU support. 8-bit optimizers, 8-bit multiplication, and GPU quantization are unavailable.\n",
" warn(\"The installed version of bitsandbytes was compiled without GPU support. \"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"'NoneType' object has no attribute 'cadam32bit_grad_fp32'\n"
]
}
],
"outputs": [],
"source": []
},
{
Expand Down Expand Up @@ -330,6 +243,42 @@
"trainer.model.save_pretrained(peft_model_id) \n",
"tokenizer.save_pretrained(peft_model_id) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Connecting to a model through inference end points: MistralAI\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import os \n",
"from dotenv import load_dotenv\n",
"\n",
"load_dotenv()\n",
"# Applicable only if your env file is stored two levels above the current directory\n",
"load_dotenv(\"./../../.env\")\n",
"\n",
"hugging_face_token_endpoint = os.getenv(\"mistral_hf_token\")\n",
"API_URL = \"https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1\"\n",
"headers = {\"Authorization\": f\"Bearer {hugging_face_token_endpoint}\"}\n",
"\n",
"def query(payload):\n",
"\tresponse = requests.post(API_URL, headers=headers, json=payload)\n",
"\treturn response.json()\n",
"\t\n",
"output = query({\n",
"\t\"inputs\": \"You are a helpful assistant who provides answers to questions. What is the capital of France?\",\n",
"})\n",
"\n",
"print(output)"
]
}
],
"metadata": {
Expand Down
44 changes: 29 additions & 15 deletions ch2/jupyter-notebooks/interacting-with-llms-openai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -63,20 +63,9 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"role\": \"assistant\",\n",
" \"content\": \"Hello! I can definitely help you with that. You can find Colombian coffee in various places. One option is to check your local grocery store or coffee shop. They often carry Colombian coffee brands. Additionally, you can also consider checking online retailers that specialize in coffee. They usually have a wide selection of Colombian coffee available for purchase. Is there anything else I can assist you with?\"\n",
"}\n"
]
}
],
"outputs": [],
"source": [
"system_prompt = \"\"\" \n",
"You are a helpful assistant who is knowledgeable about coffee. You are helpful to users who are seeking information about coffee. \n",
Expand All @@ -101,6 +90,31 @@
"\n",
"print(completion.choices[0].message) "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(completion.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"completion.keys()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 8809a80

Please sign in to comment.