diff --git a/README.md b/README.md index 0889271..b88bba4 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ You'll need the following environment variables in a .env file: * `GCS_ACCESS` * `GCS_SECRET` -* `ANYSCALE_API_KEY` +* `LLM_API_KEY` +* `LLM_BASE_URL` * `GCS_BUCKETNAME` And to get the application up and running... diff --git a/notebooks/newtasks.ipynb b/notebooks/newtasks.ipynb new file mode 100644 index 0000000..901dc61 --- /dev/null +++ b/notebooks/newtasks.ipynb @@ -0,0 +1,140 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import openai\n", + "import json" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "client = openai.OpenAI(\n", + " base_url = \"https://api.fireworks.ai/inference/v1\",\n", + " api_key = \"vQdRZPGX7Mvd9XEAIP8VAe5w1comMroY765vMfHW9rqbS48I\"\n", + ")\n", + "\n", + "messages = [\n", + " {\"role\": \"system\", \"content\": f\"You are a helpful assistant with access to functions.\" \n", + " \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"Use them if required.\"},\n", + " {\"role\": \"user\", \"content\": \"What are Nike's net income in 2022?\"}\n", + "]\n", + "\n", + "tools = [\n", + " {\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " # name of the function \n", + " \"name\": \"get_financial_data\",\n", + " # a good, detailed description for what the function is supposed to do\n", + " \"description\": \"Get financial data for a company given the metric and year.\",\n", + " # a well defined json schema: https://json-schema.org/learn/getting-started-step-by-step#define\n", + " \"parameters\": {\n", + " # for OpenAI compatibility, we always declare a top level object for the parameters of the function\n", + " \"type\": \"object\",\n", + " # the properties for the object would be any arguments you want to provide to the function\n", + " \"properties\": {\n", + " \"metric\": {\n", + " # JSON Schema supports string, number, integer, object, array, boolean and null\n", + " # for more information, please check out https://json-schema.org/understanding-json-schema/reference/type\n", + " \"type\": \"string\",\n", + " # You can restrict the space of possible values in an JSON Schema\n", + " # you can check out https://json-schema.org/understanding-json-schema/reference/enum for more examples on how enum works\n", + " \"enum\": [\"net_income\", \"revenue\", \"ebdita\"],\n", + " },\n", + " \"financial_year\": {\n", + " \"type\": \"integer\", \n", + " # If the model does not understand how it is supposed to fill the field, a good description goes a long way \n", + " \"description\": \"Year for which we want to get financial data.\"\n", + " },\n", + " \"company\": {\n", + " \"type\": \"string\",\n", + " \"description\": \"Name of the company for which we want to get financial data.\"\n", + " }\n", + " },\n", + " # You can specify which of the properties from above are required\n", + " # for more info on `required` field, please check https://json-schema.org/understanding-json-schema/reference/object#required\n", + " \"required\": [\"metric\", \"financial_year\", \"company\"],\n", + " },\n", + " },\n", + " }\n", + "]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"content\": null,\n", + " \"role\": \"assistant\",\n", + " \"function_call\": null,\n", + " \"tool_calls\": [\n", + " {\n", + " \"id\": \"call_W4IUqQRFF9vYINQ74tfBwmqr\",\n", + " \"function\": {\n", + " \"arguments\": \"{\\\"metric\\\": \\\"net_income\\\", \\\"financial_year\\\": 2022, \\\"company\\\": \\\"Nike\\\"}\",\n", + " \"name\": \"get_financial_data\"\n", + " },\n", + " \"type\": \"function\",\n", + " \"index\": 0\n", + " }\n", + " ]\n", + "}\n" + ] + } + ], + "source": [ + "\n", + "chat_completion = client.chat.completions.create(\n", + " model=\"accounts/fireworks/models/firefunction-v2\",\n", + " messages=messages,\n", + " tools=tools,\n", + " temperature=0.1\n", + ")\n", + "print(chat_completion.choices[0].message.model_dump_json(indent=4))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "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.12.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/notebooks/tasks.ipynb b/notebooks/tasks.ipynb index 9c5b010..fb7c2d3 100644 --- a/notebooks/tasks.ipynb +++ b/notebooks/tasks.ipynb @@ -2,19 +2,21 @@ "cells": [ { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "from hellocomputer.config import settings\n", + "from hellocomputer.models import AvailableModels\n", "from langchain_core.utils.function_calling import convert_to_openai_function\n", "import openai\n", + "import json\n", "from operator import itemgetter" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -38,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -52,9 +54,26 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NotFoundError", + "evalue": "Error code: 404 - {'detail': 'Not Found'}", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[17], line 18\u001b[0m\n\u001b[1;32m 6\u001b[0m client \u001b[38;5;241m=\u001b[39m openai\u001b[38;5;241m.\u001b[39mOpenAI(\n\u001b[1;32m 7\u001b[0m base_url \u001b[38;5;241m=\u001b[39m settings\u001b[38;5;241m.\u001b[39mllm_base_url,\n\u001b[1;32m 8\u001b[0m api_key \u001b[38;5;241m=\u001b[39m settings\u001b[38;5;241m.\u001b[39mllm_api_key\n\u001b[1;32m 9\u001b[0m )\n\u001b[1;32m 11\u001b[0m \u001b[38;5;66;03m# response = client.chat.completions.create(\u001b[39;00m\n\u001b[1;32m 12\u001b[0m \u001b[38;5;66;03m# model=str(AvailableModels.mixtral_8x7b),\u001b[39;00m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;66;03m# messages=messages,\u001b[39;00m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;66;03m# tools=tools_fmt,\u001b[39;00m\n\u001b[1;32m 15\u001b[0m \u001b[38;5;66;03m# tool_choice=\"auto\", # auto is default, but we'll be explicit\u001b[39;00m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;66;03m# )\u001b[39;00m\n\u001b[0;32m---> 18\u001b[0m chat_completion \u001b[38;5;241m=\u001b[39m \u001b[43mclient\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mchat\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcompletions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcreate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 19\u001b[0m \u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43maccounts/fireworks/models/firefunction-v2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 20\u001b[0m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 21\u001b[0m \u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtools_fmt\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 22\u001b[0m \u001b[43m \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0.1\u001b[39;49m\n\u001b[1;32m 23\u001b[0m \u001b[43m)\u001b[49m\n\u001b[1;32m 24\u001b[0m \u001b[38;5;28mprint\u001b[39m(chat_completion\u001b[38;5;241m.\u001b[39mchoices[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m.\u001b[39mmessage\u001b[38;5;241m.\u001b[39mmodel_dump_json(indent\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m4\u001b[39m))\n", + "File \u001b[0;32m~/genai/hellocomputer/.venv/lib/python3.12/site-packages/openai/_utils/_utils.py:277\u001b[0m, in \u001b[0;36mrequired_args..inner..wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 275\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMissing required argument: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mquote(missing[\u001b[38;5;241m0\u001b[39m])\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 276\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(msg)\n\u001b[0;32m--> 277\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/genai/hellocomputer/.venv/lib/python3.12/site-packages/openai/resources/chat/completions.py:643\u001b[0m, in \u001b[0;36mCompletions.create\u001b[0;34m(self, messages, model, frequency_penalty, function_call, functions, logit_bias, logprobs, max_tokens, n, parallel_tool_calls, presence_penalty, response_format, seed, service_tier, stop, stream, stream_options, temperature, tool_choice, tools, top_logprobs, top_p, user, extra_headers, extra_query, extra_body, timeout)\u001b[0m\n\u001b[1;32m 609\u001b[0m \u001b[38;5;129m@required_args\u001b[39m([\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmessages\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m\"\u001b[39m], [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmessages\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstream\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n\u001b[1;32m 610\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcreate\u001b[39m(\n\u001b[1;32m 611\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 641\u001b[0m timeout: \u001b[38;5;28mfloat\u001b[39m \u001b[38;5;241m|\u001b[39m httpx\u001b[38;5;241m.\u001b[39mTimeout \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m|\u001b[39m NotGiven \u001b[38;5;241m=\u001b[39m NOT_GIVEN,\n\u001b[1;32m 642\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m ChatCompletion \u001b[38;5;241m|\u001b[39m Stream[ChatCompletionChunk]:\n\u001b[0;32m--> 643\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_post\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 644\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m/chat/completions\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 645\u001b[0m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmaybe_transform\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 646\u001b[0m \u001b[43m \u001b[49m\u001b[43m{\u001b[49m\n\u001b[1;32m 647\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmessages\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 648\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmodel\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 649\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mfrequency_penalty\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfrequency_penalty\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 650\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mfunction_call\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfunction_call\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 651\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mfunctions\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfunctions\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 652\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mlogit_bias\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mlogit_bias\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 653\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mlogprobs\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mlogprobs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 654\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmax_tokens\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 655\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mn\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mn\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 656\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mparallel_tool_calls\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mparallel_tool_calls\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 657\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mpresence_penalty\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mpresence_penalty\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 658\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mresponse_format\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mresponse_format\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 659\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mseed\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mseed\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 660\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mservice_tier\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mservice_tier\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 661\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mstop\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 662\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mstream\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 663\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mstream_options\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 664\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtemperature\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 665\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtool_choice\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtool_choice\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 666\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtools\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 667\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtop_logprobs\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_logprobs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 668\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mtop_p\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_p\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 669\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43muser\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 670\u001b[0m \u001b[43m \u001b[49m\u001b[43m}\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 671\u001b[0m \u001b[43m \u001b[49m\u001b[43mcompletion_create_params\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mCompletionCreateParams\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 672\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 673\u001b[0m \u001b[43m \u001b[49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmake_request_options\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 674\u001b[0m \u001b[43m \u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mextra_headers\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_query\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mextra_query\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_body\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mextra_body\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout\u001b[49m\n\u001b[1;32m 675\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 676\u001b[0m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mChatCompletion\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 677\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 678\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mStream\u001b[49m\u001b[43m[\u001b[49m\u001b[43mChatCompletionChunk\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 679\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/genai/hellocomputer/.venv/lib/python3.12/site-packages/openai/_base_client.py:1266\u001b[0m, in \u001b[0;36mSyncAPIClient.post\u001b[0;34m(self, path, cast_to, body, options, files, stream, stream_cls)\u001b[0m\n\u001b[1;32m 1252\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpost\u001b[39m(\n\u001b[1;32m 1253\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 1254\u001b[0m path: \u001b[38;5;28mstr\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1261\u001b[0m stream_cls: \u001b[38;5;28mtype\u001b[39m[_StreamT] \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 1262\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m ResponseT \u001b[38;5;241m|\u001b[39m _StreamT:\n\u001b[1;32m 1263\u001b[0m opts \u001b[38;5;241m=\u001b[39m FinalRequestOptions\u001b[38;5;241m.\u001b[39mconstruct(\n\u001b[1;32m 1264\u001b[0m method\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpost\u001b[39m\u001b[38;5;124m\"\u001b[39m, url\u001b[38;5;241m=\u001b[39mpath, json_data\u001b[38;5;241m=\u001b[39mbody, files\u001b[38;5;241m=\u001b[39mto_httpx_files(files), \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39moptions\n\u001b[1;32m 1265\u001b[0m )\n\u001b[0;32m-> 1266\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m cast(ResponseT, \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mopts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream_cls\u001b[49m\u001b[43m)\u001b[49m)\n", + "File \u001b[0;32m~/genai/hellocomputer/.venv/lib/python3.12/site-packages/openai/_base_client.py:942\u001b[0m, in \u001b[0;36mSyncAPIClient.request\u001b[0;34m(self, cast_to, options, remaining_retries, stream, stream_cls)\u001b[0m\n\u001b[1;32m 933\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mrequest\u001b[39m(\n\u001b[1;32m 934\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 935\u001b[0m cast_to: Type[ResponseT],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 940\u001b[0m stream_cls: \u001b[38;5;28mtype\u001b[39m[_StreamT] \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 941\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m ResponseT \u001b[38;5;241m|\u001b[39m _StreamT:\n\u001b[0;32m--> 942\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 943\u001b[0m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 944\u001b[0m \u001b[43m \u001b[49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 945\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 946\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream_cls\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 947\u001b[0m \u001b[43m \u001b[49m\u001b[43mremaining_retries\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mremaining_retries\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 948\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/genai/hellocomputer/.venv/lib/python3.12/site-packages/openai/_base_client.py:1046\u001b[0m, in \u001b[0;36mSyncAPIClient._request\u001b[0;34m(self, cast_to, options, remaining_retries, stream, stream_cls)\u001b[0m\n\u001b[1;32m 1043\u001b[0m err\u001b[38;5;241m.\u001b[39mresponse\u001b[38;5;241m.\u001b[39mread()\n\u001b[1;32m 1045\u001b[0m log\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRe-raising status error\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m-> 1046\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_status_error_from_response(err\u001b[38;5;241m.\u001b[39mresponse) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1048\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_process_response(\n\u001b[1;32m 1049\u001b[0m cast_to\u001b[38;5;241m=\u001b[39mcast_to,\n\u001b[1;32m 1050\u001b[0m options\u001b[38;5;241m=\u001b[39moptions,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1053\u001b[0m stream_cls\u001b[38;5;241m=\u001b[39mstream_cls,\n\u001b[1;32m 1054\u001b[0m )\n", + "\u001b[0;31mNotFoundError\u001b[0m: Error code: 404 - {'detail': 'Not Found'}" + ] + } + ], "source": [ "messages = [\n", " {\"role\": \"system\", \"content\": \"You are helpful assistant.\"},\n", @@ -62,47 +81,84 @@ "]\n", "\n", "client = openai.OpenAI(\n", - " base_url = \"https://api.endpoints.anyscale.com/v1\",\n", - " api_key = settings.anyscale_api_key\n", + " base_url = settings.llm_base_url,\n", + " api_key = settings.llm_api_key\n", ")\n", "\n", - "response = client.chat.completions.create(\n", - " model=\"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n", + "# response = client.chat.completions.create(\n", + "# model=str(AvailableModels.mixtral_8x7b),\n", + "# messages=messages,\n", + "# tools=tools_fmt,\n", + "# tool_choice=\"auto\", # auto is default, but we'll be explicit\n", + "# )\n", + "\n", + "chat_completion = client.chat.completions.create(\n", + " model=\"accounts/fireworks/models/firefunction-v2\",\n", " messages=messages,\n", " tools=tools_fmt,\n", - " tool_choice=\"auto\", # auto is default, but we'll be explicit\n", + " temperature=0.1\n", ")\n", - "\n", - "get_args = itemgetter(\"arguments\")\n" + "print(chat_completion.choices[0].message.model_dump_json(indent=4))\n" ] }, { "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [], - "source": [ - "call = response.choices[0].message.tool_calls[0].function" - ] - }, - { - "cell_type": "code", - "execution_count": 36, + "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "5" + "{'name': 'add', 'arguments': {'a': 2, 'b': 2}}" ] }, - "execution_count": 36, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "add.func(2,3)" + "json.loads(response.choices[0].message.content.removeprefix(\"[TOOL_CALLS] \"))[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'accounts/fireworks/models/mixtral-8x7b-instruct'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "str(AvailableModels.mixtral_8x7b)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'https://api.fireworks.ai/inference/v1/completions'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "settings.llm_base_url" ] }, { @@ -129,7 +185,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.4" } }, "nbformat": 4, diff --git a/requirements.in b/requirements.in index 065f1ee..8261e1b 100644 --- a/requirements.in +++ b/requirements.in @@ -1,5 +1,6 @@ langchain langchain-community +langchain-fireworks openai fastapi pydantic-settings diff --git a/requirements.txt b/requirements.txt index ad5d5c8..702262f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,15 @@ # This file was autogenerated by uv via the following command: # uv pip compile requirements.in -aiobotocore==2.13.0 +aiobotocore==2.13.1 # via s3fs -aiofiles==23.2.1 +aiofiles==24.1.0 + # via -r requirements.in aiohttp==3.9.5 # via # aiobotocore # langchain # langchain-community + # langchain-fireworks # s3fs aioitertools==0.11.0 # via aiobotocore @@ -24,9 +26,10 @@ anyio==4.4.0 attrs==23.2.0 # via aiohttp authlib==1.3.1 -botocore==1.34.106 + # via -r requirements.in +botocore==1.34.131 # via aiobotocore -certifi==2024.6.2 +certifi==2024.7.4 # via # httpcore # httpx @@ -50,16 +53,24 @@ distro==1.9.0 dnspython==2.6.1 # via email-validator duckdb==1.0.0 -email-validator==2.1.1 + # via + # -r requirements.in + # duckdb-engine +duckdb-engine==0.13.0 + # via -r requirements.in +email-validator==2.2.0 # via fastapi fastapi==0.111.0 + # via -r requirements.in fastapi-cli==0.0.4 # via fastapi +fireworks-ai==0.14.0 + # via langchain-fireworks frozenlist==1.4.1 # via # aiohttp # aiosignal -fsspec==2024.6.0 +fsspec==2024.6.1 # via s3fs h11==0.14.0 # via @@ -72,7 +83,10 @@ httptools==0.6.1 httpx==0.27.0 # via # fastapi + # fireworks-ai # openai +httpx-sse==0.4.0 + # via fireworks-ai idna==3.7 # via # anyio @@ -81,6 +95,7 @@ idna==3.7 # requests # yarl itsdangerous==2.2.0 + # via -r requirements.in jinja2==3.1.4 # via fastapi jmespath==1.0.1 @@ -89,17 +104,23 @@ jsonpatch==1.33 # via langchain-core jsonpointer==3.0.0 # via jsonpatch -langchain==0.2.3 - # via langchain-community -langchain-community==0.2.4 -langchain-core==0.2.5 +langchain==0.2.7 + # via + # -r requirements.in + # langchain-community +langchain-community==0.2.7 + # via -r requirements.in +langchain-core==0.2.17 # via # langchain # langchain-community + # langchain-fireworks # langchain-text-splitters -langchain-text-splitters==0.2.1 +langchain-fireworks==0.1.5 + # via -r requirements.in +langchain-text-splitters==0.2.2 # via langchain -langsmith==0.1.76 +langsmith==0.1.85 # via # langchain # langchain-community @@ -123,33 +144,44 @@ numpy==1.26.4 # langchain # langchain-community # pyarrow -openai==1.33.0 -orjson==3.10.4 +openai==1.35.13 + # via + # -r requirements.in + # langchain-fireworks +orjson==3.10.6 # via # fastapi # langsmith -packaging==23.2 +packaging==24.1 # via + # duckdb-engine # langchain-core # marshmallow -polars==0.20.31 +pillow==10.4.0 + # via fireworks-ai +polars==1.1.0 + # via -r requirements.in pyarrow==16.1.0 + # via -r requirements.in pycparser==2.22 # via cffi -pydantic==2.7.3 +pydantic==2.8.2 # via # fastapi + # fireworks-ai # langchain # langchain-core # langsmith # openai # pydantic-settings -pydantic-core==2.18.4 +pydantic-core==2.20.1 # via pydantic -pydantic-settings==2.3.2 +pydantic-settings==2.3.4 + # via -r requirements.in pygments==2.18.0 # via rich pyjwt==2.8.0 + # via -r requirements.in python-dateutil==2.9.0.post0 # via botocore python-dotenv==1.0.1 @@ -157,7 +189,9 @@ python-dotenv==1.0.1 # pydantic-settings # uvicorn python-multipart==0.0.9 - # via fastapi + # via + # -r requirements.in + # fastapi pyyaml==6.0.1 # via # langchain @@ -168,10 +202,12 @@ requests==2.32.3 # via # langchain # langchain-community + # langchain-fireworks # langsmith rich==13.7.1 # via typer -s3fs==2024.6.0 +s3fs==2024.6.1 + # via -r requirements.in shellingham==1.5.4 # via typer six==1.16.0 @@ -181,13 +217,15 @@ sniffio==1.3.1 # anyio # httpx # openai -sqlalchemy==2.0.30 +sqlalchemy==2.0.31 # via + # -r requirements.in + # duckdb-engine # langchain # langchain-community starlette==0.37.2 # via fastapi -tenacity==8.3.0 +tenacity==8.5.0 # via # langchain # langchain-community @@ -209,7 +247,7 @@ typing-inspect==0.9.0 # via dataclasses-json ujson==5.10.0 # via fastapi -urllib3==2.2.1 +urllib3==2.2.2 # via # botocore # requests diff --git a/src/hellocomputer/config.py b/src/hellocomputer/config.py index aabaf44..d2cf14e 100644 --- a/src/hellocomputer/config.py +++ b/src/hellocomputer/config.py @@ -3,7 +3,8 @@ from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): base_url: str = "http://localhost:8000" - anyscale_api_key: str = "Awesome API" + llm_api_key: str = "Awesome API" + llm_base_url: str = "Awessome Endpoint" gcs_access: str = "access" gcs_secret: str = "secret" gcs_bucketname: str = "bucket" diff --git a/src/hellocomputer/main.py b/src/hellocomputer/main.py index 5ba6fa9..0fb807a 100644 --- a/src/hellocomputer/main.py +++ b/src/hellocomputer/main.py @@ -22,7 +22,6 @@ app.add_middleware(SessionMiddleware, secret_key=settings.app_secret_key) async def homepage(request: Request): user = request.session.get("user") if user: - print(json.dumps(user)) return RedirectResponse("/app") with open(static_path / "login.html") as f: diff --git a/src/hellocomputer/models.py b/src/hellocomputer/models.py index b59b1bb..09f6c9a 100644 --- a/src/hellocomputer/models.py +++ b/src/hellocomputer/models.py @@ -1,14 +1,34 @@ from enum import StrEnum -from langchain_community.chat_models import ChatAnyscale -from langchain_core.messages import HumanMessage, SystemMessage +from langchain_fireworks import Fireworks +from langchain_core.prompts import PromptTemplate class AvailableModels(StrEnum): - llama3_8b = "meta-llama/Meta-Llama-3-8B-Instruct" - llama3_70b = "meta-llama/Meta-Llama-3-70B-Instruct" + llama3_70b = "accounts/fireworks/models/llama-v3-70b-instruct" # Function calling model - mixtral_8x7b = "mistralai/Mixtral-8x7B-Instruct-v0.1" + mixtral_8x7b = "accounts/fireworks/models/mixtral-8x7b-instruct" + mixtral_8x22b = "accounts/fireworks/models/mixtral-8x22b-instruct" + firefunction_2 = "accounts/fireworks/models/firefunction-v2" + + +general_prompt = """ +You're a helpful assistant. Perform the following tasks: + +---- +{query} +---- +""" + +sql_prompt = """ +You're a SQL expert. Write a query using the duckdb dialect. The goal of the query is the following: + +---- +{query} +---- + +Return only the sql statement without any additional text. +""" class Chat: @@ -25,33 +45,36 @@ class Chat: def __init__( self, - model: AvailableModels = AvailableModels.llama3_8b, + model: AvailableModels = AvailableModels.mixtral_8x7b, api_key: str = "", temperature: float = 0.5, ): - self.model_name = model + self.model = model self.api_key = self.raise_no_key(api_key) self.messages = [] self.responses = [] - self.model: ChatAnyscale = ChatAnyscale( - model_name=model, temperature=temperature, anyscale_api_key=self.api_key + self.model: Fireworks = Fireworks( + model=model, temperature=temperature, api_key=self.api_key ) - async def eval(self, system: str, human: str): - self.messages.append( - [ - SystemMessage(content=system), - HumanMessage(content=human), - ] - ) + async def eval(self, task): + prompt = PromptTemplate.from_template(general_prompt) - response = await self.model.ainvoke(self.messages[-1]) + response = await self.model.ainvoke(prompt.format(query=task)) + self.responses.append(response) + return self + + async def sql_eval(self, question): + prompt = PromptTemplate.from_template(sql_prompt) + + response = await self.model.ainvoke(prompt.format(query=question)) self.responses.append(response) return self def last_response_content(self): - return self.responses[-1].content + last_response = self.responses[-1] + return last_response def last_response_metadata(self): return self.responses[-1].response_metadata diff --git a/src/hellocomputer/routers/analysis.py b/src/hellocomputer/routers/analysis.py index ef307fa..856717d 100644 --- a/src/hellocomputer/routers/analysis.py +++ b/src/hellocomputer/routers/analysis.py @@ -13,7 +13,7 @@ router = APIRouter() @router.get("/query", response_class=PlainTextResponse, tags=["queries"]) async def query(sid: str = "", q: str = "") -> str: - llm = Chat(api_key=settings.anyscale_api_key, temperature=0.5) + llm = Chat(api_key=settings.llm_api_key, temperature=0.5) db = SessionDB( StorageEngines.gcs, gcs_access=settings.gcs_access, diff --git a/test/test_query.py b/test/test_query.py index 0364503..347c596 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -20,45 +20,45 @@ SID = "test" @pytest.mark.asyncio -@pytest.mark.skipif( - settings.anyscale_api_key == "Awesome API", reason="API Key not set" -) +@pytest.mark.skipif(settings.llm_api_key == "Awesome API", reason="API Key not set") async def test_chat_simple(): - chat = Chat(api_key=settings.anyscale_api_key, temperature=0) - chat = await chat.eval("Your're a helpful assistant", "Say literlly 'Hello'") - assert chat.last_response_content() == "Hello!" + chat = Chat(api_key=settings.llm_api_key, temperature=0) + chat = await chat.eval("Say literlly 'Hello'") + assert "Hello" in chat.last_response_content() @pytest.mark.asyncio -@pytest.mark.skipif( - settings.anyscale_api_key == "Awesome API", reason="API Key not set" -) +@pytest.mark.skipif(settings.llm_api_key == "Awesome API", reason="API Key not set") async def test_simple_data_query(): query = "write a query that finds the average score of all students in the current database" - chat = Chat(api_key=settings.anyscale_api_key, temperature=0.5) + chat = Chat( + api_key=settings.llm_api_key, + temperature=0.5, + ) db = SessionDB( storage_engine=StorageEngines.local, path=TEST_XLS_PATH.parent, sid=SID ).load_xls(TEST_XLS_PATH) - chat = await chat.eval("You're an expert sql developer", db.query_prompt(query)) + chat = await chat.sql_eval(db.query_prompt(query)) query = extract_code_block(chat.last_response_content()) assert query.startswith("SELECT") @pytest.mark.asyncio -@pytest.mark.skipif( - settings.anyscale_api_key == "Awesome API", reason="API Key not set" -) +@pytest.mark.skipif(settings.llm_api_key == "Awesome API", reason="API Key not set") async def test_data_query(): q = "find the average score of all the sudents" - llm = Chat(api_key=settings.anyscale_api_key, temperature=0.5) + llm = Chat( + api_key=settings.llm_api_key, + temperature=0.5, + ) db = SessionDB( storage_engine=TEST_STORAGE, path=TEST_OUTPUT_FOLDER, sid="test" ).load_folder() - chat = await llm.eval("You're a DUCKDB expert", db.query_prompt(q)) + chat = await llm.sql_eval(db.query_prompt(q)) query = extract_code_block(chat.last_response_content()) result = db.query(query).pl()