Implemented full functionality for PersonaTool's generate_response method

This commit is contained in:
2024-08-17 22:18:26 -05:00
parent b5c485342c
commit ac018fd34b
+29 -6
View File
@@ -1,10 +1,33 @@
import openai
from tools.base_tool import BaseTool from tools.base_tool import BaseTool
class PersonaTool(BaseTool): class PersonaTool(BaseTool):
def get_functions(self): def __init__(self):
# Define the functions for the persona tool super().__init__()
pass # Initialize OpenAI API key
openai.api_key = "YOUR_OPENAI_API_KEY"
def execute(self, function_name, **kwargs): def generate_response(self, persona_description: str, query: str) -> str:
# Implement the logic to execute the specified function """
pass 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)}"