Package: nimbusagent
OverviewNimbusAgent is a Python module that provides an interface for interacting with OpenAI's GPT models, including GPT-4 and
GPT-3.5 Turbo. The module is designed to facilitate easy integration of advanced AI capabilities into applications,
offering features like automatic moderation, memory management, and support for both streaming and non-streaming
responses.FeaturesIntegration with OpenAI GPT models (GPT-4, GPT-3.5 Turbo)Automated content moderationCustomizable AI responses with adjustable parametersSupport for both streaming and non-streaming response handlingInternal memory management for maintaining conversation contextExtensible function handling for custom AI functionalitiesInstallationTo install NimbusAgent, run the following command:pipinstallnimbusagentUsageCompletionAgentFirst, import the necessary classes from the nimbusagent package, create an instance of the CompletionAgent class,
passing in your OpenAI API key and the name of the model you want to use:fromnimbusagent.agent.completionimportCompletionAgentagent=CompletionAgent(openai_api_key="YOUR_OPENAI_API_KEY",model_name="gpt-4-0613",max_tokens=2000)response=agent.ask("What's the weather like today?")print(response)StreamingAgentIf you want to use a streaming agent, create an instance of the StreamingAgent class instead. When using a streaming
agent, you can use the ask() method to send a prompt to the agent, and then iterate over the response to get the chunks
of text as they are generated:fromnimbusagent.agent.completionimportStreamingAgentagent=StreamingAgent(openai_api_key="YOUR_OPENAI_API_KEY",model_name="gpt-4-0613",max_tokens=2000)response=agent.ask("What's the weather like today?")forchunkinresponse:print(chunk)Configuration ParametersWhen initializing an instance ofBaseAgent,CompletionAgent, orStreamingAgent, several configuration parameters
can be passed to customize the agent's behavior. Below is a detailed description of these parameters:openai_api_keyDescription: The API key for accessing OpenAI services.Type:strDefault:None(The system will look for an environment variableOPENAI_API_KEYif not provided)model_nameDescription: The name of the primary OpenAI GPT model to use.Type:strDefault:'gpt-4-0613'secondary_model_nameDescription: The name of the secondary OpenAI GPT model to use. The secondary model may be requested by a custom
function to provide additional context for the AI, such as to rephrase a common response to it is custom. For these
simpler responses you may choose to use a cheaper model, such asgpt-3.5-turbo.Type:strDefault:'gpt-3.5-turbo'temperatureDescription: Controls the randomness of the AI's responses.Type:floatDefault:0.1max_tokensDescription: The maximum number of tokens to generate in each response.Type:intDefault:500functionsDescription: A list of custom functions that the agent can use.Type:Optional[list]Default:Nonefunctions_embeddingsDescription: Embeddings for the functions to help the AI understand them better.Type:Optional[List[dict]]Default:Nonefunctions_embeddings_modelDescription: The name of the OpenAI model to use for generating embeddings for the functions.Type:strDefault:'text-embedding-ada-002'functions_always_useDescription: Functions that should always be used by the agent.Type:Optional[List[str]]Default:Nonefunctions_pattern_groupsDescription: Pattern groups for matching functions to user queries.Type:Optional[List[dict]]Default:Nonefunctions_k_closestDescription: The number of closest functions to consider when handling a query.Type:intDefault:3functions_min_similarityDescription: The minimum similarity score for a function to be considered when handling a query.Type:floatDefault:0.5function_max_tokensDescription: The maximum number of tokens to allow towards function definitions. This is useful for preventing
using a large number of tokens from function definitions, thus lowering costs and preventing AI errors. Set to 0 for
unlimited token usageType:intDefault:2000use_tool_callsDescription: Whether to use the new OpenAI Tool Calls vs the now deprecated Function callsType:boolDefault:Truesystem_messageDescription: A system message that sets the context for the agent.Type:strDefault:"You are a helpful assistant."message_historyDescription: Pre-existing chat history for the agent to consider.Type:Optional[List[dict]]Default:Nonecalling_function_start_callbackandcalling_function_stop_callbackDescription: Callback functions triggered when a custom function starts or stops.Type:Optional[callable]Default:Noneperform_moderationDescription: Whether the agent should moderate the responses for inappropriate content.Type:boolDefault:Truemoderation_fail_messageDescription: The message returned when moderation fails.Type:strDefault:"I'm sorry, I can't help you with that as it is not appropriate."memory_max_entriesandmemory_max_tokensDescription: Limits for the agent's memory in terms of entries and tokens.Types:intDefaults:20formemory_max_entries,2000formemory_max_tokensinternal_thoughts_max_entriesDescription: The maximum number of entries for the agent's internal thoughts.Type:intDefault:8loops_maxDescription: The maximum number of loops the agent will process for a single query.Type:intDefault:8send_eventsDescription: Whether the agent should send events (useful for streaming responses).Type:boolDefault:Falsemax_event_sizeDescription: The maximum size of an event in bytes. Allows limiting sending large data streams from a function
responseType:intDefault:2000Example of InitializationHere's an example of how you might initialize aCompletionAgentwith some of these parameters:agent=CompletionAgent(openai_api_key="your_api_key_here",model_name="gpt-4-0613",temperature=0.7,max_tokens=500,perform_moderation=True,system_message="You are a helpful assistant.")You can customize these parameters based on the specific requirements of your application or the behaviors you expect
from the agent.Advanced Usage and ExamplesFor more advanced use cases such as handling multi-turn conversations or integrating custom AI functionalities, refer
to the 'examples' directory in our repository.Getting SupportFor support, please open an issue in our GitHub repository.LicenseNimbusAgent is released under the MIT License See the LICENSE file for more details.TodoAdd support for Azure OpenAI APIAdd support for OpenAI Assistant APIAdd support for new OpenAI Tool Calls vs now deprecated Function callsAdd Function call examplesStay UpdatedFollow our GitHub repository to stay updated with new releases and changes.