|
|
@ -0,0 +1,587 @@ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"cells": [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"cell_type": "code", |
|
|
|
|
|
|
|
"execution_count": 1, |
|
|
|
|
|
|
|
"metadata": {}, |
|
|
|
|
|
|
|
"outputs": [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"name": "stdout", |
|
|
|
|
|
|
|
"output_type": "stream", |
|
|
|
|
|
|
|
"text": [ |
|
|
|
|
|
|
|
"Requirement already satisfied: python-dotenv in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (1.0.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: bs4 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (0.0.2)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: google-generativeai in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (0.8.4)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: ipython in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (8.32.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: openai in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (1.61.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: beautifulsoup4 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from bs4) (4.13.3)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: google-ai-generativelanguage==0.6.15 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-generativeai) (0.6.15)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: google-api-core in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-generativeai) (2.24.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: google-api-python-client in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-generativeai) (2.160.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: google-auth>=2.15.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-generativeai) (2.38.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: protobuf in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-generativeai) (5.29.3)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: pydantic in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-generativeai) (2.10.6)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: tqdm in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-generativeai) (4.67.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: typing-extensions in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-generativeai) (4.12.2)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: proto-plus<2.0.0dev,>=1.22.3 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-ai-generativelanguage==0.6.15->google-generativeai) (1.26.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: decorator in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from ipython) (5.1.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: jedi>=0.16 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from ipython) (0.19.2)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: matplotlib-inline in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from ipython) (0.1.7)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: pexpect>4.3 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from ipython) (4.9.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: prompt_toolkit<3.1.0,>=3.0.41 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from ipython) (3.0.50)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: pygments>=2.4.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from ipython) (2.19.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: stack_data in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from ipython) (0.6.3)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: traitlets>=5.13.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from ipython) (5.14.3)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: anyio<5,>=3.5.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from openai) (4.8.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: distro<2,>=1.7.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from openai) (1.9.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: httpx<1,>=0.23.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from openai) (0.28.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: jiter<1,>=0.4.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from openai) (0.8.2)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: sniffio in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from openai) (1.3.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: idna>=2.8 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from anyio<5,>=3.5.0->openai) (3.10)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: googleapis-common-protos<2.0.dev0,>=1.56.2 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-api-core->google-generativeai) (1.67.0rc1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: requests<3.0.0.dev0,>=2.18.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-api-core->google-generativeai) (2.32.3)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: cachetools<6.0,>=2.0.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-auth>=2.15.0->google-generativeai) (5.5.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: pyasn1-modules>=0.2.1 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-auth>=2.15.0->google-generativeai) (0.4.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: rsa<5,>=3.1.4 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-auth>=2.15.0->google-generativeai) (4.9)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: certifi in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from httpx<1,>=0.23.0->openai) (2025.1.31)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: httpcore==1.* in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from httpx<1,>=0.23.0->openai) (1.0.7)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: h11<0.15,>=0.13 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.14.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: parso<0.9.0,>=0.8.4 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from jedi>=0.16->ipython) (0.8.4)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: ptyprocess>=0.5 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from pexpect>4.3->ipython) (0.7.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: wcwidth in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from prompt_toolkit<3.1.0,>=3.0.41->ipython) (0.2.13)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: annotated-types>=0.6.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from pydantic->google-generativeai) (0.7.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: pydantic-core==2.27.2 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from pydantic->google-generativeai) (2.27.2)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: soupsieve>1.2 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from beautifulsoup4->bs4) (2.6)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: httplib2<1.dev0,>=0.19.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-api-python-client->google-generativeai) (0.22.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: google-auth-httplib2<1.0.0,>=0.2.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-api-python-client->google-generativeai) (0.2.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: uritemplate<5,>=3.0.1 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-api-python-client->google-generativeai) (4.1.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: executing>=1.2.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from stack_data->ipython) (2.2.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: asttokens>=2.1.0 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from stack_data->ipython) (3.0.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: pure-eval in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from stack_data->ipython) (0.2.3)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: grpcio<2.0dev,>=1.33.2 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.10.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,<3.0.0dev,>=1.34.1->google-ai-generativelanguage==0.6.15->google-generativeai) (1.70.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: grpcio-status<2.0.dev0,>=1.33.2 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from google-api-core[grpc]!=2.0.*,!=2.1.*,!=2.10.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,<3.0.0dev,>=1.34.1->google-ai-generativelanguage==0.6.15->google-generativeai) (1.70.0)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: pyparsing!=3.0.0,!=3.0.1,!=3.0.2,!=3.0.3,<4,>=2.4.2 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from httplib2<1.dev0,>=0.19.0->google-api-python-client->google-generativeai) (3.2.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: pyasn1<0.7.0,>=0.4.6 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from pyasn1-modules>=0.2.1->google-auth>=2.15.0->google-generativeai) (0.6.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core->google-generativeai) (3.4.1)\n", |
|
|
|
|
|
|
|
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages (from requests<3.0.0.dev0,>=2.18.0->google-api-core->google-generativeai) (2.3.0)\n", |
|
|
|
|
|
|
|
"OpenAI API Key exists and begins sk-proj-\n", |
|
|
|
|
|
|
|
"Google API Key exists and begins AIzaSyDi\n", |
|
|
|
|
|
|
|
"* Running on local URL: http://127.0.0.1:7860\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"To create a public link, set `share=True` in `launch()`.\n" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"data": { |
|
|
|
|
|
|
|
"text/html": [ |
|
|
|
|
|
|
|
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>" |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"text/plain": [ |
|
|
|
|
|
|
|
"<IPython.core.display.HTML object>" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"metadata": {}, |
|
|
|
|
|
|
|
"output_type": "display_data" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"data": { |
|
|
|
|
|
|
|
"text/plain": [] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"execution_count": 1, |
|
|
|
|
|
|
|
"metadata": {}, |
|
|
|
|
|
|
|
"output_type": "execute_result" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"name": "stdout", |
|
|
|
|
|
|
|
"output_type": "stream", |
|
|
|
|
|
|
|
"text": [ |
|
|
|
|
|
|
|
"Analyzing Saviano, Co. from https://saviano.com\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"***Using LLM googleai and modelname gemini-1.5-pro\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"llm = googleai\n", |
|
|
|
|
|
|
|
"modelname = gemini-1.5-pro\n" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"name": "stderr", |
|
|
|
|
|
|
|
"output_type": "stream", |
|
|
|
|
|
|
|
"text": [ |
|
|
|
|
|
|
|
"Traceback (most recent call last):\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/google/api_core/grpc_helpers.py\", line 76, in error_remapped_callable\n", |
|
|
|
|
|
|
|
" return callable_(*args, **kwargs)\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/grpc/_interceptor.py\", line 277, in __call__\n", |
|
|
|
|
|
|
|
" response, ignored_call = self._with_call(\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/grpc/_interceptor.py\", line 332, in _with_call\n", |
|
|
|
|
|
|
|
" return call.result(), call\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/grpc/_channel.py\", line 440, in result\n", |
|
|
|
|
|
|
|
" raise self\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/grpc/_interceptor.py\", line 315, in continuation\n", |
|
|
|
|
|
|
|
" response, call = self._thunk(new_method).with_call(\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/grpc/_channel.py\", line 1198, in with_call\n", |
|
|
|
|
|
|
|
" return _end_unary_response_blocking(state, call, True, None)\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/grpc/_channel.py\", line 1006, in _end_unary_response_blocking\n", |
|
|
|
|
|
|
|
" raise _InactiveRpcError(state) # pytype: disable=not-instantiable\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
"grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:\n", |
|
|
|
|
|
|
|
"\tstatus = StatusCode.UNAVAILABLE\n", |
|
|
|
|
|
|
|
"\tdetails = \"failed to connect to all addresses; last error: UNAVAILABLE: ipv4:100.64.1.239:443: Failed to connect to remote host: Timeout occurred: FD shutdown\"\n", |
|
|
|
|
|
|
|
"\tdebug_error_string = \"UNKNOWN:Error received from peer {grpc_message:\"failed to connect to all addresses; last error: UNAVAILABLE: ipv4:100.64.1.239:443: Failed to connect to remote host: Timeout occurred: FD shutdown\", grpc_status:14, created_time:\"2025-02-09T23:08:01.374562-08:00\"}\"\n", |
|
|
|
|
|
|
|
">\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"The above exception was the direct cause of the following exception:\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"Traceback (most recent call last):\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/google/api_core/retry/retry_unary.py\", line 144, in retry_target\n", |
|
|
|
|
|
|
|
" result = target()\n", |
|
|
|
|
|
|
|
" ^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/google/api_core/timeout.py\", line 130, in func_with_timeout\n", |
|
|
|
|
|
|
|
" return func(*args, **kwargs)\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/google/api_core/grpc_helpers.py\", line 78, in error_remapped_callable\n", |
|
|
|
|
|
|
|
" raise exceptions.from_grpc_error(exc) from exc\n", |
|
|
|
|
|
|
|
"google.api_core.exceptions.ServiceUnavailable: 503 failed to connect to all addresses; last error: UNAVAILABLE: ipv4:100.64.1.239:443: Failed to connect to remote host: Timeout occurred: FD shutdown\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"The above exception was the direct cause of the following exception:\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"Traceback (most recent call last):\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/gradio/queueing.py\", line 625, in process_events\n", |
|
|
|
|
|
|
|
" response = await route_utils.call_process_api(\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/gradio/route_utils.py\", line 322, in call_process_api\n", |
|
|
|
|
|
|
|
" output = await app.get_blocks().process_api(\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/gradio/blocks.py\", line 2088, in process_api\n", |
|
|
|
|
|
|
|
" result = await self.call_function(\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/gradio/blocks.py\", line 1647, in call_function\n", |
|
|
|
|
|
|
|
" prediction = await utils.async_iteration(iterator)\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/gradio/utils.py\", line 728, in async_iteration\n", |
|
|
|
|
|
|
|
" return await anext(iterator)\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/gradio/utils.py\", line 722, in __anext__\n", |
|
|
|
|
|
|
|
" return await anyio.to_thread.run_sync(\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/anyio/to_thread.py\", line 56, in run_sync\n", |
|
|
|
|
|
|
|
" return await get_async_backend().run_sync_in_worker_thread(\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/anyio/_backends/_asyncio.py\", line 2461, in run_sync_in_worker_thread\n", |
|
|
|
|
|
|
|
" return await future\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/anyio/_backends/_asyncio.py\", line 962, in run\n", |
|
|
|
|
|
|
|
" result = context.run(func, *args)\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/gradio/utils.py\", line 705, in run_sync_iterator_async\n", |
|
|
|
|
|
|
|
" return next(iterator)\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/gradio/utils.py\", line 866, in gen_wrapper\n", |
|
|
|
|
|
|
|
" response = next(iterator)\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/var/folders/rw/g02dv0j93y9b_5lj8jhq5pwm0000gq/T/ipykernel_55999/2954596350.py\", line 233, in stream_model\n", |
|
|
|
|
|
|
|
" yield from result\n", |
|
|
|
|
|
|
|
" File \"/var/folders/rw/g02dv0j93y9b_5lj8jhq5pwm0000gq/T/ipykernel_55999/2954596350.py\", line 195, in stream_googleai\n", |
|
|
|
|
|
|
|
" get_brochure_user_prompt(company_name,url,llm,modelname,temperature),\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/var/folders/rw/g02dv0j93y9b_5lj8jhq5pwm0000gq/T/ipykernel_55999/2954596350.py\", line 164, in get_brochure_user_prompt\n", |
|
|
|
|
|
|
|
" user_prompt += get_all_details(url,llm,modelname,temperature)\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/var/folders/rw/g02dv0j93y9b_5lj8jhq5pwm0000gq/T/ipykernel_55999/2954596350.py\", line 132, in get_all_details\n", |
|
|
|
|
|
|
|
" links = get_links(url,llm,modelname,temperature)\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/var/folders/rw/g02dv0j93y9b_5lj8jhq5pwm0000gq/T/ipykernel_55999/2954596350.py\", line 124, in get_links\n", |
|
|
|
|
|
|
|
" response = model.generate_content(get_links_user_prompt(website),generation_config=genai.GenerationConfig(temperature=temperature,response_mime_type=\"application/json\"))\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/google/generativeai/generative_models.py\", line 331, in generate_content\n", |
|
|
|
|
|
|
|
" response = self._client.generate_content(\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/generative_service/client.py\", line 835, in generate_content\n", |
|
|
|
|
|
|
|
" response = rpc(\n", |
|
|
|
|
|
|
|
" ^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/google/api_core/gapic_v1/method.py\", line 131, in __call__\n", |
|
|
|
|
|
|
|
" return wrapped_func(*args, **kwargs)\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/google/api_core/retry/retry_unary.py\", line 293, in retry_wrapped_func\n", |
|
|
|
|
|
|
|
" return retry_target(\n", |
|
|
|
|
|
|
|
" ^^^^^^^^^^^^^\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/google/api_core/retry/retry_unary.py\", line 153, in retry_target\n", |
|
|
|
|
|
|
|
" _retry_error_helper(\n", |
|
|
|
|
|
|
|
" File \"/Users/adang4/Documents/devwork/andersondang/llm_engineering/llms/lib/python3.11/site-packages/google/api_core/retry/retry_base.py\", line 221, in _retry_error_helper\n", |
|
|
|
|
|
|
|
" raise final_exc from source_exc\n", |
|
|
|
|
|
|
|
"google.api_core.exceptions.RetryError: Timeout of 600.0s exceeded, last exception: 503 failed to connect to all addresses; last error: UNAVAILABLE: ipv4:100.64.1.239:443: Failed to connect to remote host: Timeout occurred: FD shutdown\n" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"name": "stdout", |
|
|
|
|
|
|
|
"output_type": "stream", |
|
|
|
|
|
|
|
"text": [ |
|
|
|
|
|
|
|
"Analyzing Saviano, Co. from https://saviano.com\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"***Using LLM googleai and modelname gemini-1.5-pro\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"llm = googleai\n", |
|
|
|
|
|
|
|
"modelname = gemini-1.5-pro\n", |
|
|
|
|
|
|
|
"## Love is in the Air (and on the Court!) ❤️ Saviano Co.'s Valentine's Day Pickleball Pampering\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"This Valentine's Day, don't let your pickleball court feel neglected! Show it some love with Saviano Co., the experts in court construction and maintenance since 1963. We're serving up satisfaction (and aces!) to clients nationally and globally.\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Is your court feeling a little... *cracked*?** 💔\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"Don't let those fissures in your playing surface become a relationship dealbreaker. We'll resurface your court with the tenderness of a first date, leaving it smooth and ready for action. From paving and grading to drainage and fencing, we handle every detail with the utmost care, just like your true love deserves.\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Tired of that *faded* look?** 😞\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"We'll give your court a Valentine's Day makeover it will never forget! Our expert resurfacing services will have it looking brand new and ready for some serious pickleball passion. We offer a range of athletic surfaces, so you can choose the perfect one to match your playing style (and your heart's desire!).\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Let us *light up* your love life (and your court!)** ✨\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"Our state-of-the-art lighting installations will transform your court into a romantic evening destination. Imagine playing under the stars with your sweetheart, showing off your dinking skills. (Just try not to get too competitive – it's Valentine's Day after all!)\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Why choose Saviano Co. this Valentine's Day?**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"* **Family-owned and operated:** We treat every court like one of our own.\n", |
|
|
|
|
|
|
|
"* **Decades of experience:** We've been building and maintaining courts since before pickleball was even a twinkle in someone's eye!\n", |
|
|
|
|
|
|
|
"* **Nationally and globally recognized:** Our reputation speaks for itself (just like your impressive backhand).\n", |
|
|
|
|
|
|
|
"* **Serving the Bay Area and beyond:** From Saratoga to Napa Valley and even across the globe, we're there for all your court needs.\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Special Valentine's Day Offer:**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"Mention this brochure and receive a FREE consultation to discuss your court's needs. We'll help you create a court that's worthy of Cupid himself!\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Don't let your pickleball court feel lonely this Valentine's Day. Contact Saviano Co. today!**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**(650) 948-3274 | info@saviano.com**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**www.saviano.com (website not real)**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Follow us on social media! (We're not really on social media...yet!)**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"Analyzing Saviano, Co. from https://saviano.com\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"***Using LLM googleai and modelname gemini-1.5-flash\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"llm = googleai\n", |
|
|
|
|
|
|
|
"modelname = gemini-1.5-flash\n", |
|
|
|
|
|
|
|
"# Saviano Co. Inc.: A Love Story for Your Pickleball Court!\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**(Image: A charming illustration of a couple playing pickleball on a beautifully maintained court, hearts floating in the air.)**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**This Valentine's Day, give your pickleball court the love it deserves!**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"Is your pickleball court looking a little… *less than perfect*? Has romance faded from those once-vibrant lines? Don't despair! Saviano Co. Inc., established in 1963, is here to rekindle the passion. For over 60 years, we've been the leading experts in court construction and maintenance, bringing joy (and killer serves) to pickleball players everywhere.\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**We're not just builders; we're matchmakers!** We connect your vision with the reality of a stunning, flawlessly maintained pickleball court. Whether you need a brand new court built from scratch or a loving refresh for your existing one, we've got you covered.\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Our Services: A Recipe for Love (and Great Pickleball):**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"* **Resurfacing:** Say goodbye to cracks and faded paint! We'll make your court smoother than a freshly-baked Valentine's Day cake.\n", |
|
|
|
|
|
|
|
"* **Drainage:** No more soggy socks! We'll ensure your court stays dry and playable, rain or shine.\n", |
|
|
|
|
|
|
|
"* **Lighting:** Set the mood for a romantic evening game under the stars (or just make sure you can see the ball!).\n", |
|
|
|
|
|
|
|
"* **Fencing:** Keep those errant shots in play and your neighbors happy.\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Why Choose Saviano Co. Inc.?**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"Because we're a family business with a passion for pickleball! We treat every court like our own—with meticulous care and attention to detail. Our clients range from prestigious country clubs to happy homeowners, all united by their love of the game.\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**(Image: A photo showcasing a beautifully resurfaced pickleball court.)**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Testimonials:**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"*\"Saviano Co. Inc. transformed our tired old court into a masterpiece! Now, our Valentine's Day pickleball games are even more romantic!\"* – Happy Homeowner, Saratoga\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"*\"Saviano Co. Inc. is the only company we trust for our country club's pickleball courts. Their quality is unmatched!\"* – Country Club Manager, Napa Valley\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Ready to fall in love with your pickleball court all over again?**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"Contact us today for a free quote!\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**(Phone number, email, website)**\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"**Saviano Co. Inc.: Building Courts, Building Memories, Building Love.**\n", |
|
|
|
|
|
|
|
"\n" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"source": [ |
|
|
|
|
|
|
|
"!pip install python-dotenv bs4 google-generativeai ipython openai\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"#\n", |
|
|
|
|
|
|
|
"# # Full code\n", |
|
|
|
|
|
|
|
"#\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# imports\n", |
|
|
|
|
|
|
|
"# If these fail, please check you're running from an 'activated' environment with (llms) in the command prompt\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"import os\n", |
|
|
|
|
|
|
|
"import requests\n", |
|
|
|
|
|
|
|
"import json\n", |
|
|
|
|
|
|
|
"from dotenv import load_dotenv\n", |
|
|
|
|
|
|
|
"from bs4 import BeautifulSoup\n", |
|
|
|
|
|
|
|
"from IPython.display import Markdown, display, update_display\n", |
|
|
|
|
|
|
|
"from openai import OpenAI\n", |
|
|
|
|
|
|
|
"import google.generativeai as genai\n", |
|
|
|
|
|
|
|
"import gradio as gr\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# Get secret key from huggingface space settings\n", |
|
|
|
|
|
|
|
"# Print the key prefixes to help with any debugging\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"openai_api_key = os.environ['OPENAI_API_KEY']\n", |
|
|
|
|
|
|
|
"#anthropic_api_key = os.environ['ANTHROPIC_API_KEY']\n", |
|
|
|
|
|
|
|
"google_api_key = os.environ['GOOGLE_API_KEY']\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"if openai_api_key:\n", |
|
|
|
|
|
|
|
" print(f\"OpenAI API Key exists and begins {openai_api_key[:8]}\")\n", |
|
|
|
|
|
|
|
"else:\n", |
|
|
|
|
|
|
|
" print(\"OpenAI API Key not set\")\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"#if anthropic_api_key:\n", |
|
|
|
|
|
|
|
"# print(f\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\")\n", |
|
|
|
|
|
|
|
"#else:\n", |
|
|
|
|
|
|
|
"# print(\"Anthropic API Key not set\")\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"if google_api_key:\n", |
|
|
|
|
|
|
|
" print(f\"Google API Key exists and begins {google_api_key[:8]}\")\n", |
|
|
|
|
|
|
|
"else:\n", |
|
|
|
|
|
|
|
" print(\"Google API Key not set\")\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# Connect to OpenAI, Anthropic and Google; comment out the Claude or Google lines if you're not using them\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"openai = OpenAI()\n", |
|
|
|
|
|
|
|
"#claude = anthropic.Anthropic()\n", |
|
|
|
|
|
|
|
"genai.configure(api_key=google_api_key)\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# A class to represent a Webpage\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# Some websites need you to use proper headers when fetching them:\n", |
|
|
|
|
|
|
|
"headers = {\n", |
|
|
|
|
|
|
|
" \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36\"\n", |
|
|
|
|
|
|
|
"}\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"class Website:\n", |
|
|
|
|
|
|
|
" \"\"\"\n", |
|
|
|
|
|
|
|
" A utility class to represent a Website that we have scraped, now with links\n", |
|
|
|
|
|
|
|
" \"\"\"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" def __init__(self, url):\n", |
|
|
|
|
|
|
|
" self.url = url\n", |
|
|
|
|
|
|
|
" response = requests.get(url, headers=headers)\n", |
|
|
|
|
|
|
|
" self.body = response.content\n", |
|
|
|
|
|
|
|
" soup = BeautifulSoup(self.body, 'html.parser')\n", |
|
|
|
|
|
|
|
" self.title = soup.title.string if soup.title else \"No title found\"\n", |
|
|
|
|
|
|
|
" if soup.body:\n", |
|
|
|
|
|
|
|
" for irrelevant in soup.body([\"script\", \"style\", \"img\", \"input\"]):\n", |
|
|
|
|
|
|
|
" irrelevant.decompose()\n", |
|
|
|
|
|
|
|
" self.text = soup.body.get_text(separator=\"\\n\", strip=True)\n", |
|
|
|
|
|
|
|
" else:\n", |
|
|
|
|
|
|
|
" self.text = \"\"\n", |
|
|
|
|
|
|
|
" links = [link.get('href') for link in soup.find_all('a')]\n", |
|
|
|
|
|
|
|
" self.links = [link for link in links if link]\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" def get_contents(self):\n", |
|
|
|
|
|
|
|
" return f\"Webpage Title:\\n{self.title}\\nWebpage Contents:\\n{self.text}\\n\\n\"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# system prompt for getting links from website\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"link_system_prompt = \"You are provided with a list of links found on a webpage. \\\n", |
|
|
|
|
|
|
|
"You are able to decide which of the links would be most relevant to include in a brochure about the company.\\n\"\n", |
|
|
|
|
|
|
|
"link_system_prompt += \"You should respond in JSON as in this example:\"\n", |
|
|
|
|
|
|
|
"link_system_prompt += \"\"\"\n", |
|
|
|
|
|
|
|
"{\n", |
|
|
|
|
|
|
|
" \"links\": [\n", |
|
|
|
|
|
|
|
" {\"type\": \"about page\", \"url\": \"https://full.url/goes/here/about\"},\n", |
|
|
|
|
|
|
|
" {\"type\": \"careers page\": \"url\": \"https://another.full.url/careers\"}\n", |
|
|
|
|
|
|
|
" ]\n", |
|
|
|
|
|
|
|
"}\n", |
|
|
|
|
|
|
|
"\"\"\"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# user prompt for getting links from website\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"def get_links_user_prompt(website):\n", |
|
|
|
|
|
|
|
" user_prompt = f\"Here is the list of links on the website of {website.url} - \"\n", |
|
|
|
|
|
|
|
" user_prompt += \"please decide which of these are relevant web links for a brochure about the company, respond with the full https URL in JSON format. \\\n", |
|
|
|
|
|
|
|
"Do not include Terms of Service, Privacy, email links.\\n\"\n", |
|
|
|
|
|
|
|
" user_prompt += \"Links (some might be relative links):\\n\"\n", |
|
|
|
|
|
|
|
" user_prompt += \"\\n\".join(website.links)\n", |
|
|
|
|
|
|
|
" return user_prompt\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"def get_links(url,llm,modelname,temperature):\n", |
|
|
|
|
|
|
|
" website = Website(url)\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" print(\"llm =\",llm)\n", |
|
|
|
|
|
|
|
" print(\"modelname =\",modelname)\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" match llm:\n", |
|
|
|
|
|
|
|
" case 'openai':\n", |
|
|
|
|
|
|
|
" response = openai.chat.completions.create(\n", |
|
|
|
|
|
|
|
" model=modelname,\n", |
|
|
|
|
|
|
|
" temperature=temperature,\n", |
|
|
|
|
|
|
|
" messages=[\n", |
|
|
|
|
|
|
|
" {\"role\": \"system\", \"content\": link_system_prompt},\n", |
|
|
|
|
|
|
|
" {\"role\": \"user\", \"content\": get_links_user_prompt(website)}\n", |
|
|
|
|
|
|
|
" ],\n", |
|
|
|
|
|
|
|
" response_format={\"type\": \"json_object\"}\n", |
|
|
|
|
|
|
|
" )\n", |
|
|
|
|
|
|
|
" result = response.choices[0].message.content\n", |
|
|
|
|
|
|
|
" case 'googleai':\n", |
|
|
|
|
|
|
|
" model=genai.GenerativeModel(model_name=modelname,system_instruction=link_system_prompt)\n", |
|
|
|
|
|
|
|
" response = model.generate_content(get_links_user_prompt(website),generation_config=genai.GenerationConfig(temperature=temperature,response_mime_type=\"application/json\"))\n", |
|
|
|
|
|
|
|
" result = response.text\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" return json.loads(result)\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"def get_all_details(url,llm,modelname,temperature):\n", |
|
|
|
|
|
|
|
" result = \"Landing page:\\n\"\n", |
|
|
|
|
|
|
|
" result += Website(url).get_contents()\n", |
|
|
|
|
|
|
|
" links = get_links(url,llm,modelname,temperature)\n", |
|
|
|
|
|
|
|
" #print(\"Found links:\", links)\n", |
|
|
|
|
|
|
|
" for link in links[\"links\"]:\n", |
|
|
|
|
|
|
|
" result += f\"\\n\\n{link['type']}\\n\"\n", |
|
|
|
|
|
|
|
" result += Website(link[\"url\"]).get_contents()\n", |
|
|
|
|
|
|
|
" return result\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# system prompt for AI to create brochure\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# system_prompt = \"You are an assistant that analyzes the contents of several relevant pages from a company website \\\n", |
|
|
|
|
|
|
|
"# and creates a short brochure about the company for prospective customers, investors and recruits. Respond in markdown.\\\n", |
|
|
|
|
|
|
|
"# Include details of company culture, customers and careers/jobs if you have the information.\"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# Or uncomment the lines below for a more humorous brochure - this demonstrates how easy it is to incorporate 'tone':\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"system_prompt = \"\"\"\n", |
|
|
|
|
|
|
|
"You are an assistant that analyzes the contents of several relevant pages from a company website\n", |
|
|
|
|
|
|
|
"and creates a short humorous, entertaining brochure about the company for prospective and previous customers.\n", |
|
|
|
|
|
|
|
"Include details of company culture and customers if you have the information. Focus on work to create or maintain pickle ball courts.\n", |
|
|
|
|
|
|
|
"Write in a theme for Valentine's Day.\n", |
|
|
|
|
|
|
|
"Emphasize customers that may need upkeep and maintenance of their existing property and installations.\n", |
|
|
|
|
|
|
|
"Return results in Markdown.\n", |
|
|
|
|
|
|
|
"\"\"\"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# Create user prompt with website details included\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"def get_brochure_user_prompt(company_name,url,llm,modelname,temperature):\n", |
|
|
|
|
|
|
|
" user_prompt = f\"You are looking at a company called: {company_name}\\n\"\n", |
|
|
|
|
|
|
|
" user_prompt += f\"Here are the contents of its landing page and other relevant pages; use this information to build a short brochure of the company in markdown.\\n\"\n", |
|
|
|
|
|
|
|
" user_prompt += get_all_details(url,llm,modelname,temperature)\n", |
|
|
|
|
|
|
|
" user_prompt = user_prompt[:5_000] # Truncate if more than 5,000 characters\n", |
|
|
|
|
|
|
|
" return user_prompt\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"#\n", |
|
|
|
|
|
|
|
"# # Everything below here uses values from the gradio web interface. Not the static values defined above\n", |
|
|
|
|
|
|
|
"#\n", |
|
|
|
|
|
|
|
"def stream_openai(system_prompt,company_name,url,llm,modelname,temperature):\n", |
|
|
|
|
|
|
|
" response = openai.chat.completions.create(\n", |
|
|
|
|
|
|
|
" model=modelname,\n", |
|
|
|
|
|
|
|
" stream=True,\n", |
|
|
|
|
|
|
|
" temperature=temperature,\n", |
|
|
|
|
|
|
|
" messages=[\n", |
|
|
|
|
|
|
|
" {\"role\": \"system\", \"content\": system_prompt},\n", |
|
|
|
|
|
|
|
" {\"role\": \"user\", \"content\": get_brochure_user_prompt(company_name,url,llm,modelname,temperature)}\n", |
|
|
|
|
|
|
|
" ],\n", |
|
|
|
|
|
|
|
" )\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" result = \"\"\n", |
|
|
|
|
|
|
|
" for chunk in response:\n", |
|
|
|
|
|
|
|
" result += chunk.choices[0].delta.content or \"\"\n", |
|
|
|
|
|
|
|
" yield result\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" print(result)\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"def stream_googleai(system_prompt,company_name,url,llm,modelname,temperature):\n", |
|
|
|
|
|
|
|
" model=genai.GenerativeModel(\n", |
|
|
|
|
|
|
|
" model_name=modelname,\n", |
|
|
|
|
|
|
|
" system_instruction=system_prompt)\n", |
|
|
|
|
|
|
|
" responses = model.generate_content(\n", |
|
|
|
|
|
|
|
" get_brochure_user_prompt(company_name,url,llm,modelname,temperature),\n", |
|
|
|
|
|
|
|
" generation_config = genai.GenerationConfig(\n", |
|
|
|
|
|
|
|
" temperature=temperature\n", |
|
|
|
|
|
|
|
" ),\n", |
|
|
|
|
|
|
|
" stream=True\n", |
|
|
|
|
|
|
|
" )\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" result = \"\"\n", |
|
|
|
|
|
|
|
" for response in responses:\n", |
|
|
|
|
|
|
|
" result += response.text\n", |
|
|
|
|
|
|
|
" yield result\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" print(result)\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"def stream_model(system_prompt,company_name,url,llm_model,temperature):\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" print(\"Analyzing %s from %s\" % (company_name,url))\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" match llm_model:\n", |
|
|
|
|
|
|
|
" case 'openai_gpt-4o-mini':\n", |
|
|
|
|
|
|
|
" llm = \"openai\"\n", |
|
|
|
|
|
|
|
" modelname = \"gpt-4o-mini\"\n", |
|
|
|
|
|
|
|
" print(\"\\n*** Using LLM %s and modelname %s\\n\" % (llm,modelname))\n", |
|
|
|
|
|
|
|
" result = stream_openai(system_prompt,company_name,url,llm,modelname,temperature)\n", |
|
|
|
|
|
|
|
" case 'googleai_gemini-1.5-pro':\n", |
|
|
|
|
|
|
|
" llm = \"googleai\"\n", |
|
|
|
|
|
|
|
" modelname = \"gemini-1.5-pro\"\n", |
|
|
|
|
|
|
|
" print(\"\\n***Using LLM %s and modelname %s\\n\" % (llm,modelname))\n", |
|
|
|
|
|
|
|
" result = stream_googleai(system_prompt,company_name,url,llm,modelname,temperature)\n", |
|
|
|
|
|
|
|
" case 'googleai_gemini-1.5-flash':\n", |
|
|
|
|
|
|
|
" llm = \"googleai\"\n", |
|
|
|
|
|
|
|
" modelname = \"gemini-1.5-flash\"\n", |
|
|
|
|
|
|
|
" print(\"\\n***Using LLM %s and modelname %s\\n\" % (llm,modelname))\n", |
|
|
|
|
|
|
|
" result = stream_googleai(system_prompt,company_name,url,llm,modelname,temperature)\n", |
|
|
|
|
|
|
|
" case _:\n", |
|
|
|
|
|
|
|
" raise ValueError(\"Unknown LLM and MODEL combination\")\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
" yield from result\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"view = gr.Interface(\n", |
|
|
|
|
|
|
|
" fn=stream_model,\n", |
|
|
|
|
|
|
|
" inputs=[\n", |
|
|
|
|
|
|
|
" gr.Textbox(label=\"AI Agent\",value=system_prompt),\n", |
|
|
|
|
|
|
|
" gr.Textbox(label=\"Company Name\", value=\"Saviano, Co.\"),\n", |
|
|
|
|
|
|
|
" gr.Textbox(label=\"Website to analyze\", value=\"https://saviano.com\"),\n", |
|
|
|
|
|
|
|
" gr.Dropdown([\"openai_gpt-4o-mini\", \"googleai_gemini-1.5-pro\", \"googleai_gemini-1.5-flash\"], label=\"Select AI Engine and LLM Model\", value=\"googleai_gemini-1.5-pro\"),\n", |
|
|
|
|
|
|
|
" gr.Slider(0,2,value=0.7,label=\"AI Temperature\",info=\"AI Creativity Level (higher = more creative)\")\n", |
|
|
|
|
|
|
|
" ],\n", |
|
|
|
|
|
|
|
" outputs=[\n", |
|
|
|
|
|
|
|
" gr.Markdown(label=\"Response:\")\n", |
|
|
|
|
|
|
|
" ],\n", |
|
|
|
|
|
|
|
" flagging_mode=\"never\"\n", |
|
|
|
|
|
|
|
")\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"view.launch()" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"metadata": { |
|
|
|
|
|
|
|
"kernelspec": { |
|
|
|
|
|
|
|
"display_name": "llms", |
|
|
|
|
|
|
|
"language": "python", |
|
|
|
|
|
|
|
"name": "python3" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"language_info": { |
|
|
|
|
|
|
|
"codemirror_mode": { |
|
|
|
|
|
|
|
"name": "ipython", |
|
|
|
|
|
|
|
"version": 3 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"file_extension": ".py", |
|
|
|
|
|
|
|
"mimetype": "text/x-python", |
|
|
|
|
|
|
|
"name": "python", |
|
|
|
|
|
|
|
"nbconvert_exporter": "python", |
|
|
|
|
|
|
|
"pygments_lexer": "ipython3", |
|
|
|
|
|
|
|
"version": "3.11.11" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"nbformat": 4, |
|
|
|
|
|
|
|
"nbformat_minor": 2 |
|
|
|
|
|
|
|
} |