Skip to content

Commit

Permalink
Modified the import to use openai and set the API key using openai.ap…
Browse files Browse the repository at this point in the history
…i_key (#611)

The openai library does not have a Client class that can be imported
directly.
Instead, we can use openai.api_key for authentication and the module's
built-in methods to interact with the API.
Set the API key using openai.api_key.

In the RecSum-experiments.ipynb file
I have converted user_input to lowercase using input("You: ").lower()
before the comparison.
This ensures that both "bye" and "Bye" (or any variation like "BYE") are
treated the same, making the condition work as intended.

PR #594, accidentally got closed.

@creatorrr I removed the .DS_Store file that I checked in accidentally.

Co-authored-by: Diwank Singh Tomer <[email protected]>
  • Loading branch information
Shuvo31 and creatorrr authored Oct 8, 2024
1 parent 7effdd3 commit 0424843
Show file tree
Hide file tree
Showing 4 changed files with 597 additions and 390 deletions.
156 changes: 104 additions & 52 deletions agents-api/notebooks/01-revise-entities.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,64 @@
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: openai in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (1.51.0)\n",
"Requirement already satisfied: anyio<5,>=3.5.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from openai) (4.6.0)\n",
"Requirement already satisfied: distro<2,>=1.7.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from openai) (1.9.0)\n",
"Requirement already satisfied: httpx<1,>=0.23.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from openai) (0.27.2)\n",
"Requirement already satisfied: jiter<1,>=0.4.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from openai) (0.5.0)\n",
"Requirement already satisfied: pydantic<3,>=1.9.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from openai) (2.9.2)\n",
"Requirement already satisfied: sniffio in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from openai) (1.3.1)\n",
"Requirement already satisfied: tqdm>4 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from openai) (4.66.5)\n",
"Requirement already satisfied: typing-extensions<5,>=4.11 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from openai) (4.12.2)\n",
"Requirement already satisfied: idna>=2.8 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from anyio<5,>=3.5.0->openai) (3.10)\n",
"Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from httpx<1,>=0.23.0->openai) (2024.8.30)\n",
"Requirement already satisfied: httpcore==1.* in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from httpx<1,>=0.23.0->openai) (1.0.6)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.14.0)\n",
"Requirement already satisfied: annotated-types>=0.6.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from pydantic<3,>=1.9.0->openai) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.23.4 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from pydantic<3,>=1.9.0->openai) (2.23.4)\n"
]
}
],
"source": [
"! pip install openai"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: python-dotenv in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (1.0.1)\n"
]
}
],
"source": [
"! pip install python-dotenv"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
"False"
]
},
"execution_count": 6,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -35,18 +83,22 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from openai import Client\n",
"import openai\n",
"from openai import OpenAI\n",
"\n",
"api_key = \"YOUR_OPENAI_API_KEY\"\n",
"\n",
"client = Client()"
"openai.api_key = api_key\n",
"client = OpenAI(api_key=api_key)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -69,7 +121,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -89,7 +141,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -106,7 +158,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -290,7 +342,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -314,7 +366,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -323,7 +375,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -339,7 +391,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -348,7 +400,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -365,7 +417,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -381,7 +433,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -460,64 +512,64 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting CoT generation\n",
"{'content': 'Planning step by step:\\n'\n",
"{'content': 'To add context for future entries, we should outline the main '\n",
" 'entities in the session. These entities are the main people, '\n",
" 'places, or things that are most relevant to the conversation.\\n'\n",
" '\\n'\n",
" '1. Identify key entities such as characters, games, and '\n",
" 'technology mentioned in the conversation.\\n'\n",
" '2. Provide context for each entity, explaining its relevance to '\n",
" 'the conversation and any additional useful information.\\n'\n",
" '3. Ensure the entities and their descriptions encapsulate the '\n",
" 'essence of the conversation for future reference or follow-up '\n",
" 'discussions.\\n'\n",
" '\\n'\n",
" 'Entities will be identified and described based on the '\n",
" \"conversation's content and flow. This will include the games \"\n",
" 'discussed, characters within those games, and any technology '\n",
" 'issues mentioned.',\n",
" 'Entities:\\n'\n",
" '1. User (The participant initiating the conversation, interested '\n",
" 'in video games and experiencing technical issues).\\n'\n",
" '2. Assistant (Engages in conversation about video games and '\n",
" 'offers technical advice).\\n'\n",
" '3. Red Dead Redemption 2 (Video game discussed, specifically the '\n",
" '\"Blood Feuds, Ancient and Modern\" mission and the character '\n",
" 'development of Arthur and Dutch).\\n'\n",
" '4. Helldivers 2 (Another video game discussed, focusing on '\n",
" 'gameplay, strategy, and specific in-game items like the laser '\n",
" 'cannon and guard dog).\\n'\n",
" '5. Nvidia (Referenced in relation to driver issues, particularly '\n",
" 'in the context of compatibility with Linux operating systems).',\n",
" 'role': 'assistant'}\n",
"End CoT generation\n",
"Starting chatml generation\n",
"End chatml generation\n",
"{'content': '- **User**: Engages in discussions about video games and faces '\n",
"{'content': '- User: Engages in discussions about video games and experiences '\n",
" 'technical issues with Nvidia drivers on Linux.\\n'\n",
" '- **Assistant**: Provides conversation on video games, offers '\n",
" 'suggestions on game strategies, and gives technical advice '\n",
" 'regarding Nvidia drivers.\\n'\n",
" '- **Red Dead Redemption 2 (RDR2)**: A video game discussed '\n",
" 'extensively, particularly its missions and character '\n",
" 'development.\\n'\n",
" '- **Arthur Morgan**: A central character in RDR2, noted for his '\n",
" 'moral complexity and development throughout the game.\\n'\n",
" '- **Dutch van der Linde**: Another key character from RDR2, whose '\n",
" \"increasingly erratic decisions impact the game's storyline.\\n\"\n",
" '- **Helldivers 2**: A cooperative multiplayer game mentioned by '\n",
" 'the user, known for its intense gameplay and strategic team '\n",
" 'dynamics.\\n'\n",
" '- **Nvidia**: Technology company referenced in relation to driver '\n",
" 'compatibility issues with Linux operating systems.\\n'\n",
" '- **Linux**: Operating system mentioned as having compatibility '\n",
" \"issues with Nvidia drivers, affecting the user's gaming \"\n",
" 'experience.',\n",
" '- Assistant: Provides insights and engages in discussions about '\n",
" 'video games, offers technical advice.\\n'\n",
" '- Red Dead Redemption 2: A video game discussed for its missions '\n",
" 'and character development.\\n'\n",
" '- Helldivers 2: Another video game mentioned, focusing on '\n",
" 'gameplay and strategies.\\n'\n",
" '- Nvidia: Mentioned in relation to driver compatibility issues '\n",
" 'with Linux.',\n",
" 'role': 'assistant'}\n"
]
}
],
"source": [
"pprint(get_entities(chat_session))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "julep",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -531,7 +583,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.12.1"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 0424843

Please sign in to comment.