Added DeepSeek to weeks 1, 2 and 8
This commit is contained in:
@@ -209,7 +209,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"test[1].prompt"
|
||||
"print(test[1].prompt)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -255,6 +255,16 @@
|
||||
" return float(match.group()) if match else 0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "06743833-c362-47f8-b02a-139be2cd52ab",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"get_price(\"The price for this is $99.99\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -306,6 +316,86 @@
|
||||
"Tester.test(gpt_4o_mini_rag, test)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d793c6d0-ce3f-4680-b37d-4643f0cd1d8e",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Optional Extra: Trying a DeepSeek API call instead of OpenAI\n",
|
||||
"\n",
|
||||
"If you have a DeepSeek API key, we will use it here as an alternative implementation; otherwise skip to the next section.."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "21b6a22f-0195-47b6-8f6d-cab6ebe05742",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Connect to DeepSeek using the OpenAI client python library\n",
|
||||
"\n",
|
||||
"deepseek_api_key = os.getenv(\"DEEPSEEK_API_KEY\")\n",
|
||||
"deepseek_via_openai_client = OpenAI(api_key=deepseek_api_key,base_url=\"https://api.deepseek.com\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ea7267d6-9489-4dac-a6e0-aec108e788c2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Added some retry logic here because DeepSeek is very oversubscribed and sometimes fails..\n",
|
||||
"\n",
|
||||
"def deepseek_api_rag(item):\n",
|
||||
" documents, prices = find_similars(item)\n",
|
||||
" retries = 8\n",
|
||||
" done = False\n",
|
||||
" while not done and retries > 0:\n",
|
||||
" try:\n",
|
||||
" response = deepseek_via_openai_client.chat.completions.create(\n",
|
||||
" model=\"deepseek-chat\", \n",
|
||||
" messages=messages_for(item, documents, prices),\n",
|
||||
" seed=42,\n",
|
||||
" max_tokens=8\n",
|
||||
" )\n",
|
||||
" reply = response.choices[0].message.content\n",
|
||||
" done = True\n",
|
||||
" except Exception as e:\n",
|
||||
" print(f\"Error: {e}\")\n",
|
||||
" retries -= 1\n",
|
||||
" return get_price(reply)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "6560faf2-4dec-41e5-95e2-b2c46cdb3ba8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"deepseek_api_rag(test[1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0578b116-869f-429d-8382-701f1c0882f3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"Tester.test(deepseek_api_rag, test)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "6739870f-1eec-4547-965d-4b594e685697",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## And now to wrap this in an \"Agent\" class"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -316,6 +406,20 @@
|
||||
"from agents.frontier_agent import FrontierAgent"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "2efa7ba9-c2d7-4f95-8bb5-c4295bbeb01f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Let's print the logs so we can see what's going on\n",
|
||||
"\n",
|
||||
"import logging\n",
|
||||
"root = logging.getLogger()\n",
|
||||
"root.setLevel(logging.INFO)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
||||
Reference in New Issue
Block a user