diff --git a/docs/source/notebooks/agent.log b/docs/source/notebooks/agent.log deleted file mode 100644 index 735f791..0000000 --- a/docs/source/notebooks/agent.log +++ /dev/null @@ -1,14 +0,0 @@ -2023-09-24 11:41:02.0354 DEBUG {chat} [create] {'message': 'Creating new chat completion', 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant.'}, {'role': 'user', 'content': 'supercharge babyagi with llambda index and other tools'}], 'timestamp': 1695570062.354676, 'call_id': '365946f1-93fb-482a-abf8-60c796db18be'} -2023-09-24 11:41:02.0355 DEBUG {chat} [create] {'message': 'Calling OpenAI API', 'call_id': '365946f1-93fb-482a-abf8-60c796db18be', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant.'}, {'role': 'user', 'content': 'supercharge babyagi with llambda index and other tools'}], 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'timestamp': 1695570062.355563, 'functions': [{'name': 'GoogleSearch', 'description': '\n Perform a Google search using the provided query. \n \n This action requires `langchain` and `google-api-python-client` installed, and GOOGLE_API_KEY, GOOGLE_CSE_ID environment variables.\n See https://python.langchain.com/docs/integrations/tools/google_search.\n\n :param query: The search query to be used for the Google search.\n :return: The search results as a string.\n ', 'parameters': {'properties': {'query': {'title': 'Query', 'type': 'string'}}, 'required': ['query'], 'title': 'Google_Search', 'type': 'object'}}], 'function_call': 'auto'} -2023-09-24 11:50:50.0919 DEBUG {chat} [create] {'message': 'Creating new chat completion', 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'timestamp': 1695570650.9194539, 'call_id': '1cfb4e13-82a7-40dd-97df-1234a3ba97bc'} -2023-09-24 11:50:50.0920 DEBUG {chat} [create] {'message': 'Calling OpenAI API', 'call_id': '1cfb4e13-82a7-40dd-97df-1234a3ba97bc', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'timestamp': 1695570650.920724, 'functions': [{'name': 'GetCurrentTime', 'description': '\n Use this for getting the current time in the specified time zone.\n \n :return: A string representing the current time in the specified time zone.\n ', 'parameters': {'properties': {}, 'title': 'Get_Current_Time', 'type': 'object'}}, {'name': 'Sleep', 'description': '\n Introduces a sleep delay of the specified seconds and returns a message.\n \n Args:\n seconds (int): The duration to sleep in seconds.\n \n Returns:\n str: A message indicating the completion of the sleep.\n ', 'parameters': {'properties': {'seconds': {'title': 'Seconds', 'type': 'integer'}}, 'required': ['seconds'], 'title': 'Sleep', 'type': 'object'}}, {'name': 'Ask', 'description': '\n Invoke this if you want to ask question, or there is anything need clarification.\n \n Args:\n question (str): The question to ask the user.\n ', 'parameters': {'properties': {'question': {'title': 'Question', 'type': 'string'}}, 'required': ['question'], 'title': 'Ask', 'type': 'object'}}], 'function_call': 'auto'} -2023-09-24 12:09:43.0512 DEBUG {chat} [create] {'message': 'Creating new chat completion', 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'timestamp': 1695571783.512407, 'call_id': 'b81bb387-3898-42ad-a401-fc4439136161'} -2023-09-24 12:09:43.0513 DEBUG {chat} [create] {'message': 'Calling OpenAI API', 'call_id': 'b81bb387-3898-42ad-a401-fc4439136161', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'timestamp': 1695571783.513483, 'functions': [{'name': 'GetCurrentTime', 'description': '\n Use this for getting the current time in the specified time zone.\n \n :return: A string representing the current time in the specified time zone.\n ', 'parameters': {'properties': {}, 'title': 'Get_Current_Time', 'type': 'object'}}, {'name': 'Sleep', 'description': '\n Introduces a sleep delay of the specified seconds and returns a message.\n \n Args:\n seconds (int): The duration to sleep in seconds.\n \n Returns:\n str: A message indicating the completion of the sleep.\n ', 'parameters': {'properties': {'seconds': {'title': 'Seconds', 'type': 'integer'}}, 'required': ['seconds'], 'title': 'Sleep', 'type': 'object'}}, {'name': 'Ask', 'description': '\n Invoke this if you want to ask question, or there is anything need clarification.\n \n Args:\n question (str): The question to ask the user.\n ', 'parameters': {'properties': {'question': {'title': 'Question', 'type': 'string'}}, 'required': ['question'], 'title': 'Ask', 'type': 'object'}}], 'function_call': 'auto'} -2023-09-24 12:12:04.0733 DEBUG {chat} [create] {'message': 'Creating new chat completion', 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'timestamp': 1695571924.733829, 'call_id': '873a88ee-2584-4fbe-b809-1474bfa77f29'} -2023-09-24 12:12:04.0734 DEBUG {chat} [create] {'message': 'Calling OpenAI API', 'call_id': '873a88ee-2584-4fbe-b809-1474bfa77f29', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'timestamp': 1695571924.734928, 'functions': [{'name': 'GetCurrentTime', 'description': '\n Use this for getting the current time in the specified time zone.\n \n :return: A string representing the current time in the specified time zone.\n ', 'parameters': {'properties': {}, 'title': 'Get_Current_Time', 'type': 'object'}}, {'name': 'Sleep', 'description': '\n Introduces a sleep delay of the specified seconds and returns a message.\n \n Args:\n seconds (int): The duration to sleep in seconds.\n \n Returns:\n str: A message indicating the completion of the sleep.\n ', 'parameters': {'properties': {'seconds': {'title': 'Seconds', 'type': 'integer'}}, 'required': ['seconds'], 'title': 'Sleep', 'type': 'object'}}, {'name': 'Ask', 'description': '\n Invoke this if you want to ask question, or there is anything need clarification.\n \n Args:\n question (str): The question to ask the user.\n ', 'parameters': {'properties': {'question': {'title': 'Question', 'type': 'string'}}, 'required': ['question'], 'title': 'Ask', 'type': 'object'}}], 'function_call': 'auto'} -2023-09-24 12:13:34.0937 DEBUG {chat} [create] {'message': 'Creating new chat completion', 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'timestamp': 1695572014.9374669, 'call_id': '54e2a2f4-10a3-41e0-b72e-d098579c75aa'} -2023-09-24 12:13:34.0939 DEBUG {chat} [create] {'message': 'Calling OpenAI API', 'call_id': '54e2a2f4-10a3-41e0-b72e-d098579c75aa', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'timestamp': 1695572014.9390678, 'functions': [{'name': 'GetCurrentTime', 'description': '\n Use this for getting the current time in the specified time zone.\n \n :return: A string representing the current time in the specified time zone.\n ', 'parameters': {'properties': {}, 'title': 'Get_Current_Time', 'type': 'object'}}, {'name': 'Sleep', 'description': '\n Introduces a sleep delay of the specified seconds and returns a message.\n \n Args:\n seconds (int): The duration to sleep in seconds.\n \n Returns:\n str: A message indicating the completion of the sleep.\n ', 'parameters': {'properties': {'seconds': {'title': 'Seconds', 'type': 'integer'}}, 'required': ['seconds'], 'title': 'Sleep', 'type': 'object'}}, {'name': 'Ask', 'description': '\n Invoke this if you want to ask question, or there is anything need clarification.\n \n Args:\n question (str): The question to ask the user.\n ', 'parameters': {'properties': {'question': {'title': 'Question', 'type': 'string'}}, 'required': ['question'], 'title': 'Ask', 'type': 'object'}}], 'function_call': 'auto'} -2023-09-24 12:23:11.0818 DEBUG {chat} [create] {'message': 'Creating new chat completion', 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'timestamp': 1695572591.8180768, 'call_id': '193677c7-61a2-4674-b085-188ecc3bfd4f'} -2023-09-24 12:23:11.0819 DEBUG {chat} [create] {'message': 'Calling OpenAI API', 'call_id': '193677c7-61a2-4674-b085-188ecc3bfd4f', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'timestamp': 1695572591.819124, 'functions': [{'name': 'GetCurrentTime', 'description': '\n Use this for getting the current time in the specified time zone.\n \n :return: A string representing the current time in the specified time zone.\n ', 'parameters': {'properties': {}, 'title': 'Get_Current_Time', 'type': 'object'}}, {'name': 'Sleep', 'description': '\n Introduces a sleep delay of the specified seconds and returns a message.\n \n Args:\n seconds (int): The duration to sleep in seconds.\n \n Returns:\n str: A message indicating the completion of the sleep.\n ', 'parameters': {'properties': {'seconds': {'title': 'Seconds', 'type': 'integer'}}, 'required': ['seconds'], 'title': 'Sleep', 'type': 'object'}}, {'name': 'Ask', 'description': '\n Invoke this if you want to ask question, or there is anything need clarification.\n \n Args:\n question (str): The question to ask the user.\n ', 'parameters': {'properties': {'question': {'title': 'Question', 'type': 'string'}}, 'required': ['question'], 'title': 'Ask', 'type': 'object'}}], 'function_call': 'auto'} -2023-09-24 12:28:16.0555 DEBUG {chat} [create] {'message': 'Creating new chat completion', 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'timestamp': 1695572896.5551429, 'call_id': 'eaf75012-69df-4fe5-9415-40df0a3f3b41'} -2023-09-24 12:28:16.0557 DEBUG {chat} [create] {'message': 'Calling OpenAI API', 'call_id': 'eaf75012-69df-4fe5-9415-40df0a3f3b41', 'input_messages': [{'role': 'system', 'content': 'You are a resourceful assistant, able to inquire for more information if you cannot provide a confident answer to a question.'}, {'role': 'user', 'content': 'generate an image of 碧桂园'}], 'model': 'gpt-3.5-turbo', 'scope': '_default_action_scope_', 'timestamp': 1695572896.557004, 'functions': [{'name': 'GetCurrentTime', 'description': '\n Use this for getting the current time in the specified time zone.\n \n :return: A string representing the current time in the specified time zone.\n ', 'parameters': {'properties': {}, 'title': 'Get_Current_Time', 'type': 'object'}}, {'name': 'Sleep', 'description': '\n Introduces a sleep delay of the specified seconds and returns a message.\n \n Args:\n seconds (int): The duration to sleep in seconds.\n \n Returns:\n str: A message indicating the completion of the sleep.\n ', 'parameters': {'properties': {'seconds': {'title': 'Seconds', 'type': 'integer'}}, 'required': ['seconds'], 'title': 'Sleep', 'type': 'object'}}, {'name': 'Ask', 'description': '\n Invoke this if you want to ask question, or there is anything need clarification.\n \n Args:\n question (str): The question to ask the user.\n ', 'parameters': {'properties': {'question': {'title': 'Question', 'type': 'string'}}, 'required': ['question'], 'title': 'Ask', 'type': 'object'}}], 'function_call': 'auto'} diff --git a/docs/source/notebooks/cookbooks/azure.ipynb b/docs/source/notebooks/cookbooks/azure.ipynb deleted file mode 100644 index 9450dd6..0000000 --- a/docs/source/notebooks/cookbooks/azure.ipynb +++ /dev/null @@ -1,258 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "id": "bc6a2fd0-889b-4006-901e-c8a57834d4ae", - "metadata": {}, - "outputs": [], - "source": [ - "import logging\n", - "import os\n", - "import openai\n", - "import itertools\n", - "import inspect\n", - "\n", - "\n", - "from actionweaver.llms.azure.chat import ChatCompletion\n", - "from actionweaver.llms.azure.tokens import TokenUsageTracker\n", - "from actionweaver import action\n", - "\n", - "\n", - "def print_output(output):\n", - " from collections.abc import Iterable\n", - " if isinstance(output, str):\n", - " print (output)\n", - " elif isinstance(output, Iterable):\n", - " for chunk in output:\n", - " content = chunk.choices[0].delta.content\n", - " if content is not None:\n", - " print(content, end='')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f738597f-26e2-4fda-aa85-466bc569c984", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b79ff9a1-050d-4ac6-9dd6-d9fee63f1e76", - "metadata": {}, - "outputs": [], - "source": [ - "logging.basicConfig(\n", - " filename='agent.log',\n", - " filemode='a',\n", - " format='%(asctime)s.%(msecs)04d %(levelname)s {%(module)s} [%(funcName)s] %(message)s',\n", - " level=logging.INFO,\n", - " datefmt='%Y-%m-%d %H:%M:%S'\n", - ")\n", - "\n", - "logger = logging.getLogger(__name__)\n", - "logger.setLevel(logging.DEBUG)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1f450232-feff-440c-8f84-04bcc131a308", - "metadata": {}, - "outputs": [], - "source": [ - "@action(name=\"GetCurrentTime\")\n", - "def get_current_time() -> str:\n", - " \"\"\"\n", - " Use this for getting the current time in the specified time zone.\n", - " \n", - " :return: A string representing the current time in the specified time zone.\n", - " \"\"\"\n", - " import datetime\n", - " current_time = datetime.datetime.now()\n", - " \n", - " return f\"The current time is {current_time}\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7cee98d0-1e93-4822-b40f-f77cc39120b1", - "metadata": {}, - "outputs": [], - "source": [ - "chat = ChatCompletion(\n", - " model=\"gpt-35-turbo-0613-16k\", \n", - " azure_endpoint = os.getenv(\"AZURE_OPENAI_ENDPOINT\"), \n", - " api_key=os.getenv(\"AZURE_OPENAI_KEY\"), \n", - " api_version=\"2023-10-01-preview\", \n", - " token_usage_tracker = TokenUsageTracker(budget=2000, logger=logger), \n", - " logger=logger)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "87b432dc-bab4-438b-b70d-6e5e60370dd7", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5d19893f-519c-4606-80d9-264e405c73f9", - "metadata": {}, - "outputs": [], - "source": [ - "print_output(chat.create([{\"role\": \"user\", \"content\": \"what time is it\"}], actions = [get_current_time], stream=False))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "173041dd-4cec-4ba6-8154-82be803dc52b", - "metadata": {}, - "outputs": [], - "source": [ - "print_output(chat.create([{\"role\": \"user\", \"content\": \"what time is it\"}], actions = [get_current_time], stream=False))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c84e995f-f4f1-43f5-b86e-c244463bd074", - "metadata": {}, - "outputs": [], - "source": [ - "print_output(chat.create([{\"role\": \"user\", \"content\": \"what time is it\"}], actions = [], stream=True))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7781e3c4-54d4-4120-80a7-f8982574b2f1", - "metadata": {}, - "outputs": [], - "source": [ - "print_output(chat.create([{\"role\": \"user\", \"content\": \"what time is it, print in chinese\"}], actions = [get_current_time], stream=True))" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "8ffedbf1-8c1f-4a5e-937f-1ba8cc60f3b7", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "User(name='Tom', age=31)" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from pydantic import BaseModel\n", - "from actionweaver.actions.factories.pydantic_model_to_action import action_from_model\n", - "\n", - "class User(BaseModel):\n", - " name: str\n", - " age: int\n", - "\n", - "action_from_model(User).invoke(chat, [{\"role\": \"user\", \"content\": \"Tom is 31 years old\"}])" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "713b4702-faa1-4f00-b8cb-1a07d5e89b9d", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'The current time is 01:00 AM.'" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "get_current_time.invoke(chat, [{\"role\": \"user\", \"content\": \"what time is it now\"}])\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4f0300dd-db32-4a8f-8fb5-28afe70ec050", - "metadata": {}, - "outputs": [], - "source": [ - "from actionweaver.mixins.examples import LangChainTools\n", - "\n", - "\n", - "class AgentV0(LangChainTools):\n", - " def __init__(self, logger):\n", - " self.llm = chat\n", - " self.messages = [{\"role\": \"system\", \"content\": \"You are a resourceful assistant.\"}]\n", - "\n", - " def __call__(self, text):\n", - " self.messages += [{\"role\": \"user\", \"content\":text}]\n", - " response = self.llm.create(messages=self.messages, actions = [self.search], stream=True)\n", - "\n", - " return response\n", - "\n", - "\n", - "agent = AgentV0(logger)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4effff20-88ed-4bba-8df7-bbfcc157dddf", - "metadata": {}, - "outputs": [], - "source": [ - "print_output(agent(\"search what is Langchain, what is haystack\"))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "65b5b7e8-dabf-4299-a278-b45468733e06", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.0" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/pyproject.toml b/pyproject.toml index c1b4b7c..88e594e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "actionweaver" -version = "0.0.18" +version = "0.0.19" description = "An Application Framework for Building LLM Agents" authors = ['Teng "Niel" Hu '] readme = "README.md"