Skip to main content

No project description provided

Project description

aiKnow

A framework of utilizing LLM agents.

Installation

Clone this repository:

git clone https://github.com/midnight-learners/aiknow.git

Navigate to the root directory of the repository and install the dependencies:

poetry install

Chat Models

Models

Currently, we support chat models from both OpenAI and Qianfan.

from aiknow.llm import OpenAIChatModel, QianfanChatModel

Authentication

Create a .env file in the root directory of your project, and fill in the following fields:

# OpenAI
OPENAI_API_KEY = ""

# Qianfan
QIANFAN_ACCESS_KEY = ""
QIANFAN_SECRET_KEY = ""

Our chat models will automatically load the authentication information from this .env file.

# Create a chat model
chat_model = OpenAIChatModel(
    name="gpt-3.5-turbo",
    temperature=0.9,
)

Model Attributes

Currently, 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 to 0.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 import OpenAIAuth. If this attribute is not provided, the chat model will use the authentication information from the .env file.

Profiles

You can set the profile for the chat model via the profile attribute.

# Create a chat model
chat_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 Inputs

You 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 in UserChatMessage:

from aiknow.llm import UserChatMessage

chat_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 of ChatMessage objects:

from aiknow.llm import UserChatMessage, AssistantChatMessage

chat_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 Responses

Call 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:

for response in chat_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:

await chat_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:

async for response in await chat_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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiknow-0.0.3.tar.gz (10.2 kB view hashes)

Uploaded Source

Built Distribution

aiknow-0.0.3-py3-none-any.whl (11.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page