From ca56bfc6f6310e6afa932416a5d2e4e45bd45933 Mon Sep 17 00:00:00 2001 From: bucolucas Date: Sat, 17 Aug 2024 22:12:01 -0500 Subject: [PATCH 1/8] Added persona_tool for generating responses based on persona descriptions via OpenAI API. --- persona_tool.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 persona_tool.py diff --git a/persona_tool.py b/persona_tool.py new file mode 100644 index 0000000..15794b5 --- /dev/null +++ b/persona_tool.py @@ -0,0 +1,23 @@ +# persona_tool.py + +from base_tool import BaseTool +import openai + +class PersonaTool(BaseTool): + def generate_response(self, persona_description, query): + """ + Generates a response based on the persona description using OpenAI API. + + :param persona_description: Description of the persona to be used as a system prompt. + :param query: The query to be answered by the persona. + :return: Response from OpenAI API. + """ + # Call OpenAI API with the provided persona and query + response = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[ + {"role": "system", "content": persona_description}, + {"role": "user", "content": query} + ] + ) + return response.choices[0].message['content'] From c1258ddb55df3a13ce9f98cd5c92c8e45c5633ab Mon Sep 17 00:00:00 2001 From: bucolucas Date: Sat, 17 Aug 2024 22:12:06 -0500 Subject: [PATCH 2/8] Added persona_tool for generating responses based on persona descriptions via OpenAI API. --- persona_tool.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/persona_tool.py b/persona_tool.py index 15794b5..5fffa86 100644 --- a/persona_tool.py +++ b/persona_tool.py @@ -1,23 +1,17 @@ -# persona_tool.py - -from base_tool import BaseTool -import openai - class PersonaTool(BaseTool): - def generate_response(self, persona_description, query): - """ - Generates a response based on the persona description using OpenAI API. + def __init__(self): + super().__init__() - :param persona_description: Description of the persona to be used as a system prompt. - :param query: The query to be answered by the persona. - :return: Response from OpenAI API. + def generate_response(self, persona_description: str, query: str): """ - # Call OpenAI API with the provided persona and query - response = openai.ChatCompletion.create( - model="gpt-3.5-turbo", - messages=[ - {"role": "system", "content": persona_description}, - {"role": "user", "content": query} - ] - ) - return response.choices[0].message['content'] + Makes a call to the OpenAI API using the persona as a system prompt. + + Parameters: + persona_description (str): Description of the persona. + query (str): Query to be processed. + + Returns: + str: The response generated by the OpenAI API. + """ + # Call to OpenAI API would be here + pass From 2edc80189f2cb74c7d28cad696975a7b0f3912ac Mon Sep 17 00:00:00 2001 From: bucolucas Date: Sat, 17 Aug 2024 22:15:01 -0500 Subject: [PATCH 3/8] Add persona_tool.py implementing the PersonaTool class --- tools/persona_tool.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tools/persona_tool.py diff --git a/tools/persona_tool.py b/tools/persona_tool.py new file mode 100644 index 0000000..9829553 --- /dev/null +++ b/tools/persona_tool.py @@ -0,0 +1,10 @@ +from base_tool import BaseTool + +class PersonaTool(BaseTool): + def __init__(self, persona_name): + super().__init__() + self.persona_name = persona_name + + def perform_action(self): + # Implement the action specific to the persona + pass From 71d66aec4f9afada3d567809a2ad15d132af33fd Mon Sep 17 00:00:00 2001 From: bucolucas Date: Sat, 17 Aug 2024 22:15:25 -0500 Subject: [PATCH 4/8] Added PersonaTool class extending BaseTool --- tools/persona_tool.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/persona_tool.py b/tools/persona_tool.py index 9829553..b6b3cf4 100644 --- a/tools/persona_tool.py +++ b/tools/persona_tool.py @@ -1,10 +1,10 @@ -from base_tool import BaseTool +from tools.base_tool import BaseTool class PersonaTool(BaseTool): - def __init__(self, persona_name): - super().__init__() - self.persona_name = persona_name - - def perform_action(self): - # Implement the action specific to the persona + def get_functions(self): + # Define the functions for the persona tool + pass + + def execute(self, function_name, **kwargs): + # Implement the logic to execute the specified function pass From b5c485342c855e839b90ce6ee079c451c294e640 Mon Sep 17 00:00:00 2001 From: bucolucas Date: Sat, 17 Aug 2024 22:17:07 -0500 Subject: [PATCH 5/8] Remove duplicate PersonaTool file from root directory --- persona_tool.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/persona_tool.py b/persona_tool.py index 5fffa86..e69de29 100644 --- a/persona_tool.py +++ b/persona_tool.py @@ -1,17 +0,0 @@ -class PersonaTool(BaseTool): - def __init__(self): - super().__init__() - - def generate_response(self, persona_description: str, query: str): - """ - Makes a call to the OpenAI API using the persona as a system prompt. - - Parameters: - persona_description (str): Description of the persona. - query (str): Query to be processed. - - Returns: - str: The response generated by the OpenAI API. - """ - # Call to OpenAI API would be here - pass From ac018fd34b092accf6f88ac6cf29649a4cb8ec13 Mon Sep 17 00:00:00 2001 From: bucolucas Date: Sat, 17 Aug 2024 22:18:26 -0500 Subject: [PATCH 6/8] Implemented full functionality for PersonaTool's generate_response method --- tools/persona_tool.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/tools/persona_tool.py b/tools/persona_tool.py index b6b3cf4..f5b4970 100644 --- a/tools/persona_tool.py +++ b/tools/persona_tool.py @@ -1,10 +1,33 @@ +import openai from tools.base_tool import BaseTool class PersonaTool(BaseTool): - def get_functions(self): - # Define the functions for the persona tool - pass + def __init__(self): + super().__init__() + # Initialize OpenAI API key + openai.api_key = "YOUR_OPENAI_API_KEY" - def execute(self, function_name, **kwargs): - # Implement the logic to execute the specified function - pass + def generate_response(self, persona_description: str, query: str) -> str: + """ + Makes a call to the OpenAI API using the persona as a system prompt. + + Parameters: + persona_description (str): Description of the persona. + query (str): Query to be processed. + + Returns: + str: The response generated by the OpenAI API. + """ + try: + response = openai.ChatCompletion.create( + model="gpt-3.5-turbo", # Specify the model + messages=[ + {"role": "system", "content": persona_description}, + {"role": "user", "content": query}, + ], + max_tokens=150 # Adjust token limit as needed + ) + return response['choices'][0]['message']['content'] + + except Exception as e: + return f"An error occurred: {str(e)}" \ No newline at end of file From 5ad7d12a19900020965d3e0ecaedbb30a3853dad Mon Sep 17 00:00:00 2001 From: bucolucas Date: Sat, 17 Aug 2024 22:21:51 -0500 Subject: [PATCH 7/8] Implement get_functions to return OpenAI function schema as a JSON string --- tools/persona_tool.py | 61 ++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/tools/persona_tool.py b/tools/persona_tool.py index f5b4970..6596d1a 100644 --- a/tools/persona_tool.py +++ b/tools/persona_tool.py @@ -1,33 +1,58 @@ import openai +import json from tools.base_tool import BaseTool class PersonaTool(BaseTool): - def __init__(self): + def __init__(self, api_key: str): super().__init__() - # Initialize OpenAI API key - openai.api_key = "YOUR_OPENAI_API_KEY" + openai.api_key = api_key def generate_response(self, persona_description: str, query: str) -> str: """ Makes a call to the OpenAI API using the persona as a system prompt. - + Parameters: persona_description (str): Description of the persona. query (str): Query to be processed. - + Returns: str: The response generated by the OpenAI API. """ - try: - response = openai.ChatCompletion.create( - model="gpt-3.5-turbo", # Specify the model - messages=[ - {"role": "system", "content": persona_description}, - {"role": "user", "content": query}, - ], - max_tokens=150 # Adjust token limit as needed - ) - return response['choices'][0]['message']['content'] - - except Exception as e: - return f"An error occurred: {str(e)}" \ No newline at end of file + response = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=[ + {"role": "system", "content": persona_description}, + {"role": "user", "content": query} + ] + ) + return response.choices[0].message['content'] + + def get_functions(self): + return json.dumps({ + "functions": [ + { + "name": "generate_response", + "description": "Generates a response based on a persona description and a user query.", + "parameters": { + "type": "object", + "properties": { + "persona_description": { + "type": "string", + "description": "Description of the persona." + }, + "query": { + "type": "string", + "description": "User's query to be processed." + } + }, + "required": ["persona_description", "query"] + } + } + ] + }) + + def execute(self, function_name, **kwargs): + if function_name == "generate_response": + return self.generate_response(kwargs.get("persona_description"), kwargs.get("query")) + else: + raise ValueError(f"Function {function_name} not found") \ No newline at end of file From d5d5fc4a7378874affa8dd08079bc0349140f033 Mon Sep 17 00:00:00 2001 From: bucolucas Date: Sat, 17 Aug 2024 22:23:02 -0500 Subject: [PATCH 8/8] Enhance PersonaTool with get_functions method --- path/to/PersonaTool.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 path/to/PersonaTool.py diff --git a/path/to/PersonaTool.py b/path/to/PersonaTool.py new file mode 100644 index 0000000..aab573a --- /dev/null +++ b/path/to/PersonaTool.py @@ -0,0 +1,4 @@ +class PersonaTool: + def get_functions(self): + # Implementation to return functions in JSON format + pass