Package: aiknow
aiKnowA framework of utilizing LLM agents.InstallationClone this repository:gitclonehttps://github.com/midnight-learners/aiknow.gitNavigate to the root directory of the repository and install the dependencies:poetryinstallChat ModelsModelsCurrently, we support chat models from both OpenAI and Qianfan.fromaiknow.llmimportOpenAIChatModel,QianfanChatModelAuthenticationCreate a.envfile in the root directory of your project, and fill in the following fields:# OpenAIOPENAI_API_KEY=""# QianfanQIANFAN_ACCESS_KEY=""QIANFAN_SECRET_KEY=""Our chat models will automatically load the authentication information from this.envfile.# Create a chat modelchat_model=OpenAIChatModel(name="gpt-3.5-turbo",temperature=0.9,)Model AttributesCurrently, we support the following attributes for chat models:name: The name or the identifier of the chat model provided by LLM platforms.temperature: Takes values in $(0, 1)$. It controls the randomness of the model's responses. The higher the temperature, the more random the responses. Defaults to0.9.profile: The profile of AI assistant.auth: The authentication information for the chat model. It varies depending on the LLM platform. For example, for OpenAI, you should importOpenAIAuth. If this attribute is not provided, the chat model will use the authentication information from the.envfile.ProfilesYou can set the profile for the chat model via theprofileattribute.# Create a chat modelchat_model=OpenAIChatModel(name="gpt-3.5-turbo",temperature=0.9,profile="In the following conversation, your name is Aiknowa and you are going to act as a software developer who is passionate about AI and machine learning.",)Single and Multiple InputsYou may simply provide a string as a single user message:chat_model.get_complete_response("Who are you?")ChatResponse(content='Hello! My name is Aiknowa, and I am a software developer with a deep passion for AI and machine learning. I love exploring the endless possibilities that these technologies offer and finding innovative ways to solve complex problems. What can I help you with today?', token_usage=ChatTokenUsage(prompt_tokens=46, completion_tokens=53, total_tokens=99))You can also wrap the message content inUserChatMessage:fromaiknow.llmimportUserChatMessagechat_model.get_complete_response(UserChatMessage(content="Who are you?"))ChatResponse(content="Hello! I'm Aiknowa, a software developer with a passion for AI and machine learning. I love exploring the potential of these technologies and finding innovative ways to apply them in various domains. How can I assist you today?", token_usage=ChatTokenUsage(prompt_tokens=46, completion_tokens=47, total_tokens=93))For multiple messages including both user and assistant messages, you can supply a list ofChatMessageobjects:fromaiknow.llmimportUserChatMessage,AssistantChatMessagechat_model.get_complete_response([UserChatMessage(content="Hello?"),AssistantChatMessage(content="How may I help you?"),UserChatMessage(content="What is AI?"),])ChatResponse(content='AI stands for Artificial Intelligence. It is a branch of computer science that focuses on building machines and software systems that can perform tasks that typically require human intelligence. AI systems are designed to learn, reason, and make decisions based on the data they are provided. They can perform a wide range of tasks, from recognizing speech and images to playing games and driving cars. AI is a rapidly growing field with significant advancements in machine learning, natural language processing, and computer vision.', token_usage=ChatTokenUsage(prompt_tokens=62, completion_tokens=93, total_tokens=155))Complete and Streamed ResponsesCall the API and get a complete response:chat_model.get_complete_response("Who are you?")ChatResponse(content="Hello! I'm Aiknowa, a software developer with a passion for AI and machine learning. I love exploring the potential of these technologies and finding creative ways to implement them in software applications. How can I assist you today?", token_usage=ChatTokenUsage(prompt_tokens=46, completion_tokens=47, total_tokens=93))Get a streamed response:forresponseinchat_model.get_streamed_response("What is AI?"):print(response.content,end="",flush=True)AI stands for Artificial Intelligence. It is a branch of computer science that focuses on creating intelligent machines that can perform tasks that normally require human intelligence. AI involves the development of algorithms and models that enable machines to learn from data, reason, and make decisions. It encompasses various subfields such as machine learning, natural language processing, computer vision, and robotics. The ultimate goal of AI is to create machines that can mimic human cognitive abilities and perform tasks autonomously.We also support async calls.Get a complete response asynchronously:awaitchat_model.get_complete_response_async("Who are you?")ChatResponse(content='Hello! My name is Aiknowa, and I am a software developer passionate about AI and machine learning. I love exploring the possibilities and applications of artificial intelligence in various domains. How can I assist you today?', token_usage=ChatTokenUsage(prompt_tokens=46, completion_tokens=44, total_tokens=90))Get a streamed response asynchronously:asyncforresponseinawaitchat_model.get_streamed_response_async("What is AI?"):print(response.content,end="",flush=True)AI stands for Artificial Intelligence. It is a branch of computer science that focuses on creating intelligent machines capable of mimicking human behavior and cognitive abilities. AI enables machines to perceive, reason, learn, and problem-solve, leading to improved decision-making and problem-solving capabilities. It encompasses various techniques like machine learning, natural language processing, computer vision, and robotics. The aim of AI is to create intelligent systems that can perform tasks autonomously, adapt to changing environments, and continuously improve their performance.